From nobody Sun Nov 24 14:06:39 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1722643167; cv=none; d=zohomail.com; s=zohoarc; b=O2tiDRYntUwoesDNlMoECFxxUlvjjy2CiLlaZw6iMxM2Zr/S3fNufbPlsaZYIMcbaRGWX/4yV59MUXdcCjFdQ50wUkwFcowfZun5herQzcBgWZL4Bm8zOV8j088IKJM2Fm49RWAJVt3ZcSQJZ8kjNqZyBI1h5lOyCpAG30LYrJ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1722643167; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=FWWgURm7Gj0tu0dmUrbtb+IelYe/G3vbyvbAbU8GzUk=; b=NeOCH01j+GMlvjecgrLPOsGvhLAxFZGr4u72PkpDewp1QFo6193RrK0iIAnrV3FcjPK5LTHFvqTNa2JEwqa2Bhxe2t84XF/O/U8gYXPwc2ZOmjzHqHFfZZ0K7I7cyhS2YBmC8KYEtYWKH0GR2G9GqFFjZAvWHJ1fdLQcYstwx24= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172264316786896.24881069467915; Fri, 2 Aug 2024 16:59:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sa29k-00021T-Q0; Fri, 02 Aug 2024 19:57:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sa29i-0001un-MJ for qemu-devel@nongnu.org; Fri, 02 Aug 2024 19:57:55 -0400 Received: from mail-io1-xd2b.google.com ([2607:f8b0:4864:20::d2b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sa29h-0004Ij-9j for qemu-devel@nongnu.org; Fri, 02 Aug 2024 19:57:54 -0400 Received: by mail-io1-xd2b.google.com with SMTP id ca18e2360f4ac-81f9339e544so340310839f.0 for ; Fri, 02 Aug 2024 16:57:52 -0700 (PDT) Received: from dune.bsdimp.com ([50.253.99.174]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4c8d69a8227sm683131173.47.2024.08.02.16.57.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 16:57:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20230601.gappssmtp.com; s=20230601; t=1722643072; x=1723247872; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FWWgURm7Gj0tu0dmUrbtb+IelYe/G3vbyvbAbU8GzUk=; b=SlRtZFYgn2Sm0Z4CkP++WDMgwGwcL6y0mQkZNMvfs1yYk2rHbydrbYclXxxQHoyJ12 9nxERWeYWhXdB2RY6XbHxvdZsIveBGWuDTReHuFhcHIadvNDlOkGx1p8897jSj/P51Cv KuC6L2d+p5/TMAEq1Rw5yolvXgL+s/pArgeK6E0zdWKGbCpc2ni837BQ6cm0/ZbC5/m+ zKj2+OhwRu7FVA4/XrPWHLCbuexm0fMGHEujHCqiPvGwmGj/qMYo38CJn2NhzoRp8EBu EojJ+O5fzQHoBHUjWzzMCqcd83PzCv/pVEdimop4SgAdDlz5UGrLspBY7MS6mKYVpXNn 6PLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722643072; x=1723247872; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FWWgURm7Gj0tu0dmUrbtb+IelYe/G3vbyvbAbU8GzUk=; b=SmZi6zf9uwArm1cfU7t3IHK9HjBr6wugYMy/ATyDB00kQulfl6N7b1WBzLCnDPLbdg P2E8Dq1Kix1H9uNjl2zmr6sgskWEPQHXwduAW7aBQQojx8myDvHytVhVD+o3T3MZHgEr NyQLPE+gp1s3Q54T/TVuEvOKbsrb18DZGrvCmwCQVYglAQqOiVfoLBiFPWg4FYvxho8p MSiqU53hW131M1Ul7sHRDHrC7MrUh7mI/idMdXEhSCRpX4hFtmaj875kbx1e3nxCbM/M 61g7NUbTGxbLfOGmYDv1FZ5N/ZeMtr1w0govODkhLU5JNz61Nk8Of9OwWvMp4eqA2ff+ GjGQ== X-Gm-Message-State: AOJu0YxjYsuAmGCxTHd/XVkcb0cJ8EOMmCTQeRsDnlB80lpiRx4uaepU xhl/A33Ch6pBMiz9TVHU3gpfJr39jNEPuVy1BaNlQ9ydAE29fuhuNxNeq4YW/vw5fv3Msf8+HBY UBKQ= X-Google-Smtp-Source: AGHT+IE2O5SY884IPHtNGxy0xYcbqgv0MSIy69f7/gVB/R2j7/TwQtot4my3nRkKDkWVvx0syz89hA== X-Received: by 2002:a05:6602:6016:b0:7f6:84e7:bd35 with SMTP id ca18e2360f4ac-81fd4358ef7mr535598339f.8.1722643071762; Fri, 02 Aug 2024 16:57:51 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Cc: Warner Losh , Kyle Evans , Jessica Clarke Subject: [PATCH 12/17] bsd-user: Use guest_range_valid_untagged to validate range Date: Fri, 2 Aug 2024 17:56:12 -0600 Message-ID: <20240802235617.7971-13-imp@bsdimp.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240802235617.7971-1-imp@bsdimp.com> References: <20240802235617.7971-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.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; Received-SPF: none client-ip=2607:f8b0:4864:20::d2b; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2b.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @bsdimp-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1722643169054116600 Content-Type: text/plain; charset="utf-8" This is the generic validation function, so remove some hand-rolled ones. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index fc69cb43ebd..ed8d31a9048 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -74,9 +74,10 @@ int target_mprotect(abi_ulong start, abi_ulong len, int = prot) if ((start & ~TARGET_PAGE_MASK) !=3D 0) return -EINVAL; len =3D TARGET_PAGE_ALIGN(len); + if (!guest_range_valid_untagged(start, len)) { + return -ENOMEM; + } end =3D start + len; - if (end < start) - return -EINVAL; prot &=3D PROT_READ | PROT_WRITE | PROT_EXEC; if (len =3D=3D 0) return 0; @@ -689,11 +690,13 @@ int target_munmap(abi_ulong start, abi_ulong len) TARGET_ABI_FMT_lx "\n", start, len); #endif - if (start & ~TARGET_PAGE_MASK) + if (start & ~TARGET_PAGE_MASK) { return -EINVAL; + } len =3D TARGET_PAGE_ALIGN(len); - if (len =3D=3D 0) + if (len =3D=3D 0 || !guest_range_valid_untagged(start, len)) { return -EINVAL; + } mmap_lock(); end =3D start + len; real_start =3D start & qemu_host_page_mask; --=20 2.45.1