From nobody Fri Aug 25 01:08:37 2023 X-Original-To: dev-commits-src-branches@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 4RX1zn3mt4z4qbDn; Fri, 25 Aug 2023 01:08:37 +0000 (UTC) (envelope-from git@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 4RX1zn3LRxz4SxJ; Fri, 25 Aug 2023 01:08:37 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925717; 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=Q6upNcGKXtC0tMfspP+Di5qjnGoUp2xQ8PO7voQYumo=; b=hum1su80ZFYKEoeiaboJNZ0bco6BUT/DLUMY7FwTby6ffrIE70i7RmCpy5O8NHlNCGTWKB rfPUrpi0xoxhy3vXgabjYIEHyrASG2ac3jrZpqglNJOJMgWf8uaV09CFudgDVvxNzejEs/ bcXMJMOq4qDn7UBeyIc+EVmCLrlDEi4cKZRFog+DOImkYlA0hyPkBrydcclUbcQkiq2lby fVzudY/t6mN4SZ0Oiy/TWg8YtfqJF/qhaQ86mkXGeIBHiWb9k8ICj8tyT6KuWjBZXAyMTa Im8rjyyEC+QrBJzZSKcXePruFQysIosAtMw8rk3877tPEJNk9eIuAFg5exG8Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925717; 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=Q6upNcGKXtC0tMfspP+Di5qjnGoUp2xQ8PO7voQYumo=; b=jDohF+WlJTfchDHZ6p6vcDHOxJRU/T3fd/WWomQdLZ8mauoR2XSX2W3MHn4M2EgysFead6 ZCc+GjnWHJA1u1OscTIANwL+4nFjTm7lYZwZJggvFUKn+NYjX6d2HgbJUbS1btJv7Ni9wz vFd7NSJ18yC3rLOf75jUd4VYz2LN5M3FGC0/pOJcG8a/PEzBIIvPK5jh9bg6bgZlX3Ln6p GkEgN26tnNAIdldRcS8v3d12/Yp04fv9pdht1U6ZVW1v3pAen0CAqODqNywfjbXwRXhY6o ryniRYX4oXeMbl56kji/fiG2mdd7PRJvdYtDhf5+bjDy8FDWQNZaUvOlw1mfcA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692925717; a=rsa-sha256; cv=none; b=JHjjpVamqSmRfNA0zo2A8gpxQjcRGcUUY0LwRK6w3/4l9UFFjRq2aSl9dIJIBugKLTBQu2 O64kVDn73KzXMANWOJZL3kMAH5pbbcxo4/xGwSb1gKk7lPMPJkhpLVMABC2viP1v6SHTJo 285atGkACXfkrFGuacyxR527gQiVk08qvD3OZvCSIBqUJvwlmxqGZFxkz+MEib78v61rQ+ nDZhq7y2dF/tSW7jADl2zHRq/981g7YcVs8ddemPsxhf7vNiSANbBhM0V3y5haRg+utasW bF9+v3QpKdwM5RMXUNSl2U0WkHgS5n2n0jomyk7iU26Z2xPjdTbSGWFpQgssEg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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 4RX1zn2R5Tzpkv; Fri, 25 Aug 2023 01:08:37 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37P18bxc058511; Fri, 25 Aug 2023 01:08:37 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37P18bdd058508; Fri, 25 Aug 2023 01:08:37 GMT (envelope-from git) Date: Fri, 25 Aug 2023 01:08:37 GMT Message-Id: <202308250108.37P18bdd058508@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: d5fccc19aa1b - stable/13 - vm_map_protect(): add VM_MAP_PROTECT_GROWSDOWN flag List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: d5fccc19aa1b1e9440b5ad3bc386b6bb42fdff78 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=d5fccc19aa1b1e9440b5ad3bc386b6bb42fdff78 commit d5fccc19aa1b1e9440b5ad3bc386b6bb42fdff78 Author: Konstantin Belousov AuthorDate: 2023-07-28 00:40:53 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-25 01:06:44 +0000 vm_map_protect(): add VM_MAP_PROTECT_GROWSDOWN flag (cherry picked from commit 90049eabcfadf229e3983f04310a8ea28fe3d2b1) --- sys/vm/vm_map.c | 19 +++++++++++++++++++ sys/vm/vm_map.h | 1 + 2 files changed, 20 insertions(+) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 1f223bbbd396..029605eb272a 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2752,6 +2752,7 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_map_entry_t entry, first_entry, in_tran, prev_entry; vm_object_t obj; struct ucred *cred; + vm_offset_t orig_start; vm_prot_t check_prot, max_prot, old_prot; int rv; @@ -2763,8 +2764,10 @@ vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, !CONTAINS_BITS(new_maxprot, new_prot)) return (KERN_OUT_OF_BOUNDS); + orig_start = start; again: in_tran = NULL; + start = orig_start; vm_map_lock(map); if ((map->flags & MAP_WXORX) != 0 && @@ -2787,6 +2790,22 @@ again: if (!vm_map_lookup_entry(map, start, &first_entry)) first_entry = vm_map_entry_succ(first_entry); + if ((flags & VM_MAP_PROTECT_GROWSDOWN) != 0 && + (first_entry->eflags & MAP_ENTRY_GROWS_DOWN) != 0) { + /* + * Handle Linux's PROT_GROWSDOWN flag. + * It means that protection is applied down to the + * whole stack, including the specified range of the + * mapped region, and the grow down region (AKA + * guard). + */ + while (!CONTAINS_BITS(first_entry->eflags, + MAP_ENTRY_GUARD | MAP_ENTRY_STACK_GAP_DN) && + first_entry != vm_map_entry_first(map)) + first_entry = vm_map_entry_pred(first_entry); + start = first_entry->start; + } + /* * Make a first pass to check for protection violations. */ diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 8adfcaf57cb3..9e4e1db0fd98 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -518,6 +518,7 @@ vm_map_entry_succ(vm_map_entry_t entry) #define VM_MAP_PROTECT_SET_PROT 0x0001 #define VM_MAP_PROTECT_SET_MAXPROT 0x0002 +#define VM_MAP_PROTECT_GROWSDOWN 0x0004 int vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_prot_t new_prot, vm_prot_t new_maxprot, int flags);