From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728377476140.1582751954295; Fri, 8 Oct 2021 14:26:17 -0700 (PDT) Received: from localhost ([::1]:51034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxNf-0005hF-Is for importer@patchew.org; Fri, 08 Oct 2021 17:26:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLX-00038b-NP for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:03 -0400 Received: from mail-il1-x134.google.com ([2607:f8b0:4864:20::134]:38585) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLW-0007bC-B7 for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:03 -0400 Received: by mail-il1-x134.google.com with SMTP id r9so11329984ile.5 for ; Fri, 08 Oct 2021 14:24:01 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.23.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FRKvWo3/8KWpxG4EBP+p+wzC/JzpwAuUb/QshF2UpdE=; b=0tGShYQMagLllo792QZkunky4he2qj6RatCuQ/MPN1s9ieRh+Oy/PCmf08+Qp3qbev FbOnM4SaKxaJbAZKdYaMabyiJ0KyusoxqHAgzbrjBdAFgwElBuvrHnWxGCEoVSzxS8sM g6lLU9sDANmh/hZxMG7aLK/gz4b+oaFccGb91cum6vEBBquJdOuVhRF8JMg9Uu4dLOZq IYLunNt1Oacz+nk9ZfOyjO/3zFZGXlWW9wa4nOoZ6aAZTPApwcVYo1KIUiOu+K81E6n4 FSbXLwkaKBDj1wIU0HS2tNOhBe0LHnRMxRD4w6OvJEkTOUxhEfgx7gb7KQCcEVoPv45c KKxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FRKvWo3/8KWpxG4EBP+p+wzC/JzpwAuUb/QshF2UpdE=; b=02c3IIPVO5dxnir+V6j8vbsfX8mpkgr5so/0Pex7IP+9VSzGnZ0hWLl3hq8AlAcggy LKjxO/yWLCKHUgi7VdLZ9uoH1KN2dYyW7mBoFTYsfYyds9NnJh7wyoG5B/+PKUdvnDYA DUo46rjDYdlglPuq1uJ8mKW6++WX8SQMfZKu0I9tgpPfnMKi9IPHu1YKfWPtqhgQ3QdU ApZMs3f4hoXbPUZakMCzMBFYoW0qVwbfI+qNvcD4ADypDNwXGHaX8VF0zFjpznN2H7vs xIPSgK/qCr0tLlJYZxNXVz+uiF5P2TE6QRAAoPTx9Mx73R6G8zzZvwHk8RyyXsczGKwc y0zA== X-Gm-Message-State: AOAM532lTQDhZtRpeXuboaDrbEG01CDB5y0O8Wf1I3o/LsWxn0ASVqhl UJZxFzIC20kZiTY9yLZTVJ9CDoXZn6ytFA== X-Google-Smtp-Source: ABdhPJyL7ff0vKzHr9+8JqvV8PfbBZWltRCmOkNXzujn+nqwhQpu4wcJnQHJl7Ek+tTPHFYO4VJ6cA== X-Received: by 2002:a05:6e02:1889:: with SMTP id o9mr9799537ilu.219.1633728240668; Fri, 08 Oct 2021 14:24:00 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 1/9] bsd-user/mmap.c: Always zero MAP_ANONYMOUS memory in mmap_frag() Date: Fri, 8 Oct 2021 15:23:36 -0600 Message-Id: <20211008212344.95537-2-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::134; envelope-from=imp@bsdimp.com; helo=mail-il1-x134.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, =?UTF-8?q?Mika=C3=ABl=20Urankar?= , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728379157100001 From: Mika=C3=ABl Urankar Similar to the equivalent linux-user commit e6deac9cf99 When mapping MAP_ANONYMOUS memory fragments, still need notice about to set it zero, or it will cause issues. Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index b40ab9045f..fc3c1480f5 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -180,10 +180,12 @@ static int mmap_frag(abi_ulong real_start, if (prot_new !=3D (prot1 | PROT_WRITE)) mprotect(host_start, qemu_host_page_size, prot_new); } else { - /* just update the protection */ if (prot_new !=3D prot1) { mprotect(host_start, qemu_host_page_size, prot_new); } + if (prot_new & PROT_WRITE) { + memset(g2h_untagged(start), 0, end - start); + } } return 0; } --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728480975907.2058482500878; Fri, 8 Oct 2021 14:28:00 -0700 (PDT) Received: from localhost ([::1]:57858 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxPK-0001oM-FQ for importer@patchew.org; Fri, 08 Oct 2021 17:27:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLZ-00038s-10 for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:05 -0400 Received: from mail-il1-x12d.google.com ([2607:f8b0:4864:20::12d]:45958) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLX-0007cJ-52 for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:04 -0400 Received: by mail-il1-x12d.google.com with SMTP id i11so10284069ila.12 for ; Fri, 08 Oct 2021 14:24:02 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BVN0ugWOSWpBWHbRsPpyH98PmJG0IHpMrYYWEQcve3M=; b=npe3xBRQIMJOgW3GFiZ0TT7PuxR3n9fxse2EIqXIyICzK75XdZmFz5tSxgfgPRxHpL FAxzoPO0p8Ydulpmit8Dl9aLkJwsUluTwJybdpNbYXklkuHyZV8vGQAPc+QLdrdPGLcg A5KV0LAaLAGwDMCoMDVtWQ50F8n+4UatGpK1FoTWhG5EMGeaR/K/UNQ8/kECiRrqnuuJ KTpliBquIFy+lUyhDJLgQOcBxNly29G5/017xJbviedDJndin0p5vBeaIwdbwXcG7tvg REOy6TudQouUB16n9aMV8CyuJSH0Xm98x56A2HHyKXpoyAzv7UQpCrLZtavg2as/L4/A Ou5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BVN0ugWOSWpBWHbRsPpyH98PmJG0IHpMrYYWEQcve3M=; b=jv3KT9haBzSS5/6lY0dvzRxRCOXRi94FpFqlWXWi31PW9weoN/40IIzGC8zKml6lEN 7dArXIn2cisQbm9U12Pfr1eVeD1h1nLg8GN9AlVENXvhpfnEIhDtoCn3zsPcV/W8xOH0 ptFQTChRRHjugZJcgkSmorwjJXCtTgIUiNk0YFfWFcf/pf+zPSMWDqnHZZyk35eEjl3Z 8A6L4mp9boYN8cUAL16Q+HH8d80w0hvfxIz0dWfkJ1RkuUZ/sK5KbAlh8bb89NRu8FiE C9ozEQN6J2S5J0eSkvfTxT6yl/2Hmy8XJMx7nutD7RDVIniDJEmnzSwXcua68eF6OOVa 32mQ== X-Gm-Message-State: AOAM530B2s/VuZX/tJN02iyjNfKk/MyTLdpJJbfucscVp4i7jv1JVRIQ euNqAeWVeRmuSpz/Nipfhq1dNEMiBeXNdQ== X-Google-Smtp-Source: ABdhPJyeQF2q0uaLA6nEZsIbkPrPm0ijsj7sIk7G6FFQnoGQvtbhylzm46HLeeoWedX1BMfXY6URZw== X-Received: by 2002:a05:6e02:1c04:: with SMTP id l4mr9149686ilh.83.1633728241756; Fri, 08 Oct 2021 14:24:01 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 2/9] bsd-user/mmap.c: check pread's return value to fix warnings with _FORTIFY_SOURCE Date: Fri, 8 Oct 2021 15:23:37 -0600 Message-Id: <20211008212344.95537-3-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::12d; envelope-from=imp@bsdimp.com; helo=mail-il1-x12d.google.com X-Spam_score_int: 0 X-Spam_score: 0.0 X-Spam_bar: / X-Spam_report: (0.0 / 5.0 requ) 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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, =?UTF-8?q?Mika=C3=ABl=20Urankar?= , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728481869100001 From: Mika=C3=ABl Urankar Simmilar to the equivalent linux-user: commit fb7e378cf9c, which added checking to pread's return value. Update to current qemu standards with {} around the if statement. Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index fc3c1480f5..4f4fa3ab46 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -174,7 +174,9 @@ static int mmap_frag(abi_ulong real_start, mprotect(host_start, qemu_host_page_size, prot1 | PROT_WRITE); =20 /* read the corresponding file data */ - pread(fd, g2h_untagged(start), end - start, offset); + if (pread(fd, g2h_untagged(start), end - start, offset) =3D=3D -1)= { + return -1; + } =20 /* put final protection */ if (prot_new !=3D (prot1 | PROT_WRITE)) @@ -593,7 +595,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, -1, 0); if (retaddr =3D=3D -1) goto fail; - pread(fd, g2h_untagged(start), len, offset); + if (pread(fd, g2h_untagged(start), len, offset) =3D=3D -1) { + goto fail; + } if (!(prot & PROT_WRITE)) { ret =3D target_mprotect(start, len, prot); if (ret !=3D 0) { --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728382140776.4909160711555; Fri, 8 Oct 2021 14:26:22 -0700 (PDT) Received: from localhost ([::1]:51556 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxNl-00065y-5D for importer@patchew.org; Fri, 08 Oct 2021 17:26:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41130) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLZ-00039U-G6 for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:05 -0400 Received: from mail-io1-xd35.google.com ([2607:f8b0:4864:20::d35]:36796) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLX-0007dM-RJ for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:05 -0400 Received: by mail-io1-xd35.google.com with SMTP id e144so12198763iof.3 for ; Fri, 08 Oct 2021 14:24:03 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9GXLEOZq/t0os6KbKaAOUmzhrYWQXeaANB7rwvx/zB8=; b=NvK2D3CgP5mR9zbAZKZAaNziPUCYEvD1k4Ul01H7Xg472vqNBY3+1G1c5WEQS3JIUe JKZF40idiU4IRg8BOnKNnohZK/u6RiMPOEICoUab4WpaVA9r1opedYhxzbUNjYmQD18k Au8KKzEnAy/c81gUIBgShGaaKPfHwOeJSSzJW5A4yNzg0bc6wAiI5g5qcnaVoCtV1Aiv 43mZ/STRgXPKoTDGKaaPsNs0NtUBpuaM0JGra0ifEXjxqpYvovDDLexlXkHUL3pwCj5E loFZX7uhwEtSXKZmrgNIAOnMRe8tNZFwijCeb6mMCuPBSItHQ3GvXhOBIuInuhp1KHKQ E+SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9GXLEOZq/t0os6KbKaAOUmzhrYWQXeaANB7rwvx/zB8=; b=Z0+fKKEzvNBji75j6GJHBLN0EGT4BEMzF54sgt+eqzk2jtHMuHkc2oNd8gKYtv21i1 EmMhyH78G2K4i3s3euqVhR4Z1CVLSDy/YbB557yAI4dXpmpwcFmtczI9Isq0G8yRrgmT uxITFiTBy2CAivwtbt/EQ1F6iBwgiEadMpqj+K3cJMDgiWYGdoz+pPcyHSB9P3qRLHHN unW56Dz/Jreh9/XOapyPEGolHeVKEj41D2EWjywSV7yc9cp6YWNMrfJ8dYrT0aE+xiag YMzjPj8RxPvfuyEsaDL6gQJG6dGIziA8oLyqswtJ5Z7bbdtjZNB4Y07ZZce+P9IQk1ix 6Mcw== X-Gm-Message-State: AOAM53074X98Z+0vHbmzLeCRGHWJNEpTWxBPwAzNm/0cK8UyTNqPQHdB K6RenUh1DKwlsiE9A3pJlRu7X2dT8/qcMQ== X-Google-Smtp-Source: ABdhPJya1qxwkwyvl/ACWHBZOTyrdprYtjmRSrM3/qBhvepLOc7b+2XSgsZT4D1kHnHiBONnIgUl8w== X-Received: by 2002:a02:3f4f:: with SMTP id c15mr9543187jaf.1.1633728242512; Fri, 08 Oct 2021 14:24:02 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 3/9] bsd-user/mmap.c: MAP_ symbols are defined, so no need for ifdefs Date: Fri, 8 Oct 2021 15:23:38 -0600 Message-Id: <20211008212344.95537-4-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::d35; envelope-from=imp@bsdimp.com; helo=mail-io1-xd35.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728383088100001 All these MAP_ symbols are always defined on supported FreeBSD versions (12.2 and newer), so remove the #ifdefs since they aren't needed. Signed-off-by: Warner Losh Reviewed-by: Philippe Mathieu-Daud=C3=A9 Acked-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 4f4fa3ab46..6f33aec58b 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -286,13 +286,9 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start= , abi_ulong size, wrapped =3D repeat =3D 0; prev =3D 0; flags =3D MAP_ANONYMOUS | MAP_PRIVATE; -#ifdef MAP_ALIGNED if (alignment !=3D 0) { flags |=3D MAP_ALIGNED(alignment); } -#else - /* XXX TODO */ -#endif =20 for (;; prev =3D ptr) { /* @@ -407,22 +403,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, printf("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); } -#if MAP_GUARD if (flags & MAP_GUARD) { printf("MAP_GUARD "); } -#endif if (flags & MAP_FIXED) { printf("MAP_FIXED "); } if (flags & MAP_ANONYMOUS) { printf("MAP_ANON "); } -#ifdef MAP_EXCL if (flags & MAP_EXCL) { printf("MAP_EXCL "); } -#endif if (flags & MAP_PRIVATE) { printf("MAP_PRIVATE "); } @@ -432,11 +424,9 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, i= nt prot, if (flags & MAP_NOCORE) { printf("MAP_NOCORE "); } -#ifdef MAP_STACK if (flags & MAP_STACK) { printf("MAP_STACK "); } -#endif printf("fd=3D%d offset=3D0x%llx\n", fd, offset); } #endif @@ -445,7 +435,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, errno =3D EINVAL; goto fail; } -#ifdef MAP_STACK if (flags & MAP_STACK) { if ((fd !=3D -1) || ((prot & (PROT_READ | PROT_WRITE)) !=3D (PROT_READ | PROT_WRITE))) { @@ -453,8 +442,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, goto fail; } } -#endif /* MAP_STACK */ -#ifdef MAP_GUARD if ((flags & MAP_GUARD) && (prot !=3D PROT_NONE || fd !=3D -1 || offset !=3D 0 || (flags & (MAP_SHARED | MAP_PRIVATE | /* MAP_PREFAULT | */ /* MAP_PREFAULT not in mman.h */ @@ -462,7 +449,6 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, errno =3D EINVAL; goto fail; } -#endif =20 if (offset & ~TARGET_PAGE_MASK) { errno =3D EINVAL; --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728481138390.6475818229417; Fri, 8 Oct 2021 14:28:01 -0700 (PDT) Received: from localhost ([::1]:57820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxPM-0001mw-6X for importer@patchew.org; Fri, 08 Oct 2021 17:28:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41152) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLb-0003Dh-8X for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:07 -0400 Received: from mail-il1-x12b.google.com ([2607:f8b0:4864:20::12b]:36439) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLY-0007dq-QJ for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:07 -0400 Received: by mail-il1-x12b.google.com with SMTP id h10so4319747ilq.3 for ; Fri, 08 Oct 2021 14:24:04 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+iCM+yR0qcttTMwYSn2e4jAE9+L2FqOFocc4ASN0OLo=; b=WaZNQ98svrVxbeiuAHb3aA3S5AADbwwegmXYeRgqm4h0HHLSGaGtUUOgULHc7EVxZe F0/XFhQV33ca1wICtcmANt/OQaeKbQaV19C9KyeXtQzqkWh1x6+UiJOsEvRcdam5tYrC lIWmxn+UHfA/cXN2zODHUS1UCcaGpBLl6yFGSKch7xlEEoRobyiZuOx+PnPbQC6DAKpk R0G5ZZEdLHB5wDsAQgsD5vqLwoSvY1aUoUnOneQ2sRuZpdXmNcQmaJNa3dKnp9QIgztg 7J7bktJ7BJEfxq3u8uoyMmzq80hN7n9KAjhtqWJEUUx3GQyzeAsQiVSMaHzwFyfNqS9i qC1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+iCM+yR0qcttTMwYSn2e4jAE9+L2FqOFocc4ASN0OLo=; b=lC9OBK02dfP14MqIzPkVhyxCmxY1fXhj4qfRC6y855IGVhYpx5wgQhN1MURFXjyKYz 7EP5xvUvFtAeZ1Us0Z9rGPVSBR9EW49esVZ3wFsJ2dU3zeJ0azbXeSUq5VmL+9rVxAIb 2RuaPc+oiA/arbhpEJJB4cGd2TC9tDYGOSkAmqQhhcbuxyNPlR3xbCEmGHY7PfS9lAcE Ctmk6FlEBGwpwu6TYqVGIow0mUCRVojlADGepEXlYs4iiBhYovqga72IH3mI7K4ScGjZ /LWHgerFGBtU4yTNRlcHhglDhB4iQYynQcpRTELHJ18wTAp/8UZFBwlyBBJvFgQkbrdi nIfw== X-Gm-Message-State: AOAM531Itegzq+88eQyLyowD7CsSPrV0tGKwN2TEn5sUxasM08b1bxcI zrIwpeCD4p4/oBtF3KBgrqDNG4hNSEaszw== X-Google-Smtp-Source: ABdhPJxwHjiy0WYUE8csiTpcD1Y+ZPD2Xk/nVCljnBSX0YSP9wZIfGm+b9nkfSOmQV+fq9fUwUS4YQ== X-Received: by 2002:a05:6e02:14d3:: with SMTP id o19mr9806343ilk.156.1633728243477; Fri, 08 Oct 2021 14:24:03 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 4/9] bsd-user/mmap.c: mmap return ENOMEM on overflow Date: Fri, 8 Oct 2021 15:23:39 -0600 Message-Id: <20211008212344.95537-5-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::12b; envelope-from=imp@bsdimp.com; helo=mail-il1-x12b.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728481893100002 mmap should return ENOMEM on len overflow rather than EINVAL. Return EINVAL when len =3D=3D 0 and ENOMEM when the rounded to a page length is 0. Found by make check-tcg. Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 6f33aec58b..f0be3b12cf 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -455,11 +455,18 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, goto fail; } =20 - len =3D TARGET_PAGE_ALIGN(len); if (len =3D=3D 0) { errno =3D EINVAL; goto fail; } + + /* Check for overflows */ + len =3D TARGET_PAGE_ALIGN(len); + if (len =3D=3D 0) { + errno =3D ENOMEM; + goto fail; + } + real_start =3D start & qemu_host_page_mask; host_offset =3D offset & qemu_host_page_mask; =20 --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728587212705.9728972771303; Fri, 8 Oct 2021 14:29:47 -0700 (PDT) Received: from localhost ([::1]:33836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxR4-0004cP-8C for importer@patchew.org; Fri, 08 Oct 2021 17:29:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLb-0003DW-5j for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:07 -0400 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]:36785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLZ-0007eQ-MC for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:06 -0400 Received: by mail-io1-xd29.google.com with SMTP id e144so12198816iof.3 for ; Fri, 08 Oct 2021 14:24:05 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1e18TD5eHR2hUes2puSFLwrXKaZMLfYPBvZiD2Wr2TM=; b=3VYYXCluck2vnrtNqBTeMT3yj33QlxkDu+Yt3UzkDD8ah5sw8Olq+johIEyJSNIADi r8rHdA7nqqAAtmCU4i8Nak4iLN7ZyLmodf+6AEmgfHJlHARWvYSDtDPzwlKQygwzWOzX iZtqj+DeqEMX9ykSERIiugAT8PtNzWrgDAC0Lxvr+VjMeFEF/FXSZaKXSXEazFuYOlxL vzu7o8cYx/aUUUxZeaNqa07F1GqYaIizIbI3HvglTRM5z3zT2Hq2CDfG8soj8948AsGY hDx+cVJuRU/sDOihnSTVOmq3B1/XFjWQWwAvojRdey92sHJAQqYlpKPCSOnujUxB0gDq 1G4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1e18TD5eHR2hUes2puSFLwrXKaZMLfYPBvZiD2Wr2TM=; b=lqmUw9k0FqykOb3R7rr8E1bZQ/clrp/ANuScuGdmwAN2qwACNeGNKMb9exfA+Hrpp4 X9sU9zos7x8c06KqjqXPlX3uJNUUe0azqERtD2LBKy8uZ3zqIERLCqgqlsVyhtZNLemK LxBUqmNkruUHPT0bPzvo0TAgvhpPAkFUBZD8DTnQ775nELdX+d3SNhtFUiUa9IqbjdRy rRNu0QeENoxnjqvA5ZT5u/xy6A39HLwkpqtja8cddZ4PQ2+Dsq3kqLMf6Nw+dPQ7W6Ab uhwW2zCgb0cXp0QL1NfvqfXsPuHF9hnXVy0izHSw9ev8Sj4RnEmefSR47cLr9Wk7DYri N51g== X-Gm-Message-State: AOAM533uL3XJjforcpmSFfagR3P9YziafTh8qEmxx4z+k4au7e872ICB 3gxfUJBWZPXUS2+BtIP4UagbLcYR8Xjigw== X-Google-Smtp-Source: ABdhPJwu8Utgr3l+JOKSe4a0cy3RgM6puGnlkkDI4GlNLGLvWkvkRBUM4vLDNMqQjjPVjOrngCuudg== X-Received: by 2002:a6b:2b52:: with SMTP id r79mr3835597ior.103.1633728244432; Fri, 08 Oct 2021 14:24:04 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 5/9] bsd-user/mmap.c: mmap prefer MAP_ANON for BSD Date: Fri, 8 Oct 2021 15:23:40 -0600 Message-Id: <20211008212344.95537-6-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::d29; envelope-from=imp@bsdimp.com; helo=mail-io1-xd29.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728589218100001 MAP_ANON and MAP_ANONYMOUS are identical. Prefer MAP_ANON for BSD since the file is now a confusing mix of the two. Signed-off-by: Warner Losh Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index f0be3b12cf..301108ed25 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -285,7 +285,7 @@ static abi_ulong mmap_find_vma_aligned(abi_ulong start,= abi_ulong size, addr =3D start; wrapped =3D repeat =3D 0; prev =3D 0; - flags =3D MAP_ANONYMOUS | MAP_PRIVATE; + flags =3D MAP_ANON | MAP_PRIVATE; if (alignment !=3D 0) { flags |=3D MAP_ALIGNED(alignment); } @@ -409,7 +409,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, if (flags & MAP_FIXED) { printf("MAP_FIXED "); } - if (flags & MAP_ANONYMOUS) { + if (flags & MAP_ANON) { printf("MAP_ANON "); } if (flags & MAP_EXCL) { @@ -431,7 +431,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, } #endif =20 - if ((flags & MAP_ANONYMOUS) && fd !=3D -1) { + if ((flags & MAP_ANON) && fd !=3D -1) { errno =3D EINVAL; goto fail; } @@ -533,7 +533,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, * qemu_real_host_page_size */ p =3D mmap(g2h_untagged(start), host_len, prot, - flags | MAP_FIXED | ((fd !=3D -1) ? MAP_ANONYMOUS : 0), -= 1, 0); + flags | MAP_FIXED | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); if (p =3D=3D MAP_FAILED) goto fail; /* update start so that it points to the file position at 'offset'= */ @@ -696,8 +696,7 @@ static void mmap_reserve(abi_ulong start, abi_ulong siz= e) } if (real_start !=3D real_end) { mmap(g2h_untagged(real_start), real_end - real_start, PROT_NONE, - MAP_FIXED | MAP_ANONYMOUS | MAP_PRIVATE, - -1, 0); + MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); } } =20 --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728384312369.59114404975594; Fri, 8 Oct 2021 14:26:24 -0700 (PDT) Received: from localhost ([::1]:51622 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxNn-00068q-3k for importer@patchew.org; Fri, 08 Oct 2021 17:26:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLc-0003Fw-2e for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:08 -0400 Received: from mail-il1-x129.google.com ([2607:f8b0:4864:20::129]:37400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLa-0007fQ-H5 for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:07 -0400 Received: by mail-il1-x129.google.com with SMTP id i13so11308029ilm.4 for ; Fri, 08 Oct 2021 14:24:06 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kh9FF1ChBgsarVfVAqz0ob9kRn+eek1S73Cr8kxiPG8=; b=30NlvziNpDjGhJsagXWNX0D9ZyhJ/fx6q5G4joCt1fkQmLgupDqHoDjXsPy4XxmN5/ liu0WgcHcwF0yHoPolZe6d1P6mf7ZlNH4Vu2Y64i9MIp/sO5PkmtlVV6N+7SjlL5+MOA HY7PuHRRkW6F4EY1wgeDo5l3hR1xUhA3i87oNxUq1T9BOu4YIxjkS3Q3rk5PKThFEDcc Ofw0hby+JizVPJJOsuakp20loV8SZwUvAndDMQDyIgbFf22ArOJML+VvpPy3Or0fuLwb Gj9uZUpv46JaveHPt1zYc5xeYoRf+3Ng+M82DiCJ7vyl55cKoctBtdMPeyrV3pJt3yNH AQfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kh9FF1ChBgsarVfVAqz0ob9kRn+eek1S73Cr8kxiPG8=; b=oQk0n/QJDe6W4peNbFT6P7VaeJ/OVGSfSZkczOPQeDYic0bwKUEFmTW21kk8DvDk2h HZUexslgtvfkkBBSBFiDVkY6erTGqtr/tP9csaKuK/MktLW3gsssi0LOgedbM1lvn3So b3E5pMbd8i6wZvMsXrpaZWAkO8t76T7M6nk9iMlcOE6M/lHVMYKpsJOsuJbhCQEASdsC Mghnu3fLAXm42f/AZgJVWtvr4Ep/Ar0mi9RgaAyE7CIB+clbYq9gWcldcYcWKh3J8VG0 mHDm4Etfnr/A8RbVu+VaogxVEW+Ledr5ecWz08iLj557kQrbhU7JjE/1j2wjQ06UU70s 8+ww== X-Gm-Message-State: AOAM531WrQBqQgXsmgIOe87/TUphumw2HKUVrEMHwftGT1VdjfVhoN0u x4wzdy6OW/QhxyOHMnzQmPZyyoDhSN2iZw== X-Google-Smtp-Source: ABdhPJwEAh9M41kdkbS3glwBTQfvj5/woww7XsQr7iMAUfgCXTvl72RjfJNhA7TCYQlumLZ1eDYtoA== X-Received: by 2002:a92:2001:: with SMTP id j1mr9317260ile.84.1633728245221; Fri, 08 Oct 2021 14:24:05 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 6/9] bsd-user/mmap.c: Convert to qemu_log logging for mmap debugging Date: Fri, 8 Oct 2021 15:23:41 -0600 Message-Id: <20211008212344.95537-7-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-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::129; envelope-from=imp@bsdimp.com; helo=mail-il1-x129.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728385163100003 Content-Type: text/plain; charset="utf-8" Convert DEBUG_MMAP to qemu_log CPU_LOG_PAGE. Signed-off-by: Warner Losh Reviewed-by: Kyle Evans Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 53 +++++++++++++++++++++---------------------------- 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 301108ed25..face98573f 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -21,8 +21,6 @@ #include "qemu.h" #include "qemu-common.h" =20 -//#define DEBUG_MMAP - static pthread_mutex_t mmap_mutex =3D PTHREAD_MUTEX_INITIALIZER; static __thread int mmap_lock_count; =20 @@ -67,14 +65,11 @@ int target_mprotect(abi_ulong start, abi_ulong len, int= prot) abi_ulong end, host_start, host_end, addr; int prot1, ret; =20 -#ifdef DEBUG_MMAP - printf("mprotect: start=3D0x" TARGET_ABI_FMT_lx - "len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c\n", start, len, - prot & PROT_READ ? 'r' : '-', - prot & PROT_WRITE ? 'w' : '-', - prot & PROT_EXEC ? 'x' : '-'); -#endif - + qemu_log_mask(CPU_LOG_PAGE, "mprotect: start=3D0x" TARGET_ABI_FMT_lx + " len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c\n", start,= len, + prot & PROT_READ ? 'r' : '-', + prot & PROT_WRITE ? 'w' : '-', + prot & PROT_EXEC ? 'x' : '-'); if ((start & ~TARGET_PAGE_MASK) !=3D 0) return -EINVAL; len =3D TARGET_PAGE_ALIGN(len); @@ -391,45 +386,43 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en; =20 mmap_lock(); -#ifdef DEBUG_MMAP - { - printf("mmap: start=3D0x" TARGET_ABI_FMT_lx - " len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c flags=3D", - start, len, - prot & PROT_READ ? 'r' : '-', - prot & PROT_WRITE ? 'w' : '-', - prot & PROT_EXEC ? 'x' : '-'); + if (qemu_loglevel_mask(CPU_LOG_PAGE)) { + qemu_log("mmap: start=3D0x" TARGET_ABI_FMT_lx + " len=3D0x" TARGET_ABI_FMT_lx " prot=3D%c%c%c flags=3D", + start, len, + prot & PROT_READ ? 'r' : '-', + prot & PROT_WRITE ? 'w' : '-', + prot & PROT_EXEC ? 'x' : '-'); if (flags & MAP_ALIGNMENT_MASK) { - printf("MAP_ALIGNED(%u) ", (flags & MAP_ALIGNMENT_MASK) - >> MAP_ALIGNMENT_SHIFT); + qemu_log("MAP_ALIGNED(%u) ", + (flags & MAP_ALIGNMENT_MASK) >> MAP_ALIGNMENT_SHIFT); } if (flags & MAP_GUARD) { - printf("MAP_GUARD "); + qemu_log("MAP_GUARD "); } if (flags & MAP_FIXED) { - printf("MAP_FIXED "); + qemu_log("MAP_FIXED "); } if (flags & MAP_ANON) { - printf("MAP_ANON "); + qemu_log("MAP_ANON "); } if (flags & MAP_EXCL) { - printf("MAP_EXCL "); + qemu_log("MAP_EXCL "); } if (flags & MAP_PRIVATE) { - printf("MAP_PRIVATE "); + qemu_log("MAP_PRIVATE "); } if (flags & MAP_SHARED) { - printf("MAP_SHARED "); + qemu_log("MAP_SHARED "); } if (flags & MAP_NOCORE) { - printf("MAP_NOCORE "); + qemu_log("MAP_NOCORE "); } if (flags & MAP_STACK) { - printf("MAP_STACK "); + qemu_log("MAP_STACK "); } - printf("fd=3D%d offset=3D0x%llx\n", fd, offset); + qemu_log("fd=3D%d offset=3D0x%lx\n", fd, offset); } -#endif =20 if ((flags & MAP_ANON) && fd !=3D -1) { errno =3D EINVAL; --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728727048983.9774091986427; Fri, 8 Oct 2021 14:32:07 -0700 (PDT) Received: from localhost ([::1]:38080 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxTJ-0007Zg-Lw for importer@patchew.org; Fri, 08 Oct 2021 17:32:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41178) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLd-0003Iq-BB for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:09 -0400 Received: from mail-io1-xd2e.google.com ([2607:f8b0:4864:20::d2e]:33353) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLb-0007gL-JF for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:09 -0400 Received: by mail-io1-xd2e.google.com with SMTP id n7so3334133iod.0 for ; Fri, 08 Oct 2021 14:24:07 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5zvZO2JIzhKG0lGaFVeCYf0u5EXqJ+A9G0XWhWcAtPw=; b=ZAZKTTNjMrlA4Nj2FdZcBcFqyyrufiOIfZLgvtkWslClmxdYneTc57OwpnYDfpSASz T5Yd3p00wsWx/ehYMDE/yiEoFaP+R5HJ8QY0bouTo1yqJs9OtaQ0WWfTtau0+kJeL8zR 9al8DQp21Bu0shcpw1xoMOdeLrxj3ZYu8dxhVE1N+e2u+mEjgpNfF3Cm/z1YyTWs4fU4 S3SBfHLQspXEtHZxZShEtFaWteKO9ojEIy68J0gmyQmO6HnEF8vre9SelHfIyvi/KJSd OpGnqAh9b7SFR+MVb85bZuv8jjcs2wG4qy67F/FghZ7fhhw7ryHMsBTOT0hDNLFdfK78 v8rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5zvZO2JIzhKG0lGaFVeCYf0u5EXqJ+A9G0XWhWcAtPw=; b=AVaqou7q6SfJq9o/lHPmACuHZa47/MjaRqY0nU4f3+0dRQYvHRLW72JPZ9gIEXYnmC dCdhi1logvr3u/AbOWvS5MZ4shRIZM/HIIG4BNzuZ02gB2Fgp+MnPHrW7bJ/d3T2ZA+F M5SU2/twp2DsO+H3q0k25oJ3DGwDOUlPG9/h3XR8dGQfppu/MkQMPrYeeGW1jDWVKSAI ZqrqjIYmgvGS0q02lIc3EQ8QnUbBMivbztTftSPJlp66mBq9uAY77qYDr/UJWy7I+COW k+UCmc7CzrYDyIZebK03awlIIgGHokrYzxmz5JIS1mra7klYl+0xpxvkW61we7WtPmvW FAyA== X-Gm-Message-State: AOAM530wmSRbsrDV4PTF5RUu6E0h9wP6JhiINvWG8DvTATrw/aofMwem HpIAkhLccJFVQDS3FVrwOkbJwmUSMyUUaQ== X-Google-Smtp-Source: ABdhPJykTx1dKWhwZjy8mw2ceJFjUEAtBvL5BAa0BweS1aHfecPCCstf1N9IpTABw0C8RPFTFENxPw== X-Received: by 2002:a6b:8f86:: with SMTP id r128mr9471024iod.201.1633728246214; Fri, 08 Oct 2021 14:24:06 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 7/9] bsd-user/mmap.c: Don't mmap fd == -1 independently from MAP_ANON flag Date: Fri, 8 Oct 2021 15:23:42 -0600 Message-Id: <20211008212344.95537-8-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-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::d2e; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2e.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, Guy Yur , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728729020100001 Content-Type: text/plain; charset="utf-8" From: Guy Yur Switch checks for !(flags & MAP_ANONYMOUS) with checks for fd !=3D -1. MAP_STACK and MAP_GUARD both require fd =3D=3D -1 and don't require mapping the fd either. Add analysis from Guy Yur detailing the different cases for MAP_GUARD and MAP_STACK. Signed-off-by: Guy Yur [ partially merged before, finishing the job and documenting origin] Signed-off-by: Warner Losh Reviewed-by: Kyle Evans Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index face98573f..4ecd949a10 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -127,7 +127,27 @@ error: return ret; } =20 -/* map an incomplete host page */ +/* + * map an incomplete host page + * + * mmap_frag can be called with a valid fd, if flags doesn't contain one of + * MAP_ANON, MAP_STACK, MAP_GUARD. If we need to map a page in those cases= , we + * pass fd =3D=3D -1. However, if flags contains MAP_GUARD then MAP_ANON c= annot be + * added. + * + * * If fd is valid (not -1) we want to map the pages with MAP_ANON. + * * If flags contains MAP_GUARD we don't want to add MAP_ANON because it + * will be rejected. See kern_mmap's enforcing of constraints for MAP_G= UARD + * in sys/vm/vm_mmap.c. + * * If flags contains MAP_ANON it doesn't matter if we add it or not. + * * If flags contains MAP_STACK, mmap adds MAP_ANON when called so doesn't + * matter if we add it or not either. See enforcing of constraints for + * MAP_STACK in kern_mmap. + * + * Don't add MAP_ANON for the flags that use fd =3D=3D -1 without specifyi= ng the + * flags directly, with the assumption that future flags that require fd = =3D=3D -1 + * will also not require MAP_ANON. + */ static int mmap_frag(abi_ulong real_start, abi_ulong start, abi_ulong end, int prot, int flags, int fd, abi_ulong offset) @@ -147,9 +167,9 @@ static int mmap_frag(abi_ulong real_start, } =20 if (prot1 =3D=3D 0) { - /* no page was there, so we allocate one */ + /* no page was there, so we allocate one. See also above. */ void *p =3D mmap(host_start, qemu_host_page_size, prot, - flags | MAP_ANON, -1, 0); + flags | ((fd !=3D -1) ? MAP_ANON : 0), -1, 0); if (p =3D=3D MAP_FAILED) return -1; prot1 =3D prot; @@ -157,7 +177,7 @@ static int mmap_frag(abi_ulong real_start, prot1 &=3D PAGE_BITS; =20 prot_new =3D prot | prot1; - if (!(flags & MAP_ANON)) { + if (fd !=3D -1) { /* msync() won't work here, so we return an error if write is possible while it is a shared mapping */ if ((flags & TARGET_BSD_MAP_FLAGMASK) =3D=3D MAP_SHARED && @@ -565,7 +585,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, in= t prot, * worst case: we cannot map the file because the offset is not * aligned, so we read it */ - if (!(flags & MAP_ANON) && + if (fd !=3D -1 && (offset & ~qemu_host_page_mask) !=3D (start & ~qemu_host_page_= mask)) { /* * msync() won't work here, so we return an error if write is --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728588522752.5628896077131; Fri, 8 Oct 2021 14:29:48 -0700 (PDT) Received: from localhost ([::1]:33900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxR5-0004f3-GS for importer@patchew.org; Fri, 08 Oct 2021 17:29:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41190) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLe-0003Lh-4r for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:10 -0400 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]:36789) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLc-0007gu-Ha for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:09 -0400 Received: by mail-io1-xd2d.google.com with SMTP id e144so12198936iof.3 for ; Fri, 08 Oct 2021 14:24:08 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FSmgGGa3oZMyK2O7LtPwzHk7PXI/hjwdJDle7ItjGLQ=; b=uCmXVjqScyWtFiwE3HbnOuqZW+IojCyxpkVBl/Y45hn9DByl/u4gpxlZ9QjWvxjr+t OxkZWiW7+99tgm2DkMPfR1NlC4tkfLx5f/oxa/3jRiQOCVcAquf2SsgggykI6SiSPQji xqtcGYfvow4b71Lmd/d2xiXUYahDonKAjCXRiGgFm/ClehZZXl5x2WkfMbBGM0wrllTG SQMHobU3aTttH1IeAADt3ce1x3uSSqhcsDf01LlN+0UifsfGwcKIaHcUPuaJ/123eRd9 Gxx40vIr3zHYIbMsHgT2Bq5P7Qi9sqMIt2YfJ25yWYMtlOhLE2iYAcbkUUqOqsc38Bnq m5wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FSmgGGa3oZMyK2O7LtPwzHk7PXI/hjwdJDle7ItjGLQ=; b=JVfd1ObxLTQxye/Kf8xDC+1GdDkSfgkFcrzP/oFTYpaRngMRLj4QCSwvW1ZsH2Yidj XEZZgBvHJ+MsCsOAgkCID4n8fOrNIP+VUt0/7Qw1PZfcLsFet9rNQCKsuHNCdZ5Otwuq rvhlshS/VANg0a++u66R0Q6k0EmokWRaU7o7ggBiIecUhP4YVEtvXbEMdiZ5lv/frGBf +QmelSW2VxdK1CafCp5L6FrKWY3/TqKTj1R66eThD9Fm7/yYIywSupusmBSQOdPJzXFK 2yn1cqfBoLpsOg1Ls97+ksIk+S5kSE48IhwO51ZvOmJcZD5LCrm1nMPNEwB/AgZZjmUL +nQw== X-Gm-Message-State: AOAM533keQtCMB4oS8eK5E85ROOX08JW++3zUqxw+jPbEfAt6znKCZbJ 2GEpwyy5kWAsRTAtQrA8nPux3G3henHyaA== X-Google-Smtp-Source: ABdhPJybBCT+NjjFHOWxCAw+oS9wIVsDtPBmr/MsnwUmh2buix+5p9eHwVjE0pMkxpOjtIfKbWFh/g== X-Received: by 2002:a5e:d80a:: with SMTP id l10mr9431148iok.182.1633728247197; Fri, 08 Oct 2021 14:24:07 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 8/9] bsd-user/mmap.c: Implement MAP_EXCL, required by jemalloc in head Date: Fri, 8 Oct 2021 15:23:43 -0600 Message-Id: <20211008212344.95537-9-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-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::d2d; envelope-from=imp@bsdimp.com; helo=mail-io1-xd2d.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kyle Evans , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728589224100002 Content-Type: text/plain; charset="utf-8" From: Kyle Evans jemalloc requires a working MAP_EXCL. Ensure that no page is double mapped when specified. In addition, use guest_range_valid_untagged to test for valid ranges of pages rather than an incomplete inlined version of the test that might be wrong. Signed-off-by: Kyle Evans Signed-off-by: Warner Losh Reviewed-by: Richard Henderson --- bsd-user/mmap.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 4ecd949a10..066d9c10ff 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -403,7 +403,7 @@ abi_ulong mmap_find_vma(abi_ulong start, abi_ulong size) abi_long target_mmap(abi_ulong start, abi_ulong len, int prot, int flags, int fd, off_t offset) { - abi_ulong ret, end, real_start, real_end, retaddr, host_offset, host_l= en; + abi_ulong addr, ret, end, real_start, real_end, retaddr, host_offset, = host_len; =20 mmap_lock(); if (qemu_loglevel_mask(CPU_LOG_PAGE)) { @@ -574,12 +574,10 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, = int prot, * It can fail only on 64-bit host with 32-bit target. * On any other target/host host mmap() handles this error correct= ly. */ -#if TARGET_ABI_BITS =3D=3D 32 && HOST_LONG_BITS =3D=3D 64 - if ((unsigned long)start + len - 1 > (abi_ulong) -1) { + if (!guest_range_valid_untagged(start, len)) { errno =3D EINVAL; goto fail; } -#endif =20 /* * worst case: we cannot map the file because the offset is not @@ -614,6 +612,12 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, i= nt prot, goto the_end; } =20 + /* Reject the mapping if any page within the range is mapped */ + if ((flags & MAP_EXCL) && page_check_range(start, len, 0) < 0) { + errno =3D EINVAL; + goto fail; + } + /* handle the start of the mapping */ if (start > real_start) { if (real_end =3D=3D real_start + qemu_host_page_size) { --=20 2.32.0 From nobody Mon May 13 20:02:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 1633728736980582.774425977309; Fri, 8 Oct 2021 14:32:16 -0700 (PDT) Received: from localhost ([::1]:38192 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mYxTU-0007e8-0R for importer@patchew.org; Fri, 08 Oct 2021 17:32:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mYxLf-0003Ox-1H for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:11 -0400 Received: from mail-il1-x131.google.com ([2607:f8b0:4864:20::131]:38583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mYxLd-0007i9-DJ for qemu-devel@nongnu.org; Fri, 08 Oct 2021 17:24:10 -0400 Received: by mail-il1-x131.google.com with SMTP id r9so11330260ile.5 for ; Fri, 08 Oct 2021 14:24:09 -0700 (PDT) Received: from dune.bsdimp.com (50-253-99-174-static.hfc.comcastbusiness.net. [50.253.99.174]) by smtp.gmail.com with ESMTPSA id a4sm186620ild.52.2021.10.08.14.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Oct 2021 14:24:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdimp-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KX/YI8ttwHulmDkzNb2DvIlZKfdvjYqr0a8Bt5W1x6I=; b=fHYeDFYJA2hfDEE6kZ2JPd60+a1iN7MaRq6MSQDTRmQDc5x2FBu8cvYLgh1R4DtKZu J/rhee+gO1MXv/i/5qPSsXrU6BE5GwowPriW6WyHXbdxGLo7dnwu8wV6PxxXoCJorU2N 6/YDmONvUNJNIMIpBiapoea172Dx33uajSUmRgDYy/lwKX0lxGNIkMEcP+iLxdH+7vYE /UyeeNIIULVbduy41zaBmT5dNRir+h7jzmRuFXqyX+Qa7vHx+vKTjc8G8eZMY4pTRW81 nBFIcUncAoMqaeN4PHgSEqHFDqL1MFJfckeMTuYoGjfAGprHOCGSz/rMgQCijnHYJZLO PRpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KX/YI8ttwHulmDkzNb2DvIlZKfdvjYqr0a8Bt5W1x6I=; b=AUyM5+m5w82l+NT30zRwRepingSQobqof4tDNiVYrSTi1N6OCoiiomNFedvEHhvM8i lUw+hx8tcy9+6KQqANO3c2GnhgREuzxn4yAgxS72e7scXa/7MlbSeyjOU4zhgeEsHAS0 bE5BL95rlkEK81e7p5K6VQaIn/SJey1RYEVlRDXoNfPb1amFDNW8JLTKxNrZ/nkNx1Ke GrcexPjF8vrsr47miUKcHXE1QGWObRM0DGQfulAB3BsEcdKZdjbasrY42jKyip3+BQqp netCgIzFiLt8hmp4pttELCzRuTJITpEPhHbvKKvVcu7LAbc4JDgjfyk3qSdPh2q4wL7M shew== X-Gm-Message-State: AOAM533CX83C5nvSQvDfXCKqpwMj4+7GOPfoNae8WLhyQfdC2k6Por1p 6+NsUHgEXHWIPEHcj6vEEshpK2B1+nFgMA== X-Google-Smtp-Source: ABdhPJyWlz7Tk1jlwNA2yUAyKCrcz97Ko4utEjrxxJ4d/zxMAxz5Xla2zPQpJzy2S0q0lyf7+LjFgw== X-Received: by 2002:a05:6e02:c0d:: with SMTP id d13mr10093188ile.163.1633728248025; Fri, 08 Oct 2021 14:24:08 -0700 (PDT) From: Warner Losh To: qemu-devel@nongnu.org Subject: [PATCH v3 9/9] bsd-user/mmap.c: assert that target_mprotect cannot fail Date: Fri, 8 Oct 2021 15:23:44 -0600 Message-Id: <20211008212344.95537-10-imp@bsdimp.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20211008212344.95537-1-imp@bsdimp.com> References: <20211008212344.95537-1-imp@bsdimp.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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::131; envelope-from=imp@bsdimp.com; helo=mail-il1-x131.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kevans@freebsd.org, =?UTF-8?q?Mika=C3=ABl=20Urankar?= , richard.henderson@linaro.org, f4bug@amsat.org, Warner Losh Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1633728737643100001 Similar to the equivalent linux-user change 86abac06c14. All error conditions that target_mprotect checks are also checked by target_mmap. EACCESS cannot happen because we are just removing PROT_WRITE. ENOMEM should not happen because we are modifying a whole VMA (and we have bigger problems anyway if it happens). Fixes a Coverity false positive, where Coverity complains about target_mprotect's return value being passed to tb_invalidate_phys_range. Signed-off-by: Mika=C3=ABl Urankar Signed-off-by: Warner Losh Reviewed-by: Richard Henderson Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kyle Evans --- bsd-user/mmap.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bsd-user/mmap.c b/bsd-user/mmap.c index 066d9c10ff..4586ad27d0 100644 --- a/bsd-user/mmap.c +++ b/bsd-user/mmap.c @@ -604,10 +604,7 @@ abi_long target_mmap(abi_ulong start, abi_ulong len, i= nt prot, } if (!(prot & PROT_WRITE)) { ret =3D target_mprotect(start, len, prot); - if (ret !=3D 0) { - start =3D ret; - goto the_end; - } + assert(ret =3D=3D 0); } goto the_end; } --=20 2.32.0