From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325243; b=5cGenV24e31OL0rqVACu0AqKRALlSNPiWVnoP8iA2bOoy8FJ3Z0PSCb/wc7xtm5cDjQJ AUzbQMEiXt4nDY9+lBKTBl/o6Q/+Raiwr7oRWbcbHAw6LMAGAwQI6fLpgMlu221Ecq6Kp Aygf2OQxEtC1NuN+tADQlDYev5a8sVEczppy3PoSL1VLRFG9mxPy+fkzYtXRhGlRTywNi rwhAjx9mrWxYdp+rPwMPVqaZO8NgrQAq8X4c7EJo28ChmphuD/e4oKOvnhDP6bJL84Mma qjV805f9gusZeTXVeuPldmleJjBTLMGZC5lbkJ/Av+ReaPjxMYmSOAa+J53dxpWQ4BA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325243; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=czodwzlSdDuKMIP/bSy4dTssLmp8SzplCJuGUGbK1Yo=; b=SuF2d4c/qKYrksp79pur3QnnMZ21ergM/VuCpd5lNh5cuwN1ldXiMnQHJSMTFttUKG2D jWpQP0qoX7trFWVxFNpRJRGy/hFsYTY9UI98WttiFoO8JvACFuhXa3ibZ93wUhk/ZYbcn KeJaveO6CptyYBJs7yBhfFOWz4Zi/4dBBmLGw0vRD/BV9XLskVvL8EDKYSrgbz2Ww/IXh xCnCp4XizyeyN0oBF/hfYVCz3O7KGGQogDaGAAj3srgcywZE1Gk9f04r9rA2PeA2/7Rtc E2lvrntMOAk0LyNa4VlT2cWugZb5d7xrtAkFSyIiI1E9CvNXHy7MUQ1PHB7JAUb+z6A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=MUc3fr5o; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C548606A322 for ; Thu, 3 Dec 2026 19:14:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=MUc3fr5o Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25D501F000C2; Thu, 3 Dec 2026 19:14:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325243; bh=czodwzlSdDuKMIP/bSy4dTssLmp8SzplCJuGUGbK1Yo=; h=Date:To:From:In-Reply-To:References:Subject; b=MUc3fr5oqKrjvr09LcUnT8LyK54KJzV5psIEUcE8waYUyq+epAZDadI6mhoFKaUVU v8+em0HvuSGcQoxtfwQ+kKXkoNHYE63+oifXvoQOLK1eEsgBKyXiuJ+Qo6LTicrGLU JZZ+DTMg3JDRWTolhTWHqtZjsTkRFdpnCUWIs0Ac= Date: Thu, 03 Dec 2026 11:14:02 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-hugetlb_fixes_2-v2-24-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-24-9bbeabb555d2@kernel.org> Subject: + hugetlbfs-seal-shm_hugetlb-files-against-growth.patch added to mm-unstable branch Message-Id: <20261203191403.25D501F000C2@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: hugetlbfs: seal SHM_HUGETLB files against growth has been added to the -mm mm-unstable branch. Its filename is hugetlbfs-seal-shm_hugetlb-files-against-growth.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/hugetlbfs-seal-shm_hugetlb-files-against-growth.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Chris Mason Subject: hugetlbfs: seal SHM_HUGETLB files against growth Date: Thu, 03 Dec 2026 12:37:47 +0100 The size of a SysV shared memory segment is fixed at shmget(), and do_shmat() relies on that by mapping i_size bytes of the backing file. However, with SHM_HUGETLB, the hugetlbfs file can be grown through an fd obtained from /proc//map_files with ftruncate() or fallocate(). Also, remap_file_pages() with a pgoff beyond the segment can grow it, because hugetlbfs_file_mmap() grows the file to the end of a writable mapping: shmget(key, 4M, SHM_HUGETLB) i_size = 4M addr = shmat(id, NULL, 0) remap_file_pages(addr, 2M, 0, 6M >> PAGE_SHIFT, 0) i_size = 8M shmat(id, NULL, 0) maps 8M Later calls to shmat() will map the bigger size. Using /proc//map_files requires CAP_CHECKPOINT_RESTORE, but remap_file_pages() does not require any privileges, so we focus on the latter. Let's fix it by setting F_SEAL_GROW on the inode when creating it for a segment. remap_file_pages() beyond the segment still succeeds, like for shmem segments, but accessing pages there now correctly results in SIGBUS. This has low urgency, and likely nobody ever ran into this in practice. Let's not CC stable. [david@kernel.org: adjust description] Link: https://patch.msgid.link/20261203-hugetlb_fixes_2-v2-24-9bbeabb555d2@kernel.org Fixes: c8d78c1823f4 ("mm: replace remap_file_pages() syscall with emulation") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Cc: Muchun Song Cc: Oscar Salvador Cc: Hongfu Li Cc: Jinmeng Zhou Cc: Mina Almasry Cc: Davidlohr Bueso Cc: Naoya Horiguchi Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Michal Hocko Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Vivek Kasireddy Cc: Mel Gorman Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Jason Gunthorpe Cc: Andy Whitcroft Cc: Roman Gushchin Cc: Barry Song Cc: Andrea Arcangeli Cc: Lorenzo Stoakes Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Jann Horn Cc: Guillaume Morin Cc: Yang Shi Cc: James Houghton Cc: Rik van Riel Cc: Harry Yoo Cc: Lance Yang Cc: Axel Rasmussen Cc: Peter Xu Cc: Sasha Levin Cc: Kiryl Shutsemau Cc: Christian Brauner Cc: Steven Rostedt Cc: Hongbo Li Cc: Gregory Price Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Ying Huang Cc: Matthew Brost Cc: Byungchul Park Cc: Alistair Popple Cc: Andi Kleen Cc: David Rientjes Cc: Joern Engel Cc: Aneesh Kumar K.V Cc: Gerd Hoffmann Cc: Johannes Weiner Cc: Jiaqi Yan fs/hugetlbfs/inode.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/hugetlbfs/inode.c~hugetlbfs-seal-shm_hugetlb-files-against-growth +++ a/fs/hugetlbfs/inode.c @@ -1561,8 +1561,11 @@ struct file *hugetlb_file_setup(const ch S_IFREG | S_IRWXUGO, 0); if (!inode) goto out; - if (creat_flags == HUGETLB_SHMFS_INODE) + if (creat_flags == HUGETLB_SHMFS_INODE) { inode->i_flags |= S_PRIVATE; + /* The size of a segment is fixed at shmget(). */ + HUGETLBFS_I(inode)->seals |= F_SEAL_GROW; + } inode->i_size = size; clear_nlink(inode); _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch kfence-use-a-nofault-store-to-zero-the-guard-page.patch mm-filemap-update-the-folio-order-range-atomically.patch mm-userfaultfd-account-memory-allocated-for-unmap-events.patch mm-userfaultfd-drop-fork-context-reference-outside-event_wqhlock.patch mm-madvise-dont-declare-oom-for-madv_willneed-swapin.patch mm-mprotect-fix-unpaired-notifier-start-at-address-0.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch mm-hugetlb-fix-truncated-copy-result-in-uffdio_copy.patch hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure.patch hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch