From patchwork Fri Jul 19 08:06:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1133929 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45qk9v2HwGz9s3Z for ; Fri, 19 Jul 2019 18:06:57 +1000 (AEST) Received: from localhost ([::1]:42896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNuo-0005CL-Bo for incoming@patchwork.ozlabs.org; Fri, 19 Jul 2019 04:06:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44539) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hoNui-0005C2-L1 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hoNuh-0004Vw-I7 for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:48 -0400 Received: from mout.kundenserver.de ([212.227.126.187]:57363) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hoNuh-0004UU-8v for qemu-devel@nongnu.org; Fri, 19 Jul 2019 04:06:47 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.167]) with ESMTPSA (Nemesis) id 1M2gt5-1hrxLC3wgJ-004CiN; Fri, 19 Jul 2019 10:06:18 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Fri, 19 Jul 2019 10:06:09 +0200 Message-Id: <20190719080610.1607-3-laurent@vivier.eu> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190719080610.1607-1-laurent@vivier.eu> References: <20190719080610.1607-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:3vZTmkp2CIU/uLb9dj5H0NYmh6QWxpKuuZCCkAw/sEStKXXk1RQ wojVnpv63+pcyzFgvI/reAUcF8xlKbpgfVBI74hCJYKG0RokUBeJ5HQg4Dl+ZPxg2xJRTC1 zDItbQQiWgTTNLxwn9UBa0MX7wMhtPXn0llHaoR0BTFZOQBsj38fmuDj8IlaPobeqrRWQ8T Zdx9M59D9FY7I78UDV+3Q== X-UI-Out-Filterresults: notjunk:1; V03:K0:90PKw+tmUqM=:oNjPxE2Kx1sPLSjFtj5TL4 NaMnlUjQrEHn5JhD3FPDwrDbiXd9SNmmktBvy7clYJ9YLKde90Jh5jYtOv/CxqaZ3R231miG/ D/B6NzU/MiOKg1hs6GDYXhM2lR7uyZtnnCFi70lRsS6v/IH/VCT5vR20YiiGytNqZfKQHg4xs sal/Fk0iJ7rz0IVD9KhdW5AsmqTIFvR+uRFnHnTO9UgOdZrDfbhbAO7jBXWWaCqDSXMAjOZjN E05H0FQl6VJknOL0Ytdx3Rr1u/welGKo+xamMDZf1FpbpL1kz6c+QmNZykTHhIyfGPBDneJlH XijY9tVJoYTI8JxMT1rubMa4kMYf+1WrYYiUui8cXfN7SXO1M71oiTMVVePWHFAZt0MDpeyR0 Rxt7vRo/SG1W1w9uNP5CFVfbV2cnFM0IZO1zIougHyIbrYHVOPJaPNYD/PbzYx0/1qPW4M4/R S7fGtRxl7QZxdLF06Nf+bc9JLwI7+Lv0mtPpcUQm1Ntuc0/V0WgMWnkCVELnu8EkkNCQ5HoMt ioIH5LKZogAy8BC3nTDefaHpqQUqiJlZ7xoB5/NQgVXUx/Pjtqc/VEnaaMphSkXKGRd5ldytm QBn2oxKVlwQdMlVeqbA9izPrgHvQZDAV5s+M+8x/1DMkjaxso8IAnZjhn2/8AwFFfmQY0OFMs 89ULtCBtatzrOUY07JycAaWKUeBKCGCAl3uGXULIqkAsuP8aaeDYZXO/JGFGKvKP1tkipDSU2 UasXO6fQanJNbxWnpLJafJ56qArdFz0ltNx3Hjp8D3Mk/x2hqWZf9LAnDfM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.187 Subject: [Qemu-devel] [PULL v2 2/3] linux-user: check valid address in access_ok() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , =?utf-8?q?R=C3=A9mi_Denis-Courmon?= =?utf-8?q?t?= , Aleksandar Rikalo , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Paolo Bonzini , Aurelien Jarno , Richard Henderson Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Rémi Denis-Courmont Fix a crash with LTP testsuite and aarch64: tst_test.c:1015: INFO: Timeout per run is 0h 05m 00s qemu-aarch64: .../qemu/accel/tcg/translate-all.c:2522: page_check_range: Assertion `start < ((target_ulong)1 << L1_MAP_ADDR_SPACE_BITS)' failed. qemu:handle_cpu_signal received signal outside vCPU context @ pc=0x60001554 page_check_range() should never be called with address outside the guest address space. This patch adds a guest_addr_valid() check in access_ok() to only call page_check_range() with a valid address. Fixes: f6768aa1b4c6 ("target/arm: fix AArch64 virtual address space size") Signed-off-by: Rémi Denis-Courmont Signed-off-by: Laurent Vivier Message-Id: <20190704084115.24713-1-lvivier@redhat.com> Signed-off-by: Laurent Vivier --- include/exec/cpu_ldst.h | 4 ++++ linux-user/qemu.h | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/exec/cpu_ldst.h b/include/exec/cpu_ldst.h index 9de8c933031b..9151fdb042c4 100644 --- a/include/exec/cpu_ldst.h +++ b/include/exec/cpu_ldst.h @@ -62,7 +62,11 @@ typedef uint64_t abi_ptr; /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h(x) ((void *)((unsigned long)(abi_ptr)(x) + guest_base)) +#if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS +#define guest_addr_valid(x) (1) +#else #define guest_addr_valid(x) ((x) <= GUEST_ADDR_MAX) +#endif #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) static inline int guest_range_valid(unsigned long start, unsigned long len) diff --git a/linux-user/qemu.h b/linux-user/qemu.h index fab287b7ec50..4258e4162d26 100644 --- a/linux-user/qemu.h +++ b/linux-user/qemu.h @@ -456,7 +456,9 @@ extern unsigned long guest_stack_size; static inline int access_ok(int type, abi_ulong addr, abi_ulong size) { - return page_check_range((target_ulong)addr, size, + return guest_addr_valid(addr) && + (size == 0 || guest_addr_valid(addr + size - 1)) && + page_check_range((target_ulong)addr, size, (type == VERIFY_READ) ? PAGE_READ : (PAGE_READ | PAGE_WRITE)) == 0; }