From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A50DA606A31F for ; Fri, 30 Oct 2026 11:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=r9dq0MW4; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=BHb4rT89 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=kc1nYy3NbBrATEnmu304kSXCIcQUyPU78cqEyUeTLQk=; b=r9dq0MW404Eaow6SaTDK1CJwNW vv2uNxZa01m6yXm640eziw0w7lWt5J2hulpGJMQc1JAb41QFCK7JrJsr6AAAPQu3fGaaA/aZzWN2T nNyrJmAYYVYPG2lz9lHSZPb+P4iDeCIF0wR42JtS6NAIu5yFpf2dzpgNosc/fjPBbARFqVmEojN8I fqb0GUGzMGJAvk+VpxwPj6iWiZP1KzPmeSeo2sXkSdy8/NYU0FBM6lxmlHUV563uQtRBSA9xyIL7c 5fQj7J42m9vsGXP9EpKJJaRDGXUk06C5ab3IQLBBXy3oEj8H0KCciTcDmUM1tX9ugpLyk+2SghllU aRDaUioQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xMkrJ-0000000BYo2-126m; Fri, 30 Oct 2026 11:33:21 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xMkrI-0000000BYns-1bZD for kexec@lists.infradead.org; Fri, 30 Oct 2026 11:33:20 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 5EAF2601EE; Fri, 30 Oct 2026 11:33:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32A5A1F000C1; Fri, 30 Oct 2026 11:33:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1793359998; bh=kc1nYy3NbBrATEnmu304kSXCIcQUyPU78cqEyUeTLQk=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=BHb4rT89dXjX/iZaObEefV3p90/w7FDU1AnmrNDjsWGet3bMCVuHxPhhh8maCSV/h zHFPhZNhQ+icw2cAAzLgVil3nTxqrp8v/shvpU7wgx9O2HOr6scmGto/DwnEx43YLR U8QuxRoob6poB0ebRlGoVLdYs4EXRG/OEIcmFg9nLjCoFcmkfPK+kLiNtyRR5jFfK/ kPdRH7C4xmDmfWvUUGNc6QJpyNgV5aZiZ4d9NVAt97UVbCogRFpjqWS63JZdadrQNq Et9wov2jU3Uf8UCr6K6rvisW1XibSsetO8Dm61vUCe5/c67aIiNMH6e+Dl8WkmU+fi vUl1VbxFRwh2Q== From: Pratyush Yadav To: "David Hildenbrand (Arm)" Cc: Andrew Morton , Johannes Weiner , Michal Hocko , Qi Zheng , Shakeel Butt , Lorenzo Stoakes , Kairui Song , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Baolin Wang , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Kees Cook , Peter Zijlstra , Jann Horn , Pedro Falcato , Hugh Dickins , Pasha Tatashin , Pratyush Yadav , "Matthew Wilcox (Oracle)" , Jan Kara , Zi Yan , Lance Yang , Rik van Riel , Harry Yoo , Alistair Popple , Nico Pache , Ryan Roberts , Dev Jain , Usama Arif , Kiryl Shutsemau , Matthew Brost , John Hubbard , Peter Xu , Will Deacon , "Aneesh Kumar K.V" , Nick Piggin , Oscar Salvador , Minchan Kim , Muchun Song , Xu Xin , Chengming Zhou , Chris Li , Kemeng Shi , Nhat Pham , Youngjun Park , Gregory Price , Joshua Hahn , Rakie Kim , Ying Huang , Jason Gunthorpe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kexec@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-cxl@vger.kernel.org, stable@vger.kernel.org, Chris Mason Subject: Re: [PATCH v2 03/47] mm/memfd: check for real shmem inodes before accessing shmem state In-Reply-To: <20261029-fixes_core-v2-3-a64ce7f83abb@kernel.org> (David Hildenbrand's message of "Thu, 29 Oct 2026 21:32:58 +0100") References: <20261029-fixes_core-v2-0-a64ce7f83abb@kernel.org> <20261029-fixes_core-v2-3-a64ce7f83abb@kernel.org> Date: Fri, 30 Oct 2026 12:33:06 +0100 Message-ID: <2vxzmrrvmnil.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Hi David, On Thu, Oct 29 2026, David Hildenbrand (Arm) wrote: > shmem_file() only checks a file's backing mapping. That mapping can belong > to another file, as with a Coda file backed by a tmpfs container after > mmap(). It does not establish that file_inode(file) is a 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. > > Add file_inode_is_shmem() to check the inode's file operations in both > paths. This identifies regular shmem inodes, including those used by > memfds and ordinary tmpfs files, independently of wrapper file operations. > > Fixes: c49fcfcda8b5 ("mm/shmem: update file sealing comments and file checking") > Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd") > Cc: stable@vger.kernel.org > Reported-by: Chris Mason > Reviewed-by: Rik van Riel > Reviewed-by: Mike Rapoport (Microsoft) > Signed-off-by: David Hildenbrand (Arm) Maybe you missed my email on v1 [0], so here's another try: Why not update shmem_file() to do this check instead? Having a shmem_file() that might not always return the right result on a file seems like a landmine. For example, you missed check_memfd_seals() in udmabuf or memfd_pin_folios() in gup. Both want to only look at "proper" shmem files, and should not do any work on a Coda file with a shmem mapping. Plus, someone later down the line might use shmem_file() without knowing this subtle problem, and we probably would miss it in review. For callers that only care about the mapping should then use shmem_mapping(). I am not sure if there are any. Perhaps that would be collapse_file()? But TBH I don't really understand khugepaged all that much. All other callers of shmem_file() seem to care about the actual inode. [0] https://lore.kernel.org/all/2vxzh5i7p5nl.fsf@kernel.org/ > --- > include/linux/shmem_fs.h | 6 ++++++ > mm/memfd.c | 8 +++++--- > mm/memfd_luo.c | 2 +- > mm/shmem.c | 5 +++++ > 4 files changed, 17 insertions(+), 4 deletions(-) [...] -- Regards, Pratyush Yadav