From nobody Fri Aug 25 01:08:25 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 4RX1zZ1xMNz4qZk3; Fri, 25 Aug 2023 01:08:26 +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 4RX1zZ0pclz4SKZ; Fri, 25 Aug 2023 01:08:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925706; 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=HJVe3YcwXXNoPKDxUILbrgiR5R+VZmmmto2c/iBlZQw=; b=G178mQD/0plGgP8uQzROLI+xliXi4y2npOmaI2NrCjhpznzbi3xcd9uzPAhAOuOBtdsP44 dHkUL3vIc8yOu23KYID+KomEYzwipTpwz7yvz7ybtwMYCZIiXavrP06lnsedL+UuLNY/3C 6wL/dPuSwz/R2CGdpfv3AhCwL73kGCQR5csmv9TkxZ/h8uqI81DqcbMrcKjS5XsaV1B3o5 M1EIMSd5DaGUsXS9zAsWQ4pVCXDc+REHodnXaTisiAsnEy+1LVo1RKOnh+oDXQuG35WcWy 2xRHy6wW5wLo/PeBUPfswQ5O3pYmQigFs4NfGBtssuSc6dE8qQgZPc1/EiFyOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925706; 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=HJVe3YcwXXNoPKDxUILbrgiR5R+VZmmmto2c/iBlZQw=; b=qhuBUslRT+tNusq4R+c85zl2VpTElvC0/qJ0IIgn1kBS3ZCYpaq8jHvjZFq1fkIvVYRmuV 5SM3y+Hsbf57tyiNjgThLxVyldG7E496swJH58/2yleX5avxkrJdGUzFg36zGh7CEJBmrg F9wwkjLipnWix3IAkF6Raukcnh5KDmaBFIHh4ebQD1hUUUvfHh94i/SZfHlWZ7keA9EhXY kF7S6Cev/nsT2ChtmaWDx8bKx9qW10p2A+9Phdu3Jbfly1Fez+BpxVc4neO4c+Mx2KF9RI VCkV43QTPik2Vpt42Op6tsqwz503kh1xVwuhtR1FDtA7rX82uCR+dvfu2hmCSw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692925706; a=rsa-sha256; cv=none; b=Q+cOwLyTUEY7pMZSlhL+g1RE7RJEkyVtncaH1QcY3z0/bDHxEmK//lULNNP0gNv6i5eMcj XiXxEK5z+7h0/jzvf5foMEk2AypDrbQFeWlsRZkqDRvSSY2tRc/SeMVO4AIDf2rwZhl2tA l6hFXLLumQnqwbwaCuh+1l+d6r6m3JrG295Q/38N+m5rBCMXLYqn0ueTrg8OD/5gpyyDwK ihUzmBEyMQKnXx6xyj5X91uXXIujeNbRKbetn/pvk3ZLgCqMQreaVayXBQao88v7IanH6L jHLZaLynjBU395mLJWprHR4GGsa9xtv2kOAB8l4eRgBImElfrRLIQ2AxheqTXw== 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 4RX1zY6y8Mzpkt; Fri, 25 Aug 2023 01:08:25 +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 37P18P4Y058006; Fri, 25 Aug 2023 01:08:25 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37P18Pl0058003; Fri, 25 Aug 2023 01:08:25 GMT (envelope-from git) Date: Fri, 25 Aug 2023 01:08:25 GMT Message-Id: <202308250108.37P18Pl0058003@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: 6c79559bf0c6 - stable/13 - mmap(MAP_STACK): on stack grow, use original protection 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: 6c79559bf0c641a7b06966fa419935ca50dddedf Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=6c79559bf0c641a7b06966fa419935ca50dddedf commit 6c79559bf0c641a7b06966fa419935ca50dddedf Author: Konstantin Belousov AuthorDate: 2023-07-19 11:05:32 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-25 01:06:43 +0000 mmap(MAP_STACK): on stack grow, use original protection PR: 272585 (cherry picked from commit 21e45c30c35c9aa732073f725924caf581c93460) --- sys/vm/vm_map.c | 24 ++++++++++++++++-------- sys/vm/vm_map.h | 4 ++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 03d44d773552..c8f3c72302fc 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -4489,7 +4489,7 @@ static int vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, vm_size_t growsize, vm_prot_t prot, vm_prot_t max, int cow) { - vm_map_entry_t new_entry, prev_entry; + vm_map_entry_t gap_entry, new_entry, prev_entry; vm_offset_t bot, gap_bot, gap_top, top; vm_size_t init_ssize, sgp; int orient, rv; @@ -4571,11 +4571,14 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, * read-ahead logic is never used for it. Re-use * next_read of the gap entry to store * stack_guard_page for vm_map_growstack(). + * Similarly, since a gap cannot have a backing object, + * store the original stack protections in the + * object offset. */ - if (orient == MAP_STACK_GROWS_DOWN) - vm_map_entry_pred(new_entry)->next_read = sgp; - else - vm_map_entry_succ(new_entry)->next_read = sgp; + gap_entry = orient == MAP_STACK_GROWS_DOWN ? + vm_map_entry_pred(new_entry) : vm_map_entry_succ(new_entry); + gap_entry->next_read = sgp; + gap_entry->offset = prot; } else { (void)vm_map_delete(map, bot, top); } @@ -4595,6 +4598,7 @@ vm_map_growstack(vm_map_t map, vm_offset_t addr, vm_map_entry_t gap_entry) struct ucred *cred; vm_offset_t gap_end, gap_start, grow_start; vm_size_t grow_amount, guard, max_grow; + vm_prot_t prot; rlim_t lmemlim, stacklim, vmemlim; int rv, rv1; bool gap_deleted, grow_down, is_procstack; @@ -4735,6 +4739,12 @@ retry: } if (grow_down) { + /* + * The gap_entry "offset" field is overloaded. See + * vm_map_stack_locked(). + */ + prot = gap_entry->offset; + grow_start = gap_entry->end - grow_amount; if (gap_entry->start + grow_amount == gap_entry->end) { gap_start = gap_entry->start; @@ -4747,9 +4757,7 @@ retry: gap_deleted = false; } rv = vm_map_insert(map, NULL, 0, grow_start, - grow_start + grow_amount, - stack_entry->protection, stack_entry->max_protection, - MAP_STACK_GROWS_DOWN); + grow_start + grow_amount, prot, prot, MAP_STACK_GROWS_DOWN); if (rv != KERN_SUCCESS) { if (gap_deleted) { rv1 = vm_map_insert(map, NULL, 0, gap_start, diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 5db7a2230351..85d622ee1bb6 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -95,6 +95,10 @@ union vm_map_object { * a VM object (or sharing map) and offset into that object, * and user-exported inheritance and protection information. * Also included is control information for virtual copy operations. + * + * For stack gap map entries (MAP_ENTRY_GUARD | MAP_ENTRY_GROWS_DOWN + * or UP), the next_read member is reused as the stack_guard_page + * storage, and offset is the stack protection. */ struct vm_map_entry { struct vm_map_entry *left; /* left child or previous entry */