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=1796150900; b=MW2dDZIKvfuCehdkO9eQcuvAjA8SNmijwNwGdXcgryO83xXulutXgO15raDsiSBRjvqC Ue//Smc6//5eCtQb42TcxDkn8SfuUZiqxh1ruZwWIZMYIuDuGqxC9hhcUgJ9QelJfmTRW R8GHiR4SAH1ABGuwnqGBWH1Jf7jmLAOAKVjbXqUHWuwRtDhcG1Vrhu81ez+2aau7taPGi 6rL2P4RAaQajy7QX+7hFK24e22tcz4N7IjtHt3EoMtS9dH8r40VIrYKVOwQCtZTGOv7Cl bm2r9hzS0XhyK3kcgs9DD9O20YFHY2Fy01/QZvHw4oPMroyoTxIceTxBX0ieIupKDgQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796150900; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=jiRzap7EdhUgeJaHM7dDVO8xuR0KuYZztYcomBXfIg0=; b=vLdSKRUkJXVmyBRw4Z3p9VwRIP1NtBcShPMDeVNQFgq2M0xzXvaHlosFGTE8ZdShh3Is zu7PtgMlYYiP3LtbD11hYf15+nnvwR4QUDIgKX2Fyjj1aWGoGvdHEyOe2nA5hKNzZRuWL TJV2HrgkZp75z2tpfjDC43b8MPrwM7eod3LXSLfKdraA1tkiUPuKMZ3Bgf5WdnzvtHmFJ mEY+QKlY2YoaAgP3tKFnUAz4aQcRi5RAgzvuOwfjWYf/Xv2PTUsybkjxLUb2F88BWvqK0 3+bEFgbbycN3gjuPfhaWmuqCSg903qn4QrZndgFJD1PJ5h9JO/Hx2U9gQ4LJlS8+kzQ== 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=FK8Bg8Mg; 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 42592606A320; Tue, 1 Dec 2026 18:48:20 +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=FK8Bg8Mg Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7A1F1F000C1; Tue, 1 Dec 2026 18:48:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796150899; bh=jiRzap7EdhUgeJaHM7dDVO8xuR0KuYZztYcomBXfIg0=; h=Date:To:From:In-Reply-To:References:Subject; b=FK8Bg8MgFPP1D2ZXOwG7MfWSoSCKwvfMoQcaI7/6aQLaBiF3+Wm6eQx4u52fEfXIo gPvpPd3keIt52nLEbYyhqB4j4clm98XjZolhZkhl8XumUkAB9We9o5zjgmjHXuGpyz 0Yx7P+sjtluV9NXPrUdGluh/ySnFn2ojhYJrqBzA= Date: Tue, 01 Dec 2026 10:48:19 -0800 To: mm-commits@vger.kernel.org,vbabka@kernel.org,usama.anjum@arm.com, surenb@google.com,stable@vger.kernel.org,skhan@linuxfoundation.org, sfr@canb.auug.org.au,rppt@kernel.org,rientjes@google.com,riel@redhat.com, rdunlap@infradead.org,pfalcato@suse.de,mirq-linux@rere.qmqm.pl, mhocko@suse.com,mason@kernel.org,liam@infradead.org,jannh@google.com, jaharkes@cs.cmu.edu,hughd@google.com,hannes@cmpxchg.org,david@readahead.eu, david@kernel.org,corbet@lwn.net,avagin@gmail.com,arnd@arndb.de, alexs@kernel.org,akpm@linux-foundation.org,ljs@kernel.org From: Andrew Morton In-Reply-To: <20261127-mlock-madvise-mprotect-ai-fixes-v1-1-e46b2b1eb435@kernel.org> References: <20261127-mlock-madvise-mprotect-ai-fixes-v1-1-e46b2b1eb435@kernel.org> Subject: + coda-never-point-a-files-f_mapping-at-a-containers-mapping.patch added to mm-new branch Message-Id: <20261201184819.C7A1F1F000C1@smtp.kernel.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: coda: never point a file's f_mapping at a container's mapping has been added to the -mm mm-new branch. Its filename is coda-never-point-a-files-f_mapping-at-a-containers-mapping.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/coda-never-point-a-files-f_mapping-at-a-containers-mapping.patch This patch will later appear in the mm-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next 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: "Lorenzo Stoakes (ARM)" Subject: coda: never point a file's f_mapping at a container's mapping Date: Fri, 27 Nov 2026 19:45:40 +0000 Patch series "mm: AI-generated fixes for coda, madvise, mprotect and PAGEMAP_SCAN". The usual stuff - glorious gifts of AI goodness transmuted into a smoother form by yours truly. This patch (of 4): Coda file systems stack differently from other stacked file systems. On mmap(), coda_file_mmap() switches both the Coda inode's i_mapping and the Coda file's f_mapping for the mapping of the container file. This causes two problems. Firstly, the container file may not remain pinned, at which point this may result in a dangling reference in coda_file->f_mapping, and so a use-after-free in mmap() or lseek(). This can happen when you open the same inode across two files, mmap()'ing in one, which assigns the i_mapping, and open()'ing another, which assigns that i_mapping to the file's f_mapping, if the cache manager gave the two files different containers. Each file pins only its own container. Consider (A, B = separate open files of the same inode): A, with container C1 B, with container C2 ==================== ==================== mmap() coda_file_mmap() i_mapping = C1's mapping open() do_dentry_open() f_mapping = i_mapping coda_open() cfi_container = C2 munmap() close() coda_release() i_mapping = &i_data fput(C1), the last one mmap() mmap_region() mapping_map_writable(f_mapping) Secondly, mmap_region() takes a temporary i_mmap_writable count on file->f_mapping ahead of the mmap hook, and drops it on file->f_mapping afterwards. As the hook changes f_mapping in between, the count is dropped on the container's mapping rather than on the mapping it was taken on: i_mmap_writable of Coda container mmap_region() mapping_map_writable(file->f_mapping) 1 0 __mmap_region() coda_file_mmap() coda_file->f_mapping = host_file->f_mapping vma->vm_file = get_file(host_file) vma_link_file() mapping_allow_writable() 1 1 mapping_unmap_writable(file->f_mapping) 1 0 munmap() mapping_unmap_writable() 1 -1 The container's count is negative after munmap(), so the next shared mapping of that Coda file, if it is open for writing, fails with -EPERM. Fix both issues by no longer updating coda_file->f_mapping in coda_file_mmap(), and by having coda_open() always assign the canonical mapping of the inode, as do_dentry_open() may have propagated an i_mapping which coda_file_mmap() redirected. Link: https://lore.kernel.org/20261127-mlock-madvise-mprotect-ai-fixes-v1-0-e46b2b1eb435@kernel.org Link: https://patch.msgid.link/20261127-mlock-madvise-mprotect-ai-fixes-v1-1-e46b2b1eb435@kernel.org Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: 4bb5f5d9395b ("mm: allow drivers to prevent new writable mappings") Fixes: 5de195060b2e ("mm: resolve faulty mmap_region() error path behaviour") Signed-off-by: Lorenzo Stoakes (ARM) Signed-off-by: Andrew Morton Reported-by: Chris Mason Acked-by: Pedro Falcato Acked-by: Andrew Morton Tested-by: Andrew Morton Link: https://lore.kernel.org/aw2EjGyP_g-VGVGf@gremlin Cc: Jan Harkes Cc: David Rheinsberg Cc: Hugh Dickins Cc: Vlastimil Babka Cc: Liam R. Howlett Cc: David Hildenbrand Cc: Jann Horn Cc: Alex Shi Cc: Johannes Weiner Cc: David Rientjes Cc: Rik van Riel Cc: Mike Rapoport Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Michał Mirosław Cc: Arnd Bergmann Cc: Stephen Rothwell Cc: Muhammad Usama Anjum Cc: Andrei Vagin Cc: # 5.3.x fs/coda/file.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) --- a/fs/coda/file.c~coda-never-point-a-files-f_mapping-at-a-containers-mapping +++ a/fs/coda/file.c @@ -182,7 +182,6 @@ coda_file_mmap(struct file *coda_file, s cii = ITOC(coda_inode); spin_lock(&cii->c_lock); - coda_file->f_mapping = host_file->f_mapping; if (coda_inode->i_mapping == &coda_inode->i_data) coda_inode->i_mapping = host_inode->i_mapping; @@ -248,6 +247,19 @@ int coda_open(struct inode *coda_inode, host_file->f_flags |= coda_file->f_flags & (O_APPEND | O_SYNC); + /* + * On mmap coda_inode->i_mapping is updated to point at the mapping of + * the mmap()'d file's container, and do_dentry_open() propagates that + * to coda_file->f_mapping. + * + * However coda_file's container may differ, in which case the lifetime + * of that mapping may not match that of coda_file. + * + * To avoid a dangling pointer, reassign the mapping to the canonical + * one. + */ + coda_file->f_mapping = &coda_inode->i_data; + cfi->cfi_magic = CODA_MAGIC; cfi->cfi_mapcount = 0; cfi->cfi_container = host_file; _ Patches currently in -mm which might be from ljs@kernel.org are mm-msync-return-enomem-if-page-aligned-length-overflows.patch mm-vma-drop-mm-asynchronously-in-vma_start_read.patch mm-vma-predicate-vma_assert_stabilised-on-config_debug_vm.patch mm-only-assert-mmap-locks-if-config_debug_vm-or-lockdep-is-set.patch mm-only-assert-vma-locks-if-config_debug_vm-is-set.patch mm-convert-warn_on_onces-to-vm_warn_on_once-in-vma-lock-code.patch mm-madvise-zap-markers-from-guard-regions.patch mm-mmap-free-gathered-pages-before-mmf_oom_skip.patch percpu-fix-contig-hints-that-are-too-low.patch percpu-search-the-whole-reserved-chunk.patch xen-privcmd-convert-mmap-hook-to-mmap_prepare.patch kvm-ppc-book3s-convert-spapr-tce-mmap-hook-to-mmap_prepare.patch mshv_vtl-convert-mmap-hooks-to-mmap_prepare.patch x86-sgx-convert-vepc-mmap-hook-to-mmap_prepare.patch udf-convert-mmap-hook-to-mmap_prepare.patch selinuxfs-convert-mmap-hooks-to-mmap_prepare.patch xen-convert-xenstore-interface-mmap-hooks-to-mmap_prepare.patch soc-aspeed-convert-lpc-and-p2a-control-mmap-hooks-to-mmap_prepare.patch soc-qcom-rmtfs_mem-convert-mmap-hook-to-mmap_prepare.patch tee-convert-shm-mmap-hook-to-mmap_prepare.patch misc-bcm-vk-convert-mmap-hook-to-mmap_prepare.patch ptp-vmclock-convert-mmap-hook-to-mmap_prepare.patch vhost-vdpa-convert-mmap-hook-to-mmap_prepare.patch mm-vma-error-out-on-invalid-bounds-in-unmapped_area_topdown.patch mm-vma-lock-vmas-before-taking-mm_all_locks_mutex.patch mm-filemap-convert-fault-and-readahead-logic-to-use-vma_flags_t.patch mm-madvise-convert-madvise_vma_behavior-to-use-vma_flags_t.patch mm-convert-miscellaneous-vma-flag-tests-to-use-vma_flags_t.patch fs-proc-task_mmu-convert-vma-flag-tests-to-use-vma_flags_t.patch fs-coredump-convert-vma_dump_size-to-use-vma_flags_t.patch uprobes-convert-vma-flag-tests-to-use-vma_flags_t.patch perf-convert-vma-flag-tests-to-use-vma_flags_t.patch selinux-convert-vma-flag-tests-to-use-vma_flags_t.patch apparmor-convert-vma-flag-tests-to-use-vma_flags_t.patch ima-convert-vma-flag-tests-to-use-vma_flags_t.patch ipe-convert-vma-flag-tests-to-use-vma_flags_t.patch coda-never-point-a-files-f_mapping-at-a-containers-mapping.patch fs-proc-task_mmu-write-protect-only-with-ptrace-attach.patch