From nobody Wed Jul 19 00:40:13 2023 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4R5H654yx9z4nqHS for ; Wed, 19 Jul 2023 00:40:13 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4R5H65097Kz40GC for ; Wed, 19 Jul 2023 00:40:13 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1689727213; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=hIHCp6GkzGaVD4eZGYAI2S2qSwEJE+nHEPfKWBQZ7TI=; b=FNH8h3RXri3GbFRdtJoJXsEpKFhp0ihbS1zDWUjihV9SkTbP0sXPtRXTECx7aZ4QDlWiY8 dfxjy1nq1iGaB4Tdz/kM7mpF3+TL+umMhZjJlntErze+NEqEdLgdkhC4Ws0mSLaiLXjAK+ U/1JxyQamorYJb/TKL6Kky4rLbO8Wkm85IRP8ZAFVTm0+/uugMIiT/H5227RtaXHQ4ccYO 2ZS+4D7QbqyT4dlb29X4fIu73klS5UyQD5Lbqu/AInCj1Rq/BVMijO/gwFtZuIJ0yz5xB3 6dg7wJNSCNmgYrxIFaHv75oc0zDV7hie1a3ytt6elwGrhDDypd9N9XuQs168Yg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1689727213; a=rsa-sha256; cv=none; b=PrFyPwVsO3gEhz02lgNWqfhN4m8GrKp0fyD9uIaCrVHgv1k9Y5+0knMcCmvYCun39Dqvvk Uhq6flCPhC8L/GKvfne9KRunKBcitVQ88j4rJ3v+mMNaTkR/OIDq3hDoyupsZwrMJcS2H+ bOCaqfrv7y8TuWy8VWr16HEE/9mvPOAEpYIUYoqkkrTnj7gjuYb2tfK0cPdzNKpMZJHN5f HnSMU9h3WlRBSEKCaH7ac/eudtg5QPi1LaeNRcngcHYXcKFL89BZ+AIzmzWmcytz/Uy200 LG5n7kDEllt4h1HZt6Y5PCkEyN+1A70sgwo9Wxbss537eNvBp1FcdSVFZTrlbQ== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4R5H646LvlzR63 for ; Wed, 19 Jul 2023 00:40:12 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 36J0eC8p060388 for ; Wed, 19 Jul 2023 00:40:12 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 36J0eCCF060386 for bugs@FreeBSD.org; Wed, 19 Jul 2023 00:40:12 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 272585] calling mprotect in an mmap-ed stack can affect non-target pages Date: Wed, 19 Jul 2023 00:40:13 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: kern X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Only Me X-Bugzilla-Who: jfc@mit.edu X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.mimetype attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D272585 Bug ID: 272585 Summary: calling mprotect in an mmap-ed stack can affect non-target pages Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Only Me Priority: --- Component: kern Assignee: bugs@FreeBSD.org Reporter: jfc@mit.edu Attachment #243475 text/plain mime type: Created attachment 243475 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D243475&action= =3Dedit mmap-ed stack with an inaccessible gap If I call mmap with MAP_GROWSDOWN|MAP_STACK and use mprotect to mark the 32= nd page from the top inaccessible (PROT_NONE), lower addresses in the region a= lso become inaccessible. This is an odd thing to do, I agree, but it happened = in a real program. Put another way: I call mmap with stack hints and get pages 0-255. Before touching the memory I call mprotect(PROT_NONE) on page 224. Now pages 1-223 are also inaccessible. The target of mprotect has to be 32 pages down, not 31 or 33, at least with= my system's configuration. Perhaps 32 pages is the initial mapped size of a s= tack region and when the stack grows it clones the page attributes of the lowest address. I attached an example that crashes reading an address that should be valid.= It works on Mac OS (without the unsupported MAP_GROWSDOWN|MAP_STACK flags) and Linux. (This is simplified from a larger program that allocates a highly aligned 1= MB stack by mapping a larger region and using mprotect to install guard pages.= It is not the "right" way to do it when MAP_ALIGNED is available. The program= was written first on Linux which doesn't have that option.) Reproduced on 13.2-STABLE/amd64, 13.2-STABLE/aarch64, 14-CURRENT/amd64. --=20 You are receiving this mail because: You are the assignee for the bug.=