From nobody Mon Feb 9 07:39:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562229775; cv=none; d=zoho.com; s=zohoarc; b=XGxJxguB2TNxRu3Fhex8tiOdLR6Zb/UhwzXDF3A21L2e+KFTXbGEA/E0Z0969nWPKDQG9WDnl9R8YAHpkzV5lvJRMZ48RnwGJoVzqd67m4QHQIHA3WNNx13glY5t6N7W1v36ixsOyNGeC0rsbsalKr5AfkBThe47MG1Eet/CEo4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562229775; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=itFPxybKnl9Dym19ty5xJKWqZNaF6udIteM/yJn3RLM=; b=AfdtfYgPyG/04s1hQ11Ita5vJLeNn0KYH4QtTk6ERSEGViSYroJzk2VVM9kGBdfq45qbO59Zk7yw2zxb6+2wXwzhQSgC5mpTmYzVwIYrWMDtmmXqJpdJmL2KflNkir8R7wqbWAd9wa1D2M+ePAcc9DEmQZ307+8GnEfQWI76mOU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1562229775184544.7867354171029; Thu, 4 Jul 2019 01:42:55 -0700 (PDT) Received: from localhost ([::1]:43560 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hixKE-0002KK-S7 for importer@patchew.org; Thu, 04 Jul 2019 04:42:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55807) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hixJG-0001X3-7J for qemu-devel@nongnu.org; Thu, 04 Jul 2019 04:41:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hixJF-0000BD-7w for qemu-devel@nongnu.org; Thu, 04 Jul 2019 04:41:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hixJF-000079-2S for qemu-devel@nongnu.org; Thu, 04 Jul 2019 04:41:41 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E69F03092651; Thu, 4 Jul 2019 08:41:24 +0000 (UTC) Received: from thinkpad.redhat.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14F5A98429; Thu, 4 Jul 2019 08:41:15 +0000 (UTC) From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 4 Jul 2019 10:41:15 +0200 Message-Id: <20190704084115.24713-1-lvivier@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 04 Jul 2019 08:41:31 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] 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=20Denis-Courmont?= , Riku Voipio , Laurent Vivier , Paolo Bonzini , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: R=C3=A9mi 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=3D0x6000= 1554 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=C3=A9mi Denis-Courmont Signed-off-by: Laurent Vivier --- Notes: v2: Check addr + size - 1 guest_addr_valid() is always true if HOST_LONG_BITS <=3D TARGET_VIRT_ADDR_SPACE_BITS 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 a08b11bd2c07..06080d27ba15 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)) =20 +#if HOST_LONG_BITS <=3D TARGET_VIRT_ADDR_SPACE_BITS +#define guest_addr_valid(x) (1) +#else #define guest_addr_valid(x) ((x) <=3D GUEST_ADDR_MAX) +#endif #define h2g_valid(x) guest_addr_valid((unsigned long)(x) - guest_base) =20 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; =20 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 =3D=3D 0 || guest_addr_valid(addr + size - 1)) && + page_check_range((target_ulong)addr, size, (type =3D=3D VERIFY_READ) ? PAGE_READ : (PAGE_= READ | PAGE_WRITE)) =3D=3D 0; } =20 --=20 2.21.0