mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Jérémy Jean" <jeremy.jean@oss.cyber.gouv.fr>
To: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Pedro Falcato <pfalcato@suse.de>,
	David Hildenbrand <david@kernel.org>, Zi Yan <ziy@nvidia.com>,
	"Liam R. Howlett" <liam@infradead.org>,
	Nico Pache <nico.pache@linux.dev>,
	Ryan Roberts <ryan.roberts@arm.com>, Dev Jain <dev.jain@arm.com>,
	Barry Song <baohua@kernel.org>, Lance Yang <lance.yang@linux.dev>,
	Usama Arif <usama.arif@linux.dev>,
	Kiryl Shutsemau <kas@kernel.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH] mm/khugepaged: reject shmem collapse ranges beyond i_size
Date: Sun, 15 Nov 2026 21:21:39 +0100	[thread overview]
Message-ID: <824c33ead7a2baf08715fe01a4c88714@oss.cyber.gouv.fr> (raw)
In-Reply-To: <795b8d8a-4f6f-451f-9274-ccb8380e03dd@linux.alibaba.com>

On 2026-11-13 03:42, Baolin Wang wrote:
> On 11/13/26 6:50 AM, Andrew Morton wrote:
>> On Thu, 12 Nov 2026 18:11:35 +0000 Pedro Falcato <pfalcato@suse.de> 
>> wrote:
>> 
>>> On Thu, Nov 12, 2026 at 02:23:35PM +0000, Jérémy Jean wrote:
>>>> MADV_COLLAPSE lets collapse_file() treat absent shmem pages as holes
>>>> filled with zeros. It does not check i_size, which allows one 
>>>> present
>>>> page to become a huge mapping that covers the whole collapse range,
>>>> including pages beyond EOF. This makes those pages writable. A later
>>>> file extension can expose their contents after F_SEAL_WRITE.
>>>> 
>>>> Hold inode i_rwsem in read mode while collapsing shmem so i_size
>>>> cannot change. Reject a collapse if its page range extends past
>>>> i_size rounded up to PAGE_SIZE. Keep i_size_read() outside the
>>>> page-cache XArray lock because its 32-bit SMP reader is not IRQ
>>>> safe.
>>> 
>>> I don't think this is an issue. shmem/tmpfs purposefully maps with 
>>> large pages
>>> across i_size, and collapsing across i_size is a feature, not a bug.
> 
> Yes. finish_fault() even has comments explaining the special case for 
> shmem/tmpfs.
> 
> 	/*
> 	 * Do not allow to map with PTEs beyond i_size and with PMD
> 	 * across i_size to preserve SIGBUS semantics.
> 	 *
> 	 * Make an exception for shmem/tmpfs that for long time
> 	 * intentionally mapped with PMDs across i_size.
> 	 */
> 	needs_fallback = !shmem_mapping(mapping) &&
> 		file_end < folio_next_index(folio);
> 
>> hoo boy, this again, See
>> https://lore-kernel.gnuweeb.org/linux-mm/nwkpojnictbg6jicccpxyfi63ol4tmfajrlx24u5xxoxx7lv5f@jkw3o7j6tlfs/T/
>> and enjoy.
>> 
>> It's not good that this sequence permits non-zero data to be exposed 
>> in
>> areas which ftruncate() created - the ftruncate() contract says it
>> doesn't do that.
> 
> That's a valid concern and this is a known issue for shmem/tmpfs. Brian 
> previously posted a patchset to fix it:
> https://lore.kernel.org/all/20251112162522.412295-1-bfoster@redhat.com/

Hello,

Thank you all for the quick feedbacks. I unfortunately did not find
and read the links you shared nor the historical discussions before I
prepared the patch. I'm sorry for reheating what it seems to me like
a sensitive subject; it was definitely not my intention.

> Jérémy , you haven't explained why this matters.  Is there some
> userspace code which is encountering problems because of this?
> Why did you propose cc:stable backporting?

My initial understanding was that there was a security boundary
crossed, and that's why I submitted the patch and added stable in the
exchange, so that it could get backported. While I'm now a bit
confused about the situation, I have no problem in accepting that I
was wrong and I'm totally fine with just dropping the patch if there
was already a discussion and suggest patches.

Regards,
Jérémy

      reply	other threads:[~2026-11-15 20:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 14:23 Jérémy Jean
2026-11-12 18:11 ` Pedro Falcato
2026-11-12 22:50   ` Andrew Morton
2026-11-13  2:42     ` Baolin Wang
2026-11-15 20:21       ` Jérémy Jean [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=824c33ead7a2baf08715fe01a4c88714@oss.cyber.gouv.fr \
    --to=jeremy.jean@oss.cyber.gouv.fr \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=kas@kernel.org \
    --cc=lance.yang@linux.dev \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nico.pache@linux.dev \
    --cc=pfalcato@suse.de \
    --cc=ryan.roberts@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=usama.arif@linux.dev \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®