From nobody Sat Aug 12 06:29:13 2023 X-Original-To: dev-commits-src-all@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 4RN9jk0Cpdz4Tvjr; Sat, 12 Aug 2023 06:29:14 +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 4RN9jj2xjbz3YDG; Sat, 12 Aug 2023 06:29:13 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691821753; 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=aqb5C4fxeqyMFTNu3Fb5Ndu6SxoppcABebz5GkqQPEs=; b=abaCyryKg3gn+H26umK2+TxD9wv/Ml5cuKSNkYfHIyDUxL6+g/vM4q2Utkwx0fHtI0zK9w PWvS9IziR/wbkhNfJaP+9zdESxNDgOR+U5W71/woYXh7vi/7WrKK9UdaWu2wIOtDVIZoci JmCiZAabZbXjb+O6WEahRIExwTjpkvBq96ffLflqjC1XZ3TSS0WB+mimOWnzymsiBl/NBa f/6GS51lMMP0LlceEtQZEgPFED+ds1XHvvEO1Qe82tRJVDZtZMZntavTuUwbgtXWGFqIxv wblKqxzAxQ2U86bVzVPT0A2ucy0OQgpZDKSIHg48mTauHgJVXJJbdf4sUSlC1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1691821753; 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=aqb5C4fxeqyMFTNu3Fb5Ndu6SxoppcABebz5GkqQPEs=; b=ZRiTY2FrRDWfGv7tBMSCfJDyEz+6MROmJyayNKEgqlre0e0o00RyBcqEw8OCYpicpjtzMI dyAjkj6KRnBoqjuhIkPZ6O0y6XpsNfcneCwgzu1PiwIvVo/5v+hg17s0fC6YYD+FRb1BVN yqhPrAOYhSRR8S8eYjRMUdUR1Xw/+2uBsMtqbgvanxeHjKKaiuyWEfevuZC7RIeHnT8jmG Z6xQ5RIuJfAv5Xg4G2HvOyYjoSiyXVAINa1tuOkPTKpGItWnGWHvcjiF/qMR6DU+g+T7Qa oqWwvSlQfce6DkUqYANz3C+OXZ2UbqLuctGqUvE5VB+SRqw31kAwZWlLJoSztA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1691821753; a=rsa-sha256; cv=none; b=jK9cdup6/zsJzgDS0sSAtZ/wAjfz31stoENTlx3cykxiPjTA3l4zOhPTAv5UEbeKmY5HCw jcnRIdpdSAPCtr6y0gJwrwjX/ak87CIWXJDzrLI+8BB6JT+mLm7sMwWEbEjNZ5iIiQcBTR kym9GavX23raZzTWVWO4NRUeXXiDEl6LBhXQo48ZACQ5v0rbFYmYJtjuSyjpe5iRqbxCJG vgfpbyjKE/OSdu2mEL36GjFKal2PfMs3gJq95yOi6NF2CNJEQO9vq1SlSA7LrGxbKBveA1 nG3FVRWK+SdR592S6bDvy2Lbp8QtOmkl+p03CzLVkivlzDOivuTyo791SmzNtw== 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 4RN9jj1XDvz191t; Sat, 12 Aug 2023 06:29:13 +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 37C6TDnE025055; Sat, 12 Aug 2023 06:29:13 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37C6TD7b025052; Sat, 12 Aug 2023 06:29:13 GMT (envelope-from git) Date: Sat, 12 Aug 2023 06:29:13 GMT Message-Id: <202308120629.37C6TD7b025052@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 90049eabcfad - main - vm_map_protect(): add VM_MAP_PROTECT_GROWSDOWN flag List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 90049eabcfadf229e3983f04310a8ea28fe3d2b1 Auto-Submitted: auto-generated The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=90049eabcfadf229e3983f04310a8ea28fe3d2b1 commit 90049eabcfadf229e3983f04310a8ea28fe3d2b1 Author: Konstantin Belousov AuthorDate: 2023-07-28 00:40:53 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-12 06:28:14 +0000 vm_map_protect(): add VM_MAP_PROTECT_GROWSDOWN flag which requests to propagate lowest stack segment protection to the grow gap. This seems to be required for Linux emulation. Reported by: dchagin Reviewed by: alc, markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D41099 --- 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 1c806d6cae34..8d98af7709cd 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2758,6 +2758,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; @@ -2769,8 +2770,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 && @@ -2793,6 +2796,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 08bc6532b8b8..e41516477af4 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -522,6 +522,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);