From nobody Fri Aug 25 01:08:33 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 4RX1zk0YtLz4qZwZ; Fri, 25 Aug 2023 01:08:34 +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 4RX1zk07jFz4Sqb; Fri, 25 Aug 2023 01:08:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925714; 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=2ViWf7ctnZAbHGfrNyGL+aCMGtAMZ/Sif5fQZMmIEIs=; b=FQx7PC8+H83ujdNsQMmm8pzTfHb+wNiyf0rZdLgHhxxY+VFGv5jUnzM+fYtkUt6roq2n4a EYyHoJYRxu4Cv2t9zh5XxG8dtWzlZLcZsnfJ7+FKZmzSZEC1FipmwTSMcRM1vXuS2CyxWX 8oC8SzClWlgxqLZ6pdPPu+dfN5mw+wo/ZSd5V+URbeV0jkY57X2Tr0XT6NAqjwCuZgoOeI w5kNIHmOSlHtv6LV5daZr6o8MiTUySQXqAcscQVFjXlCzNdpve0BKWQBPTAY81YiCsgMqY FLtMlnsVctEeXVkCxt/uXpELXo7gLP/nEo+06m7MGB3VmaYlf7ZYulgmFF/Zqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925714; 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=2ViWf7ctnZAbHGfrNyGL+aCMGtAMZ/Sif5fQZMmIEIs=; b=G052ov7JLU8e2c5ztbf1rbiKv8+unYr052Hhpp0f/M/pBC9eAXyru7Qtfju72WltsYCxl7 OZOjsQz+Vbg7ZREBFEfZ0MaOUyEzSD/Es297+cDf38LCrxRoyfe0xkWNb+KRfBVUZswxyY jTa/r+2wZF88/AUr6FJke9S46WUehQeUXMv/abFEurVZ4BW+SqHBmGGb2Ih+a4rv/LaY6b ukOapss2CAhlt6uberhEa6fGQOhZbZRoOf1VArmkASEm/qjEL4z5N7+ql8dBDckqsKVShh pvhJwwx1byCrZNu4K4cXqb4PfiApL7B/7lmZNwNqMiP7emZyP27r6XeC08EmFQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692925714; a=rsa-sha256; cv=none; b=dm9nZqhCymB62BesTYOqjRg8SrfRBACtbddHxHzu9E2Q6O2wOXHStdosEhJOs7xQjVi3wa i2DA3mQLIlRVzZlRn7/boDzpo+Y2Q/oHXoTRnF6mSjk/lc973O008An3sdzLoncp5Yw5Ea jBJWEdDK+uX8AuZDfVQJAw07FBZLUBDwnb8KemExkasLk2XiFe4KTKnybNUoonADmk+fyY 56GfOlb4laQQcRPjgkOZ/zM5HaiNhcwGPCU5VtBKKgfMLqHvf6btxJiIKB9a1LVIzFniGK rGS6Coufp9e5xAmA1mXKv52ieaLYoo5UiRD8FeDr97DaOju/39OpB1gFTF11aw== 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 4RX1zj6KQNzpZ0; Fri, 25 Aug 2023 01:08:33 +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 37P18XIE058355; Fri, 25 Aug 2023 01:08:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37P18XG0058352; Fri, 25 Aug 2023 01:08:33 GMT (envelope-from git) Date: Fri, 25 Aug 2023 01:08:33 GMT Message-Id: <202308250108.37P18XG0058352@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: bd7afd9e50b3 - stable/13 - vm_map_protect(): handle stack protection stored in the stack guard 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/stable/13 X-Git-Reftype: branch X-Git-Commit: bd7afd9e50b3a0939354c3e8c8ddcc9f696c92f9 Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=bd7afd9e50b3a0939354c3e8c8ddcc9f696c92f9 commit bd7afd9e50b3a0939354c3e8c8ddcc9f696c92f9 Author: Konstantin Belousov AuthorDate: 2023-07-25 13:32:28 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-25 01:06:44 +0000 vm_map_protect(): handle stack protection stored in the stack guard (cherry picked from commit 55be6be12cd95552a46feccb42db984c8d3cbc36) --- sys/vm/vm_map.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index d443c320b799..09e78b3e18f9 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2720,7 +2720,22 @@ static void vm_map_protect_guard(vm_map_entry_t entry, vm_prot_t new_prot, vm_prot_t new_maxprot, int flags) { + vm_prot_t old_prot; + MPASS((entry->eflags & MAP_ENTRY_GUARD) != 0); + if ((entry->eflags & (MAP_ENTRY_STACK_GAP_UP | + MAP_ENTRY_STACK_GAP_DN)) == 0) + return; + + old_prot = PROT_EXTRACT(entry->offset); + if ((flags & VM_MAP_PROTECT_SET_MAXPROT) != 0) { + entry->offset = PROT_MAX(new_maxprot) | + (new_maxprot & old_prot); + } + if ((flags & VM_MAP_PROTECT_SET_PROT) != 0) { + entry->offset = new_prot | PROT_MAX( + PROT_MAX_EXTRACT(entry->offset)); + } } /* @@ -2736,7 +2751,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_prot_t check_prot, old_prot; + vm_prot_t check_prot, max_prot, old_prot; int rv; if (start == end) @@ -2785,10 +2800,14 @@ again: vm_map_unlock(map); return (KERN_INVALID_ARGUMENT); } - if ((entry->eflags & MAP_ENTRY_GUARD) != 0) { + if ((entry->eflags & (MAP_ENTRY_GUARD | + MAP_ENTRY_STACK_GAP_DN | MAP_ENTRY_STACK_GAP_UP)) == + MAP_ENTRY_GUARD) continue; - } - if (!CONTAINS_BITS(entry->max_protection, check_prot)) { + max_prot = (entry->eflags & (MAP_ENTRY_STACK_GAP_DN | + MAP_ENTRY_STACK_GAP_UP)) != 0 ? + PROT_MAX_EXTRACT(entry->offset) : entry->max_protection; + if (!CONTAINS_BITS(max_prot, check_prot)) { vm_map_unlock(map); return (KERN_PROTECTION_FAILURE); }