From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=91.218.175.26 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796365764; b=J8diXbZayBP3DJubWb3JVFn2+bAFss7hc1NZCR4QN7t3FUiSINcwHKxwIo1C435SD59e bN0Gnu+ADVUaWf5xtQQwRDKj7bZmbPYf//b837xjkHBYt4he1yBGgsuqZVwp9rkAkaWTG H4KXMAufX8jw4Hn+TbeFkoHveEfuaeI1tfe1JCuQqP4+fCprd5tQLQgChjyu05EVq3749 k61bWCMbMAmpjQn+RW2bnemB/YP86A+rBYtkwSKfe7V8D14vZRFQpm3zDy/r1h63ymXz7 aJnGXg2y7H2jSTpuXRBxxxb9By3MNwEgx831gO2oMr9/wxRwptQJcWSrNwOU+pp0B4A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796365764; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Content-Type:Mime-Version:Subject:From: In-Reply-To:Date:Cc:Content-Transfer-Encoding:Message-Id:References: To:X-Mailer; bh=LT/0deorTJha7HXAptIh8U7ecnVRiuyLAM0mxP43slw=; b=ZIFosJ2cxDdff5DLICAWXx0UmyjUM/Snj9s2vkT222sDzD0wWpFhysEgvRjgqLFyCLRf 5KsQoUHiBdfnduW23iVrgKZ5DPktM7MaDJNacWDLoebNsZGDNvc6kmL0QWRH4n3/NWH/r 5Xm3UQ9Q18sNzk4D3Cd2NdbPYe0mynYf7z8NHoJVi0GNh4CVPMYhUIHWnnaCTHZdi/hSk hGEhrnEjfH9Taiv5ywLrGmcJvNFSPHOkMQZo8kQo50oEINwp/+bsRUP4HRspdw1Esf/YL 8GkvBS4vmR10Ibj0u65iEpV64+7H0Ru+BM3Ul/VV5bF4/VSuO9Db235Srkwpod7QlxQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=INaSkHV3; arc=none smtp.remote-ip=91.218.175.26 Received: from mta0.migadu.com (out-26.mta0.migadu.com [91.218.175.26]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9717A606A322 for ; Fri, 4 Dec 2026 06:29:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9717A606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=INaSkHV3 X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=MBmBEHl1ZIPLPZGRUaaUyeKJNnoQbDmXzi6ns9GsAKA=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796365761; v=1; x=1796970561; b=INaSkHV3jmewVTpNNqgGztuB4T29ptKbD6VsYCRDlfMb/+jQWcFnidz5rcwHD+dMAqBxdyiq pboiovlo9Qq4IjiwU6VeUJ2FYFJpM0s0NiMXEnEtC12ADDAEk29vlTU96Ps3eVa5Jm3eqBH+JbB Q05yIZdPfQ189jCLPWFld9no= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id d2756b9cdd82d3d3; Fri, 04 Dec 2026 06:29:19 +0000 X-Mizu-Trace-ID: d2756b9cdd82d3d3 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset=us-ascii X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3901.200.71.1.16\)) Subject: Re: [PATCH v2 24/35] hugetlbfs: seal SHM_HUGETLB files against growth From: Muchun Song In-Reply-To: <20261203-hugetlb_fixes_2-v2-24-9bbeabb555d2@kernel.org> Date: Fri, 4 Dec 2026 14:28:53 +0800 Cc: Muchun Song , Oscar Salvador , Andrew Morton , Hongfu Li , Jinmeng Zhou , Mina Almasry , Davidlohr Bueso , Naoya Horiguchi , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Michal Hocko , Jonathan Corbet , Shuah Khan , Randy Dunlap , Vivek Kasireddy , Mel Gorman , Hugh Dickins , Baolin Wang , Dave Airlie , Jason Gunthorpe , Andy Whitcroft , Roman Gushchin , Barry Song , Andrea Arcangeli , Lorenzo Stoakes , Suren Baghdasaryan , Shakeel Butt , Pedro Falcato , Jann Horn , Guillaume Morin , Yang Shi , James Houghton , Rik van Riel , Harry Yoo , Lance Yang , Axel Rasmussen , Peter Xu , Sasha Levin , Kiryl Shutsemau , Christian Brauner , "Steven Rostedt (Google)" , Hongbo Li , Gregory Price , Zi Yan , Joshua Hahn , Rakie Kim , Ying Huang , Matthew Brost , Byungchul Park , Alistair Popple , Andi Kleen , David Rientjes , Joern Engel , "Aneesh Kumar K.V" , linux-mm@kvack.org, linux-doc@vger.kernel.org, Gerd Hoffmann , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Johannes Weiner , Chris Mason , Jiaqi Yan Content-Transfer-Encoding: quoted-printable Message-Id: References: <20261203-hugetlb_fixes_2-v2-0-9bbeabb555d2@kernel.org> <20261203-hugetlb_fixes_2-v2-24-9bbeabb555d2@kernel.org> To: "David Hildenbrand (Arm)" X-Mailer: Apple Mail (2.3901.200.71.1.16) > On Dec 3, 2026, at 19:37, David Hildenbrand (Arm) = wrote: >=20 > From: Chris Mason >=20 > 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. >=20 > 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: >=20 > shmget(key, 4M, SHM_HUGETLB) i_size =3D 4M > addr =3D shmat(id, NULL, 0) > remap_file_pages(addr, 2M, 0, 6M >> PAGE_SHIFT, 0) > i_size =3D 8M > shmat(id, NULL, 0) maps 8M >=20 > Later calls to shmat() will map the bigger size. >=20 > Using /proc//map_files requires CAP_CHECKPOINT_RESTORE, but > remap_file_pages() does not require any privileges, so we focus on the > latter. >=20 > 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. >=20 > This has low urgency, and likely nobody ever ran into this in = practice. > Let's not CC stable. >=20 > Fixes: c8d78c1823f4 ("mm: replace remap_file_pages() syscall with = emulation") > Signed-off-by: Chris Mason > [ david: adjust description ] > Signed-off-by: David Hildenbrand (Arm) Acked-by: Muchun Song (ByteDance) Thanks.