[PATCH v3 03/47] mm/shmem: make shmem_file() check the file's inode

Baolin Wang baolin.wang at linux.alibaba.com
Sun Nov 1 19:52:13 PST 2026



On 10/31/26 5:39 PM, David Hildenbrand (Arm) wrote:
> shmem_file() only checks if file->f_mapping is a shmem mapping. This
> mapping can belong to another file, however, as with a Coda file backed
> by a tmpfs container after mmap().
> 
> So it does not guarantee that the file inode is an actual shmem inode.
> 
> Seal handling and memfd preservation use this check before accessing
> shmem inode state, so they can access an inode of the wrong type.
> 
> Let's make shmem_file() check the inode's file operations instead, to
> identify shmem inodes reliably. This will identify regular shmem inodes,
> including memfds and ordinary tmpfs files, independently of wrapper file
> operations.
> 
> Use shmem_mapping() in collapse_file() instead to not change the behavior
> of collapse_file(): it operates on the page cache and uses mapping->host
> for shmem inode operations. Focusing on the file does not seem relevant.
> 
> Fixes: c49fcfcda8b5 ("mm/shmem: update file sealing comments and file checking")
> Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
> Cc: stable at vger.kernel.org
> Reported-by: Chris Mason <mason at kernel.org>
> Suggested-by: Pratyush Yadav <pratyush at kernel.org>
> Reviewed-by: Pratyush Yadav (Google) <pratyush at kernel.org>
> Signed-off-by: David Hildenbrand (Arm) <david at kernel.org>
> ---

Make sense to me.
Reviewed-by: Baolin Wang <baolin.wang at linux.alibaba.com>



More information about the kexec mailing list