AI Trajectory


Trajectory: (Expand/Collapse All)
Seq Timestamp Type Name Duration
0/0 2026/09/08 13:26 flow patch-triage
0m Args:
null

Results:
{
  "EnableConfigs": [
    "MMU"
  ],
  "FocusSymbols": [
    "call_mmap_prepare",
    "file_is_dev_zero",
    "mmap_zero_prepare"
  ],
  "KMSANReasoning": "The patch series refactors the handling of MAP_PRIVATE /dev/zero mappings to make them truly anonymous VMAs within the core memory management subsystem (moving drivers/char/mem.c to mm/char-mem.c, updating mmap_prepare handling, and removing special-case workarounds for semi-anonymous VMAs).\n\nKMSAN vs. KASAN applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce or alter kernel-to-user copies, uninitialized buffer reads, or conditional branches on uninitialized data. All structures (e.g. struct vm_area_desc) are fully initialized before use.\n- Any bugs stemming from this refactoring (e.g. VMA merging discrepancies, page offset errors, or reference/lifetime management issues) are memory management/logic issues that would manifest as use-after-free or memory corruption, which are covered by KASAN and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false,
  "Reasoning": "The patch refactors the handling of MAP_PRIVATE /dev/zero mappings so they become truly anonymous mappings within core mm rather than being treated as semi-anonymous file mappings. It modifies reachable logic in mm/vma.c, mm/char-mem.c, and header helpers, affecting VMA merging, page offset calculations, and mmap preparation.",
  "WorthFuzzing": true
}

1/1 2026/09/08 13:26 action read-patch-diff
0m Args:
null

Results:
{
  "PatchDiff": "commit 86396586e98d580888c81aef7f2d6b03669a4554\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate:   Tue Sep 8 13:26:38 2026 +0000\n\n    syz-cluster: applied patch under review\n\ndiff --git a/MAINTAINERS b/MAINTAINERS\nindex 3a19da74d00c9..a0a5db444c663 100644\n--- a/MAINTAINERS\n+++ b/MAINTAINERS\n@@ -17276,7 +17276,7 @@ F:\tDocumentation/ABI/testing/sysfs-kernel-mm-memory-tiers\n F:\tDocumentation/ABI/testing/sysfs-kernel-mm-numa\n F:\tDocumentation/admin-guide/mm/\n F:\tDocumentation/mm/\n-F:\tdrivers/char/mem.c\n+F:\tmm/char-mem.c\n F:\tinclude/linux/cma.h\n F:\tinclude/linux/dmapool.h\n F:\tinclude/linux/ioremap.h\n@@ -17481,7 +17481,7 @@ L:\tlinux-mm@kvack.org\n S:\tMaintained\n W:\thttp://www.linux-mm.org\n T:\tgit git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm\n-F:\tdrivers/char/mem.c\n+F:\tmm/char-mem.c\n F:\tinclude/trace/events/mmap.h\n F:\tfs/proc/task_mmu.c\n F:\tfs/proc/task_nommu.c\ndiff --git a/drivers/char/Makefile b/drivers/char/Makefile\nindex a46d7bf7c4c82..bb3bf66937b37 100644\n--- a/drivers/char/Makefile\n+++ b/drivers/char/Makefile\n@@ -3,7 +3,7 @@\n # Makefile for the kernel character device drivers.\n #\n \n-obj-y\t\t\t\t+= mem.o random.o\n+obj-y\t\t\t\t+= random.o\n obj-$(CONFIG_TTY_PRINTK)\t+= ttyprintk.o\n obj-y\t\t\t\t+= misc.o\n obj-$(CONFIG_TEST_MISC_MINOR)\t+= misc_minor_kunit.o\ndiff --git a/include/linux/mm.h b/include/linux/mm.h\nindex dd09c438fa23e..864d5ac3704df 100644\n--- a/include/linux/mm.h\n+++ b/include/linux/mm.h\n@@ -1551,11 +1551,6 @@ static inline void vma_set_anonymous(struct vm_area_struct *vma)\n \tvma-\u003evm_ops = NULL;\n }\n \n-static inline void vma_desc_set_anonymous(struct vm_area_desc *desc)\n-{\n-\tdesc-\u003evm_ops = NULL;\n-}\n-\n static inline bool vma_is_anonymous(const struct vm_area_struct *vma)\n {\n \treturn !vma-\u003evm_ops;\n@@ -4408,9 +4403,8 @@ static inline unsigned long vma_pages(const struct vm_area_struct *vma)\n  * If @vma is a MAP_PRIVATE file-backed mapping, then this returns the\n  * page offset within the file.\n  *\n- * Edge cases: nommu does not abide by these, MAP_PRIVATE-/dev/zero satisfies\n- * vma_is_anonymous() but has file-backed page offset, and MAP_PRIVATE-pfnmap\n- * regions have their page offset set to the first PFN in the range.\n+ * Edge cases: nommu does not abide by these and CoW MAP_PRIVATE-pfnmap regions\n+ * have their page offset set to the first PFN in the range.\n  *\n  * Returns: The page offset of the start of @vma.\n  */\ndiff --git a/include/linux/pagemap.h b/include/linux/pagemap.h\nindex 0adfa6605653d..939f3a5e973f6 100644\n--- a/include/linux/pagemap.h\n+++ b/include/linux/pagemap.h\n@@ -1128,8 +1128,7 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,\n \tconst pgoff_t pgoff = __linear_anon_page_index(vma, address);\n \n \tVM_WARN_ON_ONCE(!vma_is_cow_mapping(vma));\n-\t/* Account for MAP_PRIVATE-/dev/zero which is only semi-anonymous. */\n-\tif (vma_is_anonymous(vma) \u0026\u0026 !vma-\u003evm_file)\n+\tif (vma_is_anonymous(vma))\n \t\tVM_WARN_ON_ONCE(pgoff != linear_page_index(vma, address));\n \n \treturn pgoff;\ndiff --git a/mm/Makefile b/mm/Makefile\nindex e7245cb88c665..2a3ec53d62eef 100644\n--- a/mm/Makefile\n+++ b/mm/Makefile\n@@ -55,7 +55,8 @@ obj-y\t\t\t:= filemap.o mempool.o oom_kill.o fadvise.o \\\n \t\t\t   mm_init.o percpu.o slab_common.o \\\n \t\t\t   compaction.o show_mem.o \\\n \t\t\t   interval_tree.o list_lru.o workingset.o \\\n-\t\t\t   debug.o gup.o mmap_lock.o vma_init.o $(mmu-y)\n+\t\t\t   debug.o gup.o mmap_lock.o vma_init.o char-mem.o \\\n+\t\t\t   $(mmu-y)\n \n # Give 'page_alloc' its own module-parameter namespace\n page-alloc-y := page_alloc.o\ndiff --git a/drivers/char/mem.c b/mm/char-mem.c\nsimilarity index 97%\nrename from drivers/char/mem.c\nrename to mm/char-mem.c\nindex 63253d1de5d70..c0b5fb019223c 100644\n--- a/drivers/char/mem.c\n+++ b/mm/char-mem.c\n@@ -1,6 +1,6 @@\n // SPDX-License-Identifier: GPL-2.0\n /*\n- *  linux/drivers/char/mem.c\n+ *  mm/char-mem.c\n  *\n  *  Copyright (C) 1991, 1992  Linus Torvalds\n  *\n@@ -31,6 +31,8 @@\n #include \u003clinux/uaccess.h\u003e\n #include \u003clinux/security.h\u003e\n \n+#include \"internal.h\"\n+\n #define DEVMEM_MINOR\t1\n #define DEVPORT_MINOR\t4\n \n@@ -506,11 +508,7 @@ static int mmap_zero_prepare(struct vm_area_desc *desc)\n \tif (vma_desc_test(desc, VMA_SHARED_BIT))\n \t\treturn shmem_zero_setup_desc(desc);\n \n-\t/*\n-\t * This is a highly unique situation where we mark a MAP_PRIVATE mapping\n-\t * of /dev/zero anonymous, despite it not being.\n-\t */\n-\tvma_desc_set_anonymous(desc);\n+\t/* MAP_PRIVATE semantics are taken care of for us by core mm. */\n \treturn 0;\n }\n \n@@ -707,6 +705,17 @@ static const struct memdev {\n #endif\n };\n \n+/**\n+ * file_is_dev_zero() - is the specified @file associated with the /dev/zero\n+ * driver?\n+ * @file: File to test.\n+ * Returns: true if it is, false otherwise.\n+ */\n+bool file_is_dev_zero(const struct file *file)\n+{\n+\treturn file \u0026\u0026 file-\u003ef_op == \u0026zero_fops;\n+}\n+\n static int memory_open(struct inode *inode, struct file *filp)\n {\n \tint minor;\ndiff --git a/mm/internal.h b/mm/internal.h\nindex 38b1165212c94..2782924a277c9 100644\n--- a/mm/internal.h\n+++ b/mm/internal.h\n@@ -237,15 +237,18 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma)\n {\n \tint err = vfs_mmap(file, vma);\n \n-\tif (likely(!err))\n-\t\treturn 0;\n-\n \t/*\n-\t * OK, we tried to call the file hook for mmap(), but an error\n-\t * arose. The mapping is in an inconsistent state and we must not invoke\n-\t * any further hooks on it.\n+\t * Either we tried to call the file hook for mmap() and an error arose\n+\t * or a driver set vma-\u003evm_ops = NULL intending there to be no VMA\n+\t * operations.\n+\t *\n+\t * In the former case the VMA is in an inconsistent state and we mustn't\n+\t * invoke any further hooks on it, in the latter case the hook actually\n+\t * wanted no further hooks to be invoked, so fix both by setting dummy\n+\t * VMA ops.\n \t */\n-\tvma-\u003evm_ops = \u0026vma_dummy_vm_ops;\n+\tif (unlikely(err || !vma-\u003evm_ops))\n+\t\tvma-\u003evm_ops = \u0026vma_dummy_vm_ops;\n \n \treturn err;\n }\n@@ -1654,4 +1657,7 @@ static inline bool can_spin_trylock(void)\n \treturn true;\n }\n \n+/* char-mem.c */\n+bool file_is_dev_zero(const struct file *file);\n+\n #endif\t/* __MM_INTERNAL_H */\ndiff --git a/mm/shmem.c b/mm/shmem.c\nindex 897fa2b61346f..c60763ef561cf 100644\n--- a/mm/shmem.c\n+++ b/mm/shmem.c\n@@ -2786,7 +2786,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,\n \t\t\tsb = file_inode(file)-\u003ei_sb;\n \t\t} else {\n \t\t\t/*\n-\t\t\t * Called directly from mm/mmap.c, or drivers/char/mem.c\n+\t\t\t * Called directly from mm/mmap.c, or mm/char-mem.c\n \t\t\t * for \"/dev/zero\", to create a shared anonymous object.\n \t\t\t */\n \t\t\tif (IS_ERR(shm_mnt))\ndiff --git a/mm/vma.c b/mm/vma.c\nindex 35e7a64855fad..6fdce4852ce61 100644\n--- a/mm/vma.c\n+++ b/mm/vma.c\n@@ -2621,6 +2621,23 @@ static int __mmap_new_file_vma(struct mmap_state *map,\n \treturn 0;\n }\n \n+static void map_set_anon(struct mmap_state *map)\n+{\n+\tmap-\u003efile = NULL;\n+\tmap-\u003evm_ops = NULL;\n+\tmap-\u003epgoff = map-\u003eaddr \u003e\u003e PAGE_SHIFT;\n+}\n+\n+static bool map_is_private(const struct mmap_state *map)\n+{\n+\treturn !vma_flags_test(\u0026map-\u003evma_flags, VMA_SHARED_BIT);\n+}\n+\n+static bool map_is_anon(const struct mmap_state *map)\n+{\n+\treturn map_is_private(map) \u0026\u0026 !map-\u003efile;\n+}\n+\n /*\n  * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not\n  * possible.\n@@ -2634,8 +2651,7 @@ static int __mmap_new_file_vma(struct mmap_state *map,\n static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap,\n \tstruct mmap_action *action)\n {\n-\tconst bool is_anon = !map-\u003efile \u0026\u0026\n-\t\t!vma_flags_test(\u0026map-\u003evma_flags, VMA_SHARED_BIT);\n+\tconst bool is_anon = map_is_anon(map);\n \tstruct vma_iterator *vmi = map-\u003evmi;\n \tint error = 0;\n \tstruct vm_area_struct *vma;\n@@ -2777,6 +2793,10 @@ static int call_mmap_prepare(struct mmap_state *map,\n \tif (err)\n \t\treturn err;\n \n+\t/* It's invalid for mmap_preprare hooks to clear vm_ops. */\n+\tif (!desc-\u003evm_ops)\n+\t\treturn -EINVAL;\n+\n \terr = call_action_prepare(map, desc);\n \tif (err)\n \t\treturn err;\n@@ -2793,16 +2813,21 @@ static int call_mmap_prepare(struct mmap_state *map,\n \tmap-\u003evm_ops = desc-\u003evm_ops;\n \tmap-\u003evm_private_data = desc-\u003eprivate_data;\n \n+\t/*\n+\t * MAP_PRIVATE-/dev/zero mappings are an ancient way of getting\n+\t * anonymous mappings. Rather than allowing these mappings to be odd\n+\t * outliers, simply make them truly anonymous.\n+\t */\n+\tif (map_is_private(map) \u0026\u0026 file_is_dev_zero(map-\u003efile))\n+\t\tmap_set_anon(map);\n+\n \treturn 0;\n }\n \n static void set_vma_user_defined_fields(struct vm_area_struct *vma,\n \t\tstruct mmap_state *map)\n {\n-\tif (map-\u003evm_ops)\n-\t\tvma-\u003evm_ops = map-\u003evm_ops;\n-\telse\t/* Only /dev/zero should do this. */\n-\t\tvma_set_anonymous(vma);\n+\tvma-\u003evm_ops = map-\u003evm_ops;\n \tvma-\u003evm_private_data = map-\u003evm_private_data;\n }\n \n@@ -2882,7 +2907,7 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,\n \t\tallocated_new = true;\n \t}\n \n-\tif (have_mmap_prepare)\n+\tif (have_mmap_prepare \u0026\u0026 !map_is_anon(\u0026map))\n \t\tset_vma_user_defined_fields(vma, \u0026map);\n \n \t__mmap_complete(\u0026map, vma);\ndiff --git a/mm/vma.h b/mm/vma.h\nindex 024fabe63560a..e97bd2dfa786d 100644\n--- a/mm/vma.h\n+++ b/mm/vma.h\n@@ -267,9 +267,6 @@ static inline void assert_sane_pgoff(struct vm_area_struct *vma, pgoff_t pgoff)\n \t */\n \tif (!vma_is_anonymous(vma))\n \t\treturn;\n-\t/* MAP_PRIVATE-/dev/zero is anon, non-NULL vm_file, but has file pgoff. */\n-\tif (vma-\u003evm_file)\n-\t\treturn;\n \t/* If faulted in, could have been remapped. */\n \tif (vma-\u003eanon_vma)\n \t\treturn;\ndiff --git a/tools/testing/selftests/mm/merge.c b/tools/testing/selftests/mm/merge.c\nindex 52b8727b6628e..7dd2933417c1d 100644\n--- a/tools/testing/selftests/mm/merge.c\n+++ b/tools/testing/selftests/mm/merge.c\n@@ -1362,6 +1362,101 @@ TEST_F(merge, anon_and_page_offset_mismatch_memfd)\n \tASSERT_EQ(procmap-\u003equery.vma_end, (unsigned long)ptr + 5 * page_size);\n }\n \n+TEST_F(merge, merge_map_private_dev_zero_unfaulted)\n+{\n+\tstruct procmap_fd *procmap = \u0026self-\u003eprocmap;\n+\tunsigned int page_size = self-\u003epage_size;\n+\tchar *carveout = self-\u003ecarveout;\n+\tchar *ptr, *ptr2;\n+\tint fd_zero;\n+\n+\tif (access(\"/dev/zero\", F_OK))\n+\t\tSKIP(return, \"No /dev/zero.\");\n+\tfd_zero = open(\"/dev/zero\", O_RDWR);\n+\tASSERT_NE(fd_zero, -1);\n+\n+\t/*\n+\t * Map two MAP_PRIVATE-/dev/zero VMAs next to one another with offset 0\n+\t * each.\n+\t *\n+\t * With these being made truly anonymous upon mapping, they will\n+\t * merge. If they were file-backed VMAs the page offsets would prevent\n+\t * the merge:\n+\t *\n+\t * |-----||------|    |-------------|\n+\t * | ptr || ptr2 | -\u003e |     ptr     |\n+\t * |-----||------|    |-------------|\n+\t */\n+\tptr = mmap(carveout, 5 * page_size, PROT_READ | PROT_WRITE,\n+\t\t   MAP_FIXED | MAP_PRIVATE, fd_zero, 0);\n+\tptr2 = mmap(\u0026carveout[5 * page_size], 5 * page_size,\n+\t\t   PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, fd_zero, 0);\n+\tclose(fd_zero);\n+\tASSERT_NE(ptr, MAP_FAILED);\n+\tASSERT_NE(ptr2, MAP_FAILED);\n+\n+\t/* Assert that they merged. */\n+\tASSERT_TRUE(find_vma_procmap(procmap, ptr));\n+\tASSERT_EQ(procmap-\u003equery.vma_start, (unsigned long)ptr);\n+\tASSERT_EQ(procmap-\u003equery.vma_end, (unsigned long)ptr + 10 * page_size);\n+}\n+\n+TEST_F(merge, merge_map_private_dev_zero_faulted_unfaulted)\n+{\n+\tstruct procmap_fd *procmap = \u0026self-\u003eprocmap;\n+\tunsigned int page_size = self-\u003epage_size;\n+\tchar *carveout = self-\u003ecarveout;\n+\tchar *ptr, *ptr2;\n+\tint fd_zero;\n+\n+\tif (access(\"/dev/zero\", F_OK))\n+\t\tSKIP(return, \"No /dev/zero.\");\n+\tfd_zero = open(\"/dev/zero\", O_RDWR);\n+\tASSERT_NE(fd_zero, -1);\n+\n+\t/*\n+\t * Map a MAP_PRIVATE mapping of /dev/zero with page offset 0, then fault\n+\t * it in:\n+\t *\n+\t * |-------------------------------|\n+\t * |           faulted             |\n+\t * |-------------------------------|\n+\t */\n+\tptr = mmap(carveout, 15 * page_size, PROT_READ | PROT_WRITE,\n+\t\t   MAP_FIXED | MAP_PRIVATE, fd_zero, 0);\n+\tASSERT_NE(ptr, MAP_FAILED);\n+\tmemset(ptr, 'x', 15 * page_size);\n+\n+\t/*\n+\t * Unmap the middle:\n+\t *\n+\t * |---------|           |---------|\n+\t * | faulted |           | faulted |\n+\t * |---------|           |---------|\n+\t */\n+\tASSERT_EQ(munmap(\u0026ptr[5 * page_size], 5 * page_size), 0);\n+\n+\t/*\n+\t * Map in a new unfaulted mapping in the middle with page offset 0 -\n+\t * this should merge and would not if it were treated as a file rather\n+\t * than pure anon:\n+\t *\n+\t * |---------|-----------|---------|\n+\t * | faulted | unfaulted | faulted |\n+\t * |---------|-----------|---------|\n+\t */\n+\tptr2 = mmap(\u0026carveout[5 * page_size], 5 * page_size,\n+\t\t    PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE,\n+\t\t    fd_zero, 0);\n+\tclose(fd_zero);\n+\tASSERT_NE(ptr2, MAP_FAILED);\n+\n+\t/* Assert that they merged. */\n+\tASSERT_TRUE(find_vma_procmap(procmap, ptr));\n+\tASSERT_EQ(procmap-\u003equery.vma_start, (unsigned long)ptr);\n+\tASSERT_EQ(procmap-\u003equery.vma_end, (unsigned long)ptr + 15 * page_size);\n+}\n+\n TEST_F(merge_with_fork, mremap_faulted_to_unfaulted_prev)\n {\n \tstruct procmap_fd *procmap = \u0026self-\u003eprocmap;\ndiff --git a/tools/testing/selftests/proc/proc-self-map-files-001.c b/tools/testing/selftests/proc/proc-self-map-files-001.c\nindex 4209c64283d6f..bbca9f9e27439 100644\n--- a/tools/testing/selftests/proc/proc-self-map-files-001.c\n+++ b/tools/testing/selftests/proc/proc-self-map-files-001.c\n@@ -51,7 +51,7 @@ int main(void)\n \tint fd;\n \tunsigned long a, b;\n \n-\tfd = open(\"/dev/zero\", O_RDONLY);\n+\tfd = open(\"/proc/self/exe\", O_RDONLY);\n \tif (fd == -1)\n \t\treturn 1;\n \ndiff --git a/tools/testing/selftests/proc/proc-self-map-files-002.c b/tools/testing/selftests/proc/proc-self-map-files-002.c\nindex e6aa00a183bcd..5786cdffbbf63 100644\n--- a/tools/testing/selftests/proc/proc-self-map-files-002.c\n+++ b/tools/testing/selftests/proc/proc-self-map-files-002.c\n@@ -57,7 +57,7 @@ int main(void)\n \tint fd;\n \tunsigned long a, b;\n \n-\tfd = open(\"/dev/zero\", O_RDONLY);\n+\tfd = open(\"/proc/self/exe\", O_RDONLY);\n \tif (fd == -1)\n \t\treturn 1;\n \ndiff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h\nindex 4c58487b764e9..5669081d91b9f 100644\n--- a/tools/testing/vma/include/dup.h\n+++ b/tools/testing/vma/include/dup.h\n@@ -1638,9 +1638,15 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,\n \tconst pgoff_t pgoff = __linear_anon_page_index(vma, address);\n \n \tVM_WARN_ON_ONCE(!vma_is_cow_mapping(vma));\n-\t/* Account for MAP_PRIVATE-/dev/zero which is only semi-anonymous. */\n-\tif (vma_is_anonymous(vma) \u0026\u0026 !vma-\u003evm_file)\n+\tif (vma_is_anonymous(vma))\n \t\tVM_WARN_ON_ONCE(pgoff != linear_page_index(vma, address));\n \n \treturn pgoff;\n }\n+\n+extern const struct file_operations zero_fops;\n+\n+static inline bool file_is_dev_zero(const struct file *file)\n+{\n+\treturn file \u0026\u0026 file-\u003ef_op == \u0026zero_fops;\n+}\ndiff --git a/tools/testing/vma/shared.c b/tools/testing/vma/shared.c\nindex 4a39c9d504896..8c4826499f405 100644\n--- a/tools/testing/vma/shared.c\n+++ b/tools/testing/vma/shared.c\n@@ -12,6 +12,15 @@ const struct vm_operations_struct vma_dummy_vm_ops;\n struct anon_vma dummy_anon_vma;\n struct task_struct __current;\n \n+static int mmap_zero_prepare(struct vm_area_desc *desc)\n+{\n+\treturn 0;\n+}\n+\n+const struct file_operations zero_fops = {\n+\t.mmap_prepare = mmap_zero_prepare,\n+};\n+\n struct vm_area_struct *alloc_vma(struct mm_struct *mm,\n \t\tunsigned long start, unsigned long end,\n \t\tpgoff_t pgoff, vma_flags_t vma_flags)\ndiff --git a/tools/testing/vma/tests/mmap.c b/tools/testing/vma/tests/mmap.c\nindex c85bc000d1cb7..fa73faff22626 100644\n--- a/tools/testing/vma/tests/mmap.c\n+++ b/tools/testing/vma/tests/mmap.c\n@@ -45,7 +45,44 @@ static bool test_mmap_region_basic(void)\n \treturn true;\n }\n \n+static bool test_pure_anon_dev_zero(void)\n+{\n+\tconst vma_flags_t vma_flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,\n+\t\t\tVMA_MAYREAD_BIT, VMA_MAYWRITE_BIT);\n+\tstruct file file = {\n+\t\t.f_op = \u0026zero_fops,\n+\t};\n+\tstruct mm_struct mm = {};\n+\tstruct vm_area_struct *vma;\n+\tunsigned long addr;\n+\tVMA_ITERATOR(vmi, \u0026mm, 0);\n+\n+\tcurrent-\u003emm = \u0026mm;\n+\n+\t/*\n+\t * Map a MAP_PRIVATE-/dev/zero mapping at address 0x300000 with a page\n+\t * offset of 0x10, which we expect to be reset to the anonymous page\n+\t * offset.\n+\t */\n+\taddr = __mmap_region(\u0026file, 0x300000, 0x3000, vma_flags, 0x10, NULL);\n+\tASSERT_EQ(addr, 0x300000);\n+\n+\t/* Assert that it truly is an anonymous mapping. */\n+\tvma = vma_lookup(\u0026mm, addr);\n+\tASSERT_NE(vma, NULL);\n+\tASSERT_TRUE(vma_is_anonymous(vma));\n+\tASSERT_EQ(vma-\u003evm_file, NULL);\n+\tASSERT_EQ(vma-\u003evm_private_data, NULL);\n+\t/* Expect anonymous page offsets. */\n+\tASSERT_EQ(vma-\u003evm_pgoff, 0x300);\n+\tASSERT_EQ(vma_start_anon_pgoff(vma), 0x300);\n+\n+\tcleanup_mm(\u0026mm, \u0026vmi);\n+\treturn true;\n+}\n+\n static void run_mmap_tests(int *num_tests, int *num_fail)\n {\n \tTEST(mmap_region_basic);\n+\tTEST(pure_anon_dev_zero);\n }\n"
}

2/1 2026/09/08 13:26 agent patch-evaluator
0m Model:
core

Args:
null

Results:
{
  "EnableConfigs": [
    "MMU"
  ],
  "FocusSymbols": [
    "call_mmap_prepare",
    "file_is_dev_zero",
    "mmap_zero_prepare"
  ],
  "Reasoning": "The patch refactors the handling of MAP_PRIVATE /dev/zero mappings so they become truly anonymous mappings within core mm rather than being treated as semi-anonymous file mappings. It modifies reachable logic in mm/vma.c, mm/char-mem.c, and header helpers, affecting VMA merging, page offset calculations, and mmap preparation.",
  "WorthFuzzing": true
}

Instruction:
You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.

IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.

================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.

- REACHABILITY IS THE PRIMARY GATE:
  Fuzzing can only discover bugs in code that can actually execute in standard virtualized
  environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
  If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
  regardless of whether it adds assertions or complex logic.

- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
  Patch authors routinely label changes as "cleanups", "refactorings", or state
  "No functional change intended". Do NOT take these claims at face value.
  Code refactorings that rearrange logic, introduce helper functions, or alter state management
  in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
  If reachable executable code is modified or refactored, it MUST be fuzzed.

- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
  When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
  BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
  Even if the author believes the invariant always holds, fuzzing is essential to verify whether
  an unusual sequence of operations can violate it.

================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:

- Non-kernel and non-executable changes:
  * Modifications to Documentation/, comments, or spelling fixes.
  * User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
    that do not affect the compiled kernel image (vmlinux) or kernel modules.
  * Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
    that do not alter control flow or data structures.
  * Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
  * Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
    ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
  * Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
    physical PCI hot-unplug or manual sysfs driver unbinding.
  * Code paths exclusive to architectures other than the target architecture.

================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
  * Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
    BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
  * Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
  * Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
  * Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).

================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:

- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
  Do NOT list generic, ubiquitous functions called by almost every program in the corpus
  (including, but not limited to: general memory allocators and deallocators, page fault
  and trap handlers, or core synchronization primitives; this is not an exhaustive list).
  Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
  which severely dilutes fuzzing effort away from the actual changes.

- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
  List functions that specifically implement the logic being added or altered, or direct API entrypoints
  for the subsystem feature under review.

- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
  Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
  distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
  If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
  functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).

================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 86396586e98d580888c81aef7f2d6b03669a4554
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 8 13:26:38 2026 +0000

    syz-cluster: applied patch under review

diff --git a/MAINTAINERS b/MAINTAINERS
index 3a19da74d00c9..a0a5db444c663 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17276,7 +17276,7 @@ F:	Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
 F:	Documentation/ABI/testing/sysfs-kernel-mm-numa
 F:	Documentation/admin-guide/mm/
 F:	Documentation/mm/
-F:	drivers/char/mem.c
+F:	mm/char-mem.c
 F:	include/linux/cma.h
 F:	include/linux/dmapool.h
 F:	include/linux/ioremap.h
@@ -17481,7 +17481,7 @@ L:	linux-mm@kvack.org
 S:	Maintained
 W:	http://www.linux-mm.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
-F:	drivers/char/mem.c
+F:	mm/char-mem.c
 F:	include/trace/events/mmap.h
 F:	fs/proc/task_mmu.c
 F:	fs/proc/task_nommu.c
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index a46d7bf7c4c82..bb3bf66937b37 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -3,7 +3,7 @@
 # Makefile for the kernel character device drivers.
 #
 
-obj-y				+= mem.o random.o
+obj-y				+= random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
 obj-y				+= misc.o
 obj-$(CONFIG_TEST_MISC_MINOR)	+= misc_minor_kunit.o
diff --git a/include/linux/mm.h b/include/linux/mm.h
index dd09c438fa23e..864d5ac3704df 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1551,11 +1551,6 @@ static inline void vma_set_anonymous(struct vm_area_struct *vma)
 	vma->vm_ops = NULL;
 }
 
-static inline void vma_desc_set_anonymous(struct vm_area_desc *desc)
-{
-	desc->vm_ops = NULL;
-}
-
 static inline bool vma_is_anonymous(const struct vm_area_struct *vma)
 {
 	return !vma->vm_ops;
@@ -4408,9 +4403,8 @@ static inline unsigned long vma_pages(const struct vm_area_struct *vma)
  * If @vma is a MAP_PRIVATE file-backed mapping, then this returns the
  * page offset within the file.
  *
- * Edge cases: nommu does not abide by these, MAP_PRIVATE-/dev/zero satisfies
- * vma_is_anonymous() but has file-backed page offset, and MAP_PRIVATE-pfnmap
- * regions have their page offset set to the first PFN in the range.
+ * Edge cases: nommu does not abide by these and CoW MAP_PRIVATE-pfnmap regions
+ * have their page offset set to the first PFN in the range.
  *
  * Returns: The page offset of the start of @vma.
  */
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 0adfa6605653d..939f3a5e973f6 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1128,8 +1128,7 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,
 	const pgoff_t pgoff = __linear_anon_page_index(vma, address);
 
 	VM_WARN_ON_ONCE(!vma_is_cow_mapping(vma));
-	/* Account for MAP_PRIVATE-/dev/zero which is only semi-anonymous. */
-	if (vma_is_anonymous(vma) && !vma->vm_file)
+	if (vma_is_anonymous(vma))
 		VM_WARN_ON_ONCE(pgoff != linear_page_index(vma, address));
 
 	return pgoff;
diff --git a/mm/Makefile b/mm/Makefile
index e7245cb88c665..2a3ec53d62eef 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -55,7 +55,8 @@ obj-y			:= filemap.o mempool.o oom_kill.o fadvise.o \
 			   mm_init.o percpu.o slab_common.o \
 			   compaction.o show_mem.o \
 			   interval_tree.o list_lru.o workingset.o \
-			   debug.o gup.o mmap_lock.o vma_init.o $(mmu-y)
+			   debug.o gup.o mmap_lock.o vma_init.o char-mem.o \
+			   $(mmu-y)
 
 # Give 'page_alloc' its own module-parameter namespace
 page-alloc-y := page_alloc.o
diff --git a/drivers/char/mem.c b/mm/char-mem.c
similarity index 97%
rename from drivers/char/mem.c
rename to mm/char-mem.c
index 63253d1de5d70..c0b5fb019223c 100644
--- a/drivers/char/mem.c
+++ b/mm/char-mem.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- *  linux/drivers/char/mem.c
+ *  mm/char-mem.c
  *
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *
@@ -31,6 +31,8 @@
 #include <linux/uaccess.h>
 #include <linux/security.h>
 
+#include "internal.h"
+
 #define DEVMEM_MINOR	1
 #define DEVPORT_MINOR	4
 
@@ -506,11 +508,7 @@ static int mmap_zero_prepare(struct vm_area_desc *desc)
 	if (vma_desc_test(desc, VMA_SHARED_BIT))
 		return shmem_zero_setup_desc(desc);
 
-	/*
-	 * This is a highly unique situation where we mark a MAP_PRIVATE mapping
-	 * of /dev/zero anonymous, despite it not being.
-	 */
-	vma_desc_set_anonymous(desc);
+	/* MAP_PRIVATE semantics are taken care of for us by core mm. */
 	return 0;
 }
 
@@ -707,6 +705,17 @@ static const struct memdev {
 #endif
 };
 
+/**
+ * file_is_dev_zero() - is the specified @file associated with the /dev/zero
+ * driver?
+ * @file: File to test.
+ * Returns: true if it is, false otherwise.
+ */
+bool file_is_dev_zero(const struct file *file)
+{
+	return file && file->f_op == &zero_fops;
+}
+
 static int memory_open(struct inode *inode, struct file *filp)
 {
 	int minor;
diff --git a/mm/internal.h b/mm/internal.h
index 38b1165212c94..2782924a277c9 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -237,15 +237,18 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
 {
 	int err = vfs_mmap(file, vma);
 
-	if (likely(!err))
-		return 0;
-
 	/*
-	 * OK, we tried to call the file hook for mmap(), but an error
-	 * arose. The mapping is in an inconsistent state and we must not invoke
-	 * any further hooks on it.
+	 * Either we tried to call the file hook for mmap() and an error arose
+	 * or a driver set vma->vm_ops = NULL intending there to be no VMA
+	 * operations.
+	 *
+	 * In the former case the VMA is in an inconsistent state and we mustn't
+	 * invoke any further hooks on it, in the latter case the hook actually
+	 * wanted no further hooks to be invoked, so fix both by setting dummy
+	 * VMA ops.
 	 */
-	vma->vm_ops = &vma_dummy_vm_ops;
+	if (unlikely(err || !vma->vm_ops))
+		vma->vm_ops = &vma_dummy_vm_ops;
 
 	return err;
 }
@@ -1654,4 +1657,7 @@ static inline bool can_spin_trylock(void)
 	return true;
 }
 
+/* char-mem.c */
+bool file_is_dev_zero(const struct file *file);
+
 #endif	/* __MM_INTERNAL_H */
diff --git a/mm/shmem.c b/mm/shmem.c
index 897fa2b61346f..c60763ef561cf 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2786,7 +2786,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 			sb = file_inode(file)->i_sb;
 		} else {
 			/*
-			 * Called directly from mm/mmap.c, or drivers/char/mem.c
+			 * Called directly from mm/mmap.c, or mm/char-mem.c
 			 * for "/dev/zero", to create a shared anonymous object.
 			 */
 			if (IS_ERR(shm_mnt))
diff --git a/mm/vma.c b/mm/vma.c
index 35e7a64855fad..6fdce4852ce61 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2621,6 +2621,23 @@ static int __mmap_new_file_vma(struct mmap_state *map,
 	return 0;
 }
 
+static void map_set_anon(struct mmap_state *map)
+{
+	map->file = NULL;
+	map->vm_ops = NULL;
+	map->pgoff = map->addr >> PAGE_SHIFT;
+}
+
+static bool map_is_private(const struct mmap_state *map)
+{
+	return !vma_flags_test(&map->vma_flags, VMA_SHARED_BIT);
+}
+
+static bool map_is_anon(const struct mmap_state *map)
+{
+	return map_is_private(map) && !map->file;
+}
+
 /*
  * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not
  * possible.
@@ -2634,8 +2651,7 @@ static int __mmap_new_file_vma(struct mmap_state *map,
 static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap,
 	struct mmap_action *action)
 {
-	const bool is_anon = !map->file &&
-		!vma_flags_test(&map->vma_flags, VMA_SHARED_BIT);
+	const bool is_anon = map_is_anon(map);
 	struct vma_iterator *vmi = map->vmi;
 	int error = 0;
 	struct vm_area_struct *vma;
@@ -2777,6 +2793,10 @@ static int call_mmap_prepare(struct mmap_state *map,
 	if (err)
 		return err;
 
+	/* It's invalid for mmap_preprare hooks to clear vm_ops. */
+	if (!desc->vm_ops)
+		return -EINVAL;
+
 	err = call_action_prepare(map, desc);
 	if (err)
 		return err;
@@ -2793,16 +2813,21 @@ static int call_mmap_prepare(struct mmap_state *map,
 	map->vm_ops = desc->vm_ops;
 	map->vm_private_data = desc->private_data;
 
+	/*
+	 * MAP_PRIVATE-/dev/zero mappings are an ancient way of getting
+	 * anonymous mappings. Rather than allowing these mappings to be odd
+	 * outliers, simply make them truly anonymous.
+	 */
+	if (map_is_private(map) && file_is_dev_zero(map->file))
+		map_set_anon(map);
+
 	return 0;
 }
 
 static void set_vma_user_defined_fields(struct vm_area_struct *vma,
 		struct mmap_state *map)
 {
-	if (map->vm_ops)
-		vma->vm_ops = map->vm_ops;
-	else	/* Only /dev/zero should do this. */
-		vma_set_anonymous(vma);
+	vma->vm_ops = map->vm_ops;
 	vma->vm_private_data = map->vm_private_data;
 }
 
@@ -2882,7 +2907,7 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
 		allocated_new = true;
 	}
 
-	if (have_mmap_prepare)
+	if (have_mmap_prepare && !map_is_anon(&map))
 		set_vma_user_defined_fields(vma, &map);
 
 	__mmap_complete(&map, vma);
diff --git a/mm/vma.h b/mm/vma.h
index 024fabe63560a..e97bd2dfa786d 100644
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -267,9 +267,6 @@ static inline void assert_sane_pgoff(struct vm_area_struct *vma, pgoff_t pgoff)
 	 */
 	if (!vma_is_anonymous(vma))
 		return;
-	/* MAP_PRIVATE-/dev/zero is anon, non-NULL vm_file, but has file pgoff. */
-	if (vma->vm_file)
-		return;
 	/* If faulted in, could have been remapped. */
 	if (vma->anon_vma)
 		return;
diff --git a/tools/testing/selftests/mm/merge.c b/tools/testing/selftests/mm/merge.c
index 52b8727b6628e..7dd2933417c1d 100644
--- a/tools/testing/selftests/mm/merge.c
+++ b/tools/testing/selftests/mm/merge.c
@@ -1362,6 +1362,101 @@ TEST_F(merge, anon_and_page_offset_mismatch_memfd)
 	ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr + 5 * page_size);
 }
 
+TEST_F(merge, merge_map_private_dev_zero_unfaulted)
+{
+	struct procmap_fd *procmap = &self->procmap;
+	unsigned int page_size = self->page_size;
+	char *carveout = self->carveout;
+	char *ptr, *ptr2;
+	int fd_zero;
+
+	if (access("/dev/zero", F_OK))
+		SKIP(return, "No /dev/zero.");
+	fd_zero = open("/dev/zero", O_RDWR);
+	ASSERT_NE(fd_zero, -1);
+
+	/*
+	 * Map two MAP_PRIVATE-/dev/zero VMAs next to one another with offset 0
+	 * each.
+	 *
+	 * With these being made truly anonymous upon mapping, they will
+	 * merge. If they were file-backed VMAs the page offsets would prevent
+	 * the merge:
+	 *
+	 * |-----||------|    |-------------|
+	 * | ptr || ptr2 | -> |     ptr     |
+	 * |-----||------|    |-------------|
+	 */
+	ptr = mmap(carveout, 5 * page_size, PROT_READ | PROT_WRITE,
+		   MAP_FIXED | MAP_PRIVATE, fd_zero, 0);
+	ptr2 = mmap(&carveout[5 * page_size], 5 * page_size,
+		   PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, fd_zero, 0);
+	close(fd_zero);
+	ASSERT_NE(ptr, MAP_FAILED);
+	ASSERT_NE(ptr2, MAP_FAILED);
+
+	/* Assert that they merged. */
+	ASSERT_TRUE(find_vma_procmap(procmap, ptr));
+	ASSERT_EQ(procmap->query.vma_start, (unsigned long)ptr);
+	ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr + 10 * page_size);
+}
+
+TEST_F(merge, merge_map_private_dev_zero_faulted_unfaulted)
+{
+	struct procmap_fd *procmap = &self->procmap;
+	unsigned int page_size = self->page_size;
+	char *carveout = self->carveout;
+	char *ptr, *ptr2;
+	int fd_zero;
+
+	if (access("/dev/zero", F_OK))
+		SKIP(return, "No /dev/zero.");
+	fd_zero = open("/dev/zero", O_RDWR);
+	ASSERT_NE(fd_zero, -1);
+
+	/*
+	 * Map a MAP_PRIVATE mapping of /dev/zero with page offset 0, then fault
+	 * it in:
+	 *
+	 * |-------------------------------|
+	 * |           faulted             |
+	 * |-------------------------------|
+	 */
+	ptr = mmap(carveout, 15 * page_size, PROT_READ | PROT_WRITE,
+		   MAP_FIXED | MAP_PRIVATE, fd_zero, 0);
+	ASSERT_NE(ptr, MAP_FAILED);
+	memset(ptr, 'x', 15 * page_size);
+
+	/*
+	 * Unmap the middle:
+	 *
+	 * |---------|           |---------|
+	 * | faulted |           | faulted |
+	 * |---------|           |---------|
+	 */
+	ASSERT_EQ(munmap(&ptr[5 * page_size], 5 * page_size), 0);
+
+	/*
+	 * Map in a new unfaulted mapping in the middle with page offset 0 -
+	 * this should merge and would not if it were treated as a file rather
+	 * than pure anon:
+	 *
+	 * |---------|-----------|---------|
+	 * | faulted | unfaulted | faulted |
+	 * |---------|-----------|---------|
+	 */
+	ptr2 = mmap(&carveout[5 * page_size], 5 * page_size,
+		    PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE,
+		    fd_zero, 0);
+	close(fd_zero);
+	ASSERT_NE(ptr2, MAP_FAILED);
+
+	/* Assert that they merged. */
+	ASSERT_TRUE(find_vma_procmap(procmap, ptr));
+	ASSERT_EQ(procmap->query.vma_start, (unsigned long)ptr);
+	ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr + 15 * page_size);
+}
+
 TEST_F(merge_with_fork, mremap_faulted_to_unfaulted_prev)
 {
 	struct procmap_fd *procmap = &self->procmap;
diff --git a/tools/testing/selftests/proc/proc-self-map-files-001.c b/tools/testing/selftests/proc/proc-self-map-files-001.c
index 4209c64283d6f..bbca9f9e27439 100644
--- a/tools/testing/selftests/proc/proc-self-map-files-001.c
+++ b/tools/testing/selftests/proc/proc-self-map-files-001.c
@@ -51,7 +51,7 @@ int main(void)
 	int fd;
 	unsigned long a, b;
 
-	fd = open("/dev/zero", O_RDONLY);
+	fd = open("/proc/self/exe", O_RDONLY);
 	if (fd == -1)
 		return 1;
 
diff --git a/tools/testing/selftests/proc/proc-self-map-files-002.c b/tools/testing/selftests/proc/proc-self-map-files-002.c
index e6aa00a183bcd..5786cdffbbf63 100644
--- a/tools/testing/selftests/proc/proc-self-map-files-002.c
+++ b/tools/testing/selftests/proc/proc-self-map-files-002.c
@@ -57,7 +57,7 @@ int main(void)
 	int fd;
 	unsigned long a, b;
 
-	fd = open("/dev/zero", O_RDONLY);
+	fd = open("/proc/self/exe", O_RDONLY);
 	if (fd == -1)
 		return 1;
 
diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h
index 4c58487b764e9..5669081d91b9f 100644
--- a/tools/testing/vma/include/dup.h
+++ b/tools/testing/vma/include/dup.h
@@ -1638,9 +1638,15 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,
 	const pgoff_t pgoff = __linear_anon_page_index(vma, address);
 
 	VM_WARN_ON_ONCE(!vma_is_cow_mapping(vma));
-	/* Account for MAP_PRIVATE-/dev/zero which is only semi-anonymous. */
-	if (vma_is_anonymous(vma) && !vma->vm_file)
+	if (vma_is_anonymous(vma))
 		VM_WARN_ON_ONCE(pgoff != linear_page_index(vma, address));
 
 	return pgoff;
 }
+
+extern const struct file_operations zero_fops;
+
+static inline bool file_is_dev_zero(const struct file *file)
+{
+	return file && file->f_op == &zero_fops;
+}
diff --git a/tools/testing/vma/shared.c b/tools/testing/vma/shared.c
index 4a39c9d504896..8c4826499f405 100644
--- a/tools/testing/vma/shared.c
+++ b/tools/testing/vma/shared.c
@@ -12,6 +12,15 @@ const struct vm_operations_struct vma_dummy_vm_ops;
 struct anon_vma dummy_anon_vma;
 struct task_struct __current;
 
+static int mmap_zero_prepare(struct vm_area_desc *desc)
+{
+	return 0;
+}
+
+const struct file_operations zero_fops = {
+	.mmap_prepare = mmap_zero_prepare,
+};
+
 struct vm_area_struct *alloc_vma(struct mm_struct *mm,
 		unsigned long start, unsigned long end,
 		pgoff_t pgoff, vma_flags_t vma_flags)
diff --git a/tools/testing/vma/tests/mmap.c b/tools/testing/vma/tests/mmap.c
index c85bc000d1cb7..fa73faff22626 100644
--- a/tools/testing/vma/tests/mmap.c
+++ b/tools/testing/vma/tests/mmap.c
@@ -45,7 +45,44 @@ static bool test_mmap_region_basic(void)
 	return true;
 }
 
+static bool test_pure_anon_dev_zero(void)
+{
+	const vma_flags_t vma_flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
+			VMA_MAYREAD_BIT, VMA_MAYWRITE_BIT);
+	struct file file = {
+		.f_op = &zero_fops,
+	};
+	struct mm_struct mm = {};
+	struct vm_area_struct *vma;
+	unsigned long addr;
+	VMA_ITERATOR(vmi, &mm, 0);
+
+	current->mm = &mm;
+
+	/*
+	 * Map a MAP_PRIVATE-/dev/zero mapping at address 0x300000 with a page
+	 * offset of 0x10, which we expect to be reset to the anonymous page
+	 * offset.
+	 */
+	addr = __mmap_region(&file, 0x300000, 0x3000, vma_flags, 0x10, NULL);
+	ASSERT_EQ(addr, 0x300000);
+
+	/* Assert that it truly is an anonymous mapping. */
+	vma = vma_lookup(&mm, addr);
+	ASSERT_NE(vma, NULL);
+	ASSERT_TRUE(vma_is_anonymous(vma));
+	ASSERT_EQ(vma->vm_file, NULL);
+	ASSERT_EQ(vma->vm_private_data, NULL);
+	/* Expect anonymous page offsets. */
+	ASSERT_EQ(vma->vm_pgoff, 0x300);
+	ASSERT_EQ(vma_start_anon_pgoff(vma), 0x300);
+
+	cleanup_mm(&mm, &vmi);
+	return true;
+}
+
 static void run_mmap_tests(int *num_tests, int *num_fail)
 {
 	TEST(mmap_region_basic);
+	TEST(pure_anon_dev_zero);
 }

3/2 2026/09/08 13:26 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 9749
							output: 21
							thoughts: 1178
						

Thoughts:
**Patch Analysis: Determining Fuzzing Worthiness and Configuration**

Okay, let's break this down. The instructions are clear: discover crashes, regressions, or latent bugs introduced by the patch series. I need to determine if this patch is worth fuzzing. The criteria are also clear: check for touch points on reachable executable code within core subsystems.

My initial thought is that this *looks* promising for fuzzing. We have modifications to `mm/vma.c`, `mm/char-mem.c`, `include/linux/mm.h`, `include/linux/pagemap.h`, and `mm/internal.h`, all core memory management areas. Specifically, the patch series seems to be refactoring how `/dev/zero` mappings interact with anonymous memory, making them truly anonymous in the core mm. This seems like it touches reachable code in memory management, so `WorthFuzzing` is likely `true`.

Let's dissect the diff step-by-step to be certain:

1.  We have the standard file renames/moves (MAINTAINERS, `drivers/char/Makefile`, `mm/Makefile`). These aren't immediately concerning.
2.  `drivers/char/mem.c` is moved to `mm/char-mem.c`. The changes to `mmap_zero_prepare()` and the addition of `file_is_dev_zero()` are interesting and require a closer look. This definitely seems core mm related.
3.  The changes in `include/linux/mm.h` (removal of `vma_desc_set_anonymous()`) and `include/linux/pagemap.h` (simplification of `linear_anon_page_index()`) point to refactoring of how VMA's are handled, which strengthens the idea of fuzzing.
4.  `mm/internal.h` includes the inline function modification in `mmap_file`, and the addition of the prototype `file_is_dev_zero`. This is certainly related to VMA setup and the new checks.
5.  `mm/vma.c` is where things get really interesting: new functions like `map_set_anon()`, `map_is_private()`, `map_is_anon()`, and changes to `__mmap_new_vma()`, `call_mmap_prepare()`, and `__mmap_region()`. These modifications are crucial. The changes in `call_mmap_prepare()` and `__mmap_region()` seem like code paths with high potential for issues, and those are definitely in core memory management.
6.  The change in `mm/vma.h` (removing a `vma->vm_file` check in `assert_sane_pgoff`) also feels like a refactoring.
7.  And of course, we have related selftests.

This patch is definitely touching core mm logic, specifically memory management with respect to mapping and VMA logic (`mm/vma.c`, `mm/char-mem.c`, `mm/internal.h`, `include/linux/pagemap.h`, `include/linux/mm.h`, `mm/vma.h`). Given the instructions, this seems like *exactly* the kind of change we *want* to fuzz. It's a clear 'yes' to `WorthFuzzing=true`.

Now, let's identify relevant symbols for fuzzing. I'll need to create a list of `FocusSymbols` and consider which `EnableConfigs` might be useful. I'll need to go through the diff and create a list of functions touched by the changes:

*   `call_mmap_prepare` (in mm/vma.c)
*   `__mmap_new_vma` (in mm/vma.c)
*   `__mmap_region` (in mm/vma.c)
*   `map_set_anon` (static in mm/vma.c)
*   `file_is_dev_zero` (in mm/char-mem.c)
*   `mmap_zero_prepare` (in mm/char-mem.c)
*   `mmap_file` (inline in mm/internal.h)
*   `linear_anon_page_index` (inline in include/linux/pagemap.h)
*   `assert_sane_pgoff` (inline in mm/vma.h)

I'll now need to use `git grep` and the kernel build system to see which other functions interact with these, and consider additional configuration options. My goal is a fuzzing configuration that maximizes the likelihood


4/2 2026/09/08 13:26 tool grepper
0m Args:
{
  "Expression": "file_is_dev_zero"
}

Results:
{
  "Output": "mm/char-mem.c=686=static const struct memdev {\n--\nmm/char-mem.c-708-/**\nmm/char-mem.c:709: * file_is_dev_zero() - is the specified @file associated with the /dev/zero\nmm/char-mem.c-710- * driver?\n--\nmm/char-mem.c-713- */\nmm/char-mem.c:714:bool file_is_dev_zero(const struct file *file)\nmm/char-mem.c-715-{\n--\nmm/internal.h=1637=static inline bool can_spin_trylock(void)\n--\nmm/internal.h-1660-/* char-mem.c */\nmm/internal.h:1661:bool file_is_dev_zero(const struct file *file);\nmm/internal.h-1662-\n--\nmm/vma.c=2786=static int call_mmap_prepare(struct mmap_state *map,\n--\nmm/vma.c-2820-\t */\nmm/vma.c:2821:\tif (map_is_private(map) \u0026\u0026 file_is_dev_zero(map-\u003efile))\nmm/vma.c-2822-\t\tmap_set_anon(map);\n--\ntools/testing/vma/include/dup.h=1647=extern const struct file_operations zero_fops;\ntools/testing/vma/include/dup.h-1648-\ntools/testing/vma/include/dup.h:1649:static inline bool file_is_dev_zero(const struct file *file)\ntools/testing/vma/include/dup.h-1650-{\n"
}

5/2 2026/09/08 13:26 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 12428
							output: 20
							thoughts: 22
						

Thoughts:
Here's a summary of my thought process:

**Diving into Memory Mapping for Character Devices**

Alright, let's get down to brass tacks. I need to understand how zero-filled memory is prepared within the context of character devices. That means my immediate focus is on the `mmap_zero_prepare` function, specifically in `mm/char-mem.c`. This is where the magic happens, or at least, the preparation for the magic of mapping zero pages into user space memory occurs. I'm assuming that this function is where the kernel handles the initial setup before the actual memory mapping takes place, or the actual zeroing itself. Given the file and function name, I'm expecting to find the key steps related to setting up the page table entries, or possibly zeroing the pages ahead of the mapping. This is where the intricacies of memory management and device interaction converge, and I'm ready to dig in. This is where I'll find my answers.



6/2 2026/09/08 13:26 tool grepper
0m Args:
{
  "Expression": "mmap_zero_prepare"
}

Results:
{
  "Output": "mm/char-mem.c=476=static ssize_t read_zero(struct file *file, char __user *buf,\n--\nmm/char-mem.c-502-\nmm/char-mem.c:503:static int mmap_zero_prepare(struct vm_area_desc *desc)\nmm/char-mem.c-504-{\n--\nmm/char-mem.c=523=static unsigned long get_unmapped_area_zero(struct file *file,\n--\nmm/char-mem.c-528-\t\t/*\nmm/char-mem.c:529:\t\t * mmap_zero_prepare() will call shmem_zero_setup() to create a\nmm/char-mem.c-530-\t\t * file, so use shmem's get_unmapped_area in case it can be\n--\nmm/char-mem.c=664=static const struct file_operations zero_fops = {\n--\nmm/char-mem.c-671-\t.splice_write\t= splice_write_zero,\nmm/char-mem.c:672:\t.mmap_prepare\t= mmap_zero_prepare,\nmm/char-mem.c-673-\t.get_unmapped_area = get_unmapped_area_zero,\n--\ntools/testing/vma/shared.c=13=struct task_struct __current;\ntools/testing/vma/shared.c-14-\ntools/testing/vma/shared.c:15:static int mmap_zero_prepare(struct vm_area_desc *desc)\ntools/testing/vma/shared.c-16-{\n--\ntools/testing/vma/shared.c=20=const struct file_operations zero_fops = {\ntools/testing/vma/shared.c:21:\t.mmap_prepare = mmap_zero_prepare,\ntools/testing/vma/shared.c-22-};\n"
}

7/2 2026/09/08 13:26 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 13170
							output: 35
							thoughts: 45
						

Thoughts:
Here's my summary, as though I'm thinking through this process:

**Diving into Memory Mapping Implementation**

Okay, so I need to understand how this memory mapping is being prepared and executed. My immediate focus is on the `call_mmap_prepare` and `__mmap_region` functions. These are likely the crucial entry points and the core logic within `mm/vma.c`, so that's where I need to start. I'm going to carefully read the surrounding code in `mm/vma.c` to grasp the flow and context around those specific lines. I want to see how the Virtual Memory Area (VMA) is being set up and how the region is actually established. This should help me understand the pre-conditions, the assumptions being made, and what the code is *actually* doing.



8/2 2026/09/08 13:26 tool read-file
0m Args:
{
  "File": "mm/vma.c",
  "FirstLine": 2780,
  "LineCount": 80
}

Results:
{
  "Contents": "2780:\t * that are permitted to be updated by the caller.\n2781:\t *\n2782:\t * All but user-defined fields will be pre-populated with original values.\n2783:\t *\n2784:\t * Returns 0 on success, or an error code otherwise.\n2785:\t */\n2786:\tstatic int call_mmap_prepare(struct mmap_state *map,\n2787:\t\t\tstruct vm_area_desc *desc)\n2788:\t{\n2789:\t\tint err;\n2790:\t\n2791:\t\t/* Invoke the hook. */\n2792:\t\terr = vfs_mmap_prepare(map-\u003efile, desc);\n2793:\t\tif (err)\n2794:\t\t\treturn err;\n2795:\t\n2796:\t\t/* It's invalid for mmap_preprare hooks to clear vm_ops. */\n2797:\t\tif (!desc-\u003evm_ops)\n2798:\t\t\treturn -EINVAL;\n2799:\t\n2800:\t\terr = call_action_prepare(map, desc);\n2801:\t\tif (err)\n2802:\t\t\treturn err;\n2803:\t\n2804:\t\t/* Update fields permitted to be changed. */\n2805:\t\tmap-\u003epgoff = desc-\u003epgoff;\n2806:\t\tif (desc-\u003evm_file != map-\u003efile) {\n2807:\t\t\tmap-\u003efile_doesnt_need_get = true;\n2808:\t\t\tmap-\u003efile = desc-\u003evm_file;\n2809:\t\t}\n2810:\t\tmap-\u003evma_flags = desc-\u003evma_flags;\n2811:\t\tmap-\u003epage_prot = desc-\u003epage_prot;\n2812:\t\t/* User-defined fields. */\n2813:\t\tmap-\u003evm_ops = desc-\u003evm_ops;\n2814:\t\tmap-\u003evm_private_data = desc-\u003eprivate_data;\n2815:\t\n2816:\t\t/*\n2817:\t\t * MAP_PRIVATE-/dev/zero mappings are an ancient way of getting\n2818:\t\t * anonymous mappings. Rather than allowing these mappings to be odd\n2819:\t\t * outliers, simply make them truly anonymous.\n2820:\t\t */\n2821:\t\tif (map_is_private(map) \u0026\u0026 file_is_dev_zero(map-\u003efile))\n2822:\t\t\tmap_set_anon(map);\n2823:\t\n2824:\t\treturn 0;\n2825:\t}\n2826:\t\n2827:\tstatic void set_vma_user_defined_fields(struct vm_area_struct *vma,\n2828:\t\t\tstruct mmap_state *map)\n2829:\t{\n2830:\t\tvma-\u003evm_ops = map-\u003evm_ops;\n2831:\t\tvma-\u003evm_private_data = map-\u003evm_private_data;\n2832:\t}\n2833:\t\n2834:\t/*\n2835:\t * Are we guaranteed no driver can change state such as to preclude KSM merging?\n2836:\t * If so, let's set the KSM mergeable flag early so we don't break VMA merging.\n2837:\t */\n2838:\tstatic bool can_set_ksm_flags_early(struct mmap_state *map)\n2839:\t{\n2840:\t\tstruct file *file = map-\u003efile;\n2841:\t\n2842:\t\t/* Anonymous mappings have no driver which can change them. */\n2843:\t\tif (!file)\n2844:\t\t\treturn true;\n2845:\t\n2846:\t\t/*\n2847:\t\t * If .mmap_prepare() is specified, then the driver will have already\n2848:\t\t * manipulated state prior to updating KSM flags. So no need to worry\n2849:\t\t * about mmap callbacks modifying VMA flags after the KSM flag has been\n2850:\t\t * updated here, which could otherwise affect KSM eligibility.\n2851:\t\t */\n2852:\t\tif (file-\u003ef_op-\u003emmap_prepare)\n2853:\t\t\treturn true;\n2854:\t\n2855:\t\t/* shmem is safe. */\n2856:\t\tif (shmem_file(file))\n2857:\t\t\treturn true;\n2858:\t\n2859:\t\t/* Any other .mmap callback is not safe. */\n"
}

9/2 2026/09/08 13:26 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 14611
							output: 35
							thoughts: 14
						

Thoughts:
Here's a summary of my thought process, as if I were analyzing that code snippet:

**Diving Deeper into Memory Mapping**

Okay, so we're looking at `__mmap_region` again. My immediate thought is, let's not just isolate on that function, but broaden the scope slightly. To truly understand its purpose and potential implications, I need to see the context. So, I need to check the surrounding lines of code. What calls `__mmap_region`? What data does it operate on? What follows its execution? I'm thinking, are there any error checks, or related memory management operations in its vicinity? Are we dealing with allocation, deallocation, or simply modification of an existing mapping? A deeper dive around that specific function will give a much clearer picture. I'm after the bigger story.



10/2 2026/09/08 13:26 tool read-file
0m Args:
{
  "File": "mm/vma.c",
  "FirstLine": 2880,
  "LineCount": 50
}

Results:
{
  "Contents": "2880:\t\t};\n2881:\t\tbool allocated_new = false;\n2882:\t\tint error;\n2883:\t\n2884:\t\tmap.check_ksm_early = can_set_ksm_flags_early(\u0026map);\n2885:\t\n2886:\t\terror = __mmap_setup(\u0026map, \u0026desc, uf);\n2887:\t\tif (!error \u0026\u0026 have_mmap_prepare)\n2888:\t\t\terror = call_mmap_prepare(\u0026map, \u0026desc);\n2889:\t\tif (error)\n2890:\t\t\tgoto abort_munmap;\n2891:\t\n2892:\t\tif (map.check_ksm_early)\n2893:\t\t\tupdate_ksm_flags(\u0026map);\n2894:\t\n2895:\t\t/* Attempt to merge with adjacent VMAs... */\n2896:\t\tif (map.prev || map.next) {\n2897:\t\t\tVMG_MMAP_STATE(vmg, \u0026map, /* vma = */ NULL);\n2898:\t\n2899:\t\t\tvma = vma_merge_new_range(\u0026vmg);\n2900:\t\t}\n2901:\t\n2902:\t\t/* ...but if we can't, allocate a new VMA. */\n2903:\t\tif (!vma) {\n2904:\t\t\terror = __mmap_new_vma(\u0026map, \u0026vma, \u0026desc.action);\n2905:\t\t\tif (error)\n2906:\t\t\t\tgoto unacct_error;\n2907:\t\t\tallocated_new = true;\n2908:\t\t}\n2909:\t\n2910:\t\tif (have_mmap_prepare \u0026\u0026 !map_is_anon(\u0026map))\n2911:\t\t\tset_vma_user_defined_fields(vma, \u0026map);\n2912:\t\n2913:\t\t__mmap_complete(\u0026map, vma);\n2914:\t\n2915:\t\tif (have_mmap_prepare \u0026\u0026 allocated_new) {\n2916:\t\t\terror = mmap_action_complete(vma, \u0026desc.action,\n2917:\t\t\t\t\t\t     /*is_compat=*/false);\n2918:\t\t\tif (error)\n2919:\t\t\t\treturn error;\n2920:\t\t}\n2921:\t\n2922:\t\treturn addr;\n2923:\t\n2924:\t\t/* Accounting was done by __mmap_setup(). */\n2925:\tunacct_error:\n2926:\t\tif (map.charged)\n2927:\t\t\tvm_unacct_memory(map.charged);\n2928:\tabort_munmap:\n2929:\t\t/*\n"
}

11/2 2026/09/08 13:26 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 15563
							output: 18
							thoughts: 22
						

Thoughts:
Here's my summary, as though I were thinking through the process:

**Diving into `mmap_file`**

Alright, time to dig into this. I need to understand `mmap_file`, so I'll start by checking its definition in `mm/internal.h`. That's the logical starting point for understanding its purpose and parameters. From there, I'll need to trace its usage. I'll need to identify all the functions that *call* `mmap_file`. That's where the real clues will lie – seeing how it's used will give me the best insight into its intended behavior and interactions with other parts of the memory management subsystem. This is going to be about understanding the data flow and the context in which `mmap_file` operates. Knowing the callers is *key* to grasping its overall function.



12/2 2026/09/08 13:26 tool grepper
0m Args:
{
  "Expression": "mmap_file"
}

Results:
{
  "Output": "fs/9p/vfs_file.c-30-\nfs/9p/vfs_file.c:31:static const struct vm_operations_struct v9fs_mmap_file_vm_ops;\nfs/9p/vfs_file.c-32-\n--\nfs/9p/vfs_file.c=462=v9fs_file_mmap_prepare(struct vm_area_desc *desc)\n--\nfs/9p/vfs_file.c-477-\tif (!retval)\nfs/9p/vfs_file.c:478:\t\tdesc-\u003evm_ops = \u0026v9fs_mmap_file_vm_ops;\nfs/9p/vfs_file.c-479-\n--\nfs/9p/vfs_file.c=489=static void v9fs_mmap_vm_close(struct vm_area_struct *vma)\n--\nfs/9p/vfs_file.c-501-\nfs/9p/vfs_file.c:502:static const struct vm_operations_struct v9fs_mmap_file_vm_ops = {\nfs/9p/vfs_file.c-503-\t.close = v9fs_mmap_vm_close,\n--\nfs/backing-file.c=329=int backing_file_mmap(struct file *file, struct vm_area_struct *vma,\n--\nfs/backing-file.c-337-\nfs/backing-file.c:338:\tif (!can_mmap_file(file))\nfs/backing-file.c-339-\t\treturn -ENODEV;\n--\nfs/binfmt_elf.c=642=static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,\n--\nfs/binfmt_elf.c-660-\t\tgoto out;\nfs/binfmt_elf.c:661:\tif (!can_mmap_file(interpreter))\nfs/binfmt_elf.c-662-\t\tgoto out;\n--\nfs/binfmt_elf.c=829=static int load_elf_binary(struct linux_binprm *bprm)\n--\nfs/binfmt_elf.c-862-\t\tgoto out;\nfs/binfmt_elf.c:863:\tif (!can_mmap_file(bprm-\u003efile))\nfs/binfmt_elf.c-864-\t\tgoto out;\n--\nfs/binfmt_elf_fdpic.c=104=static int is_elf(struct elfhdr *hdr, struct file *file)\n--\nfs/binfmt_elf_fdpic.c-111-\t\treturn 0;\nfs/binfmt_elf_fdpic.c:112:\tif (!can_mmap_file(file))\nfs/binfmt_elf_fdpic.c-113-\t\treturn 0;\n--\nfs/coda/file.c=151=coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)\n--\nfs/coda/file.c-162-\nfs/coda/file.c:163:\tif (!can_mmap_file(host_file))\nfs/coda/file.c-164-\t\treturn -ENODEV;\n--\nfs/ecryptfs/file.c=186=static int ecryptfs_mmap(struct file *file, struct vm_area_struct *vma)\n--\nfs/ecryptfs/file.c-193-\t */\nfs/ecryptfs/file.c:194:\tif (!can_mmap_file(lower_file))\nfs/ecryptfs/file.c-195-\t\treturn -ENODEV;\n--\nfs/f2fs/f2fs.h=3635=static inline int f2fs_exist_data(struct inode *inode)\n--\nfs/f2fs/f2fs.h-3639-\nfs/f2fs/f2fs.h:3640:static inline int f2fs_is_mmap_file(struct inode *inode)\nfs/f2fs/f2fs.h-3641-{\n--\nfs/f2fs/f2fs.h=4871=static inline bool f2fs_disable_compressed_file(struct inode *inode)\n--\nfs/f2fs/f2fs.h-4880-\t}\nfs/f2fs/f2fs.h:4881:\tif (f2fs_is_mmap_file(inode) || atomic_read(\u0026fi-\u003ewriteback) ||\nfs/f2fs/f2fs.h-4882-\t\t(S_ISREG(inode-\u003ei_mode) \u0026\u0026 F2FS_HAS_BLOCKS(inode))) {\n--\nfs/f2fs/f2fs.h=5045=static inline bool f2fs_may_compress(struct inode *inode)\n--\nfs/f2fs/f2fs.h-5048-\t\tf2fs_is_atomic_file(inode) || f2fs_has_inline_data(inode) ||\nfs/f2fs/f2fs.h:5049:\t\tf2fs_is_mmap_file(inode))\nfs/f2fs/f2fs.h-5050-\t\treturn false;\n--\nfs/f2fs/file.c=4725=static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg)\n--\nfs/f2fs/file.c-4758-\nfs/f2fs/file.c:4759:\tif (f2fs_is_mmap_file(inode) || get_dirty_pages(inode)) {\nfs/f2fs/file.c-4760-\t\tret = -EBUSY;\n--\ninclude/linux/fs.h=1994=struct inode_operations {\n--\ninclude/linux/fs.h-2039-/* Did the driver provide valid mmap hook configuration? */\ninclude/linux/fs.h:2040:static inline bool can_mmap_file(struct file *file)\ninclude/linux/fs.h-2041-{\n--\ninclude/linux/lsm_hook_defs.h=201=LSM_HOOK(int, 0, mmap_addr, unsigned long addr)\ninclude/linux/lsm_hook_defs.h:202:LSM_HOOK(int, 0, mmap_file, struct file *file, unsigned long reqprot,\ninclude/linux/lsm_hook_defs.h-203-\t unsigned long prot, unsigned long flags)\n--\ninclude/linux/security.h=479=int security_file_ioctl_compat(struct file *file, unsigned int cmd,\ninclude/linux/security.h-480-\t\t\t       unsigned long arg);\ninclude/linux/security.h:481:int security_mmap_file(struct file *file, unsigned long prot,\ninclude/linux/security.h-482-\t\t\tunsigned long flags);\n--\ninclude/linux/security.h=1166=static inline int security_file_ioctl_compat(struct file *file,\n--\ninclude/linux/security.h-1172-\ninclude/linux/security.h:1173:static inline int security_mmap_file(struct file *file, unsigned long prot,\ninclude/linux/security.h-1174-\t\t\t\t     unsigned long flags)\n--\nipc/shm.c=1521=long do_shmat(int shmid, char __user *shmaddr, int shmflg,\n--\nipc/shm.c-1645-\nipc/shm.c:1646:\terr = security_mmap_file(file, prot, flags);\nipc/shm.c-1647-\tif (err)\n--\nkernel/bpf/bpf_lsm.c=345=BTF_ID(func, bpf_lsm_path_chown)\n--\nkernel/bpf/bpf_lsm.c-347-\nkernel/bpf/bpf_lsm.c:348:BTF_ID(func, bpf_lsm_mmap_file)\nkernel/bpf/bpf_lsm.c-349-BTF_ID(func, bpf_lsm_netlink_send)\n--\nkernel/bpf/bpf_lsm_proto.c-9-/*\nkernel/bpf/bpf_lsm_proto.c:10: * Strong definition of the mmap_file() BPF LSM hook. The __nullable suffix on\nkernel/bpf/bpf_lsm_proto.c-11- * the struct file pointer parameter name marks it as PTR_MAYBE_NULL. This\n--\nkernel/bpf/bpf_lsm_proto.c-14- */\nkernel/bpf/bpf_lsm_proto.c:15:int bpf_lsm_mmap_file(struct file *file__nullable, unsigned long reqprot,\nkernel/bpf/bpf_lsm_proto.c-16-\t\t      unsigned long prot, unsigned long flags)\n--\nmm/internal.h=219=static inline void *folio_raw_mapping(const struct folio *folio)\n--\nmm/internal.h-235- */\nmm/internal.h:236:static inline int mmap_file(struct file *file, struct vm_area_struct *vma)\nmm/internal.h-237-{\n--\nmm/mmap.c=338=unsigned long do_mmap(struct file *file, unsigned long addr,\n--\nmm/mmap.c-484-\nmm/mmap.c:485:\t\t\tif (!can_mmap_file(file))\nmm/mmap.c-486-\t\t\t\treturn -ENODEV;\n--\nmm/mmap.c=1101=SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,\n--\nmm/mmap.c-1157-\t/* Call outside mmap_lock to be consistent with other callers. */\nmm/mmap.c:1158:\tret = security_mmap_file(file, prot, flags);\nmm/mmap.c-1159-\tif (ret) {\n--\nmm/nommu.c=690=static int validate_mmap_request(struct file *file,\n--\nmm/nommu.c-722-\t\t/* files must support mmap */\nmm/nommu.c:723:\t\tif (!can_mmap_file(file))\nmm/nommu.c-724-\t\t\treturn -ENODEV;\n--\nmm/nommu.c=893=static int do_mmap_shared_file(struct vm_area_struct *vma)\n--\nmm/nommu.c-896-\nmm/nommu.c:897:\tret = mmap_file(vma-\u003evm_file, vma);\nmm/nommu.c-898-\tif (ret == 0) {\n--\nmm/nommu.c=914=static int do_mmap_private(struct vm_area_struct *vma,\n--\nmm/nommu.c-929-\tif (capabilities \u0026 NOMMU_MAP_DIRECT) {\nmm/nommu.c:930:\t\tret = mmap_file(vma-\u003evm_file, vma);\nmm/nommu.c-931-\t\t/* shouldn't return success if we're not sharing */\n--\nmm/util.c=565=unsigned long vm_mmap_pgoff(struct file *file, unsigned long addr,\n--\nmm/util.c-574-\nmm/util.c:575:\tret = security_mmap_file(file, prot, flag);\nmm/util.c-576-\tif (!ret)\n--\nmm/vma.c=2519=static int __mmap_setup(struct mmap_state *map, struct vm_area_desc *desc,\n--\nmm/vma.c-2571-\t * cannot race with the freeing later in the truncate scenario.\nmm/vma.c:2572:\t * This is also needed for mmap_file(), which is why vm_ops\nmm/vma.c-2573-\t * close function is called.\n--\nmm/vma.c=2582=static int __mmap_new_file_vma(struct mmap_state *map,\n--\nmm/vma.c-2594-\nmm/vma.c:2595:\terror = mmap_file(vma-\u003evm_file, vma);\nmm/vma.c-2596-\tif (error) {\n--\nscripts/recordmcount.c=151=static void * umalloc(size_t size)\n--\nscripts/recordmcount.c-175- */\nscripts/recordmcount.c:176:static void *mmap_file(char const *fname)\nscripts/recordmcount.c-177-{\n--\nscripts/recordmcount.c=511=static int do_file(char const *const fname)\n--\nscripts/recordmcount.c-516-\nscripts/recordmcount.c:517:\tehdr = mmap_file(fname);\nscripts/recordmcount.c-518-\tif (!ehdr)\n--\nsecurity/apparmor/lsm.c=561=static int common_mmap(const char *op, struct file *file, unsigned long prot,\n--\nsecurity/apparmor/lsm.c-582-\nsecurity/apparmor/lsm.c:583:static int apparmor_mmap_file(struct file *file, unsigned long reqprot,\nsecurity/apparmor/lsm.c-584-\t\t\t      unsigned long prot, unsigned long flags)\n--\nsecurity/apparmor/lsm.c=1767=static struct security_hook_list apparmor_hooks[] __ro_after_init = {\n--\nsecurity/apparmor/lsm.c-1794-\tLSM_HOOK_INIT(file_free_security, apparmor_file_free_security),\nsecurity/apparmor/lsm.c:1795:\tLSM_HOOK_INIT(mmap_file, apparmor_mmap_file),\nsecurity/apparmor/lsm.c-1796-\tLSM_HOOK_INIT(file_mprotect, apparmor_file_mprotect),\n--\nsecurity/integrity/ima/ima_main.c=106=static int mmap_violation_check(enum ima_hooks func, struct file *file,\n--\nsecurity/integrity/ima/ima_main.c-121-\t\tintegrity_audit_msg(AUDIT_INTEGRITY_DATA, inode, *pathname,\nsecurity/integrity/ima/ima_main.c:122:\t\t\t\t    \"mmap_file\", \"mmapped_writers\", rc, 0);\nsecurity/integrity/ima/ima_main.c-123-\t}\n--\nsecurity/integrity/ima/ima_main.c=1353=static struct security_hook_list ima_hooks[] __ro_after_init = {\n--\nsecurity/integrity/ima/ima_main.c-1359-\tLSM_HOOK_INIT(file_release, ima_file_free),\nsecurity/integrity/ima/ima_main.c:1360:\tLSM_HOOK_INIT(mmap_file, ima_file_mmap),\nsecurity/integrity/ima/ima_main.c-1361-\tLSM_HOOK_INIT(file_mprotect, ima_file_mprotect),\n--\nsecurity/ipe/hooks.c=53=int ipe_bprm_creds_for_exec(struct linux_binprm *bprm)\n--\nsecurity/ipe/hooks.c-65-/**\nsecurity/ipe/hooks.c:66: * ipe_mmap_file() - ipe security hook function for mmap check.\nsecurity/ipe/hooks.c-67- * @f: File being mmap'd. Can be NULL in the case of anonymous memory.\n--\nsecurity/ipe/hooks.c-79- */\nsecurity/ipe/hooks.c:80:int ipe_mmap_file(struct file *f, unsigned long reqprot __always_unused,\nsecurity/ipe/hooks.c-81-\t\t  unsigned long prot, unsigned long flags)\n--\nsecurity/ipe/hooks.h=28=int ipe_bprm_creds_for_exec(struct linux_binprm *bprm);\nsecurity/ipe/hooks.h-29-\nsecurity/ipe/hooks.h:30:int ipe_mmap_file(struct file *f, unsigned long reqprot, unsigned long prot,\nsecurity/ipe/hooks.h-31-\t\t  unsigned long flags);\n--\nsecurity/ipe/ipe.c=48=static struct security_hook_list ipe_hooks[] __ro_after_init = {\n--\nsecurity/ipe/ipe.c-50-\tLSM_HOOK_INIT(bprm_creds_for_exec, ipe_bprm_creds_for_exec),\nsecurity/ipe/ipe.c:51:\tLSM_HOOK_INIT(mmap_file, ipe_mmap_file),\nsecurity/ipe/ipe.c-52-\tLSM_HOOK_INIT(file_mprotect, ipe_file_mprotect),\n--\nsecurity/security.c=2534=static inline unsigned long mmap_prot(struct file *file, unsigned long prot)\n--\nsecurity/security.c-2567-/**\nsecurity/security.c:2568: * security_mmap_file() - Check if mmap'ing a file is allowed\nsecurity/security.c-2569- * @file: file\n--\nsecurity/security.c-2577- */\nsecurity/security.c:2578:int security_mmap_file(struct file *file, unsigned long prot,\nsecurity/security.c-2579-\t\t       unsigned long flags)\nsecurity/security.c-2580-{\nsecurity/security.c:2581:\treturn call_int_hook(mmap_file, file, prot, mmap_prot(file, prot),\nsecurity/security.c-2582-\t\t\t     flags);\n--\nsecurity/security.c-2591- * Check permissions for a mmap operation on a stacked filesystem.  This hook\nsecurity/security.c:2592: * is called after the security_mmap_file() and is responsible for authorizing\nsecurity/security.c-2593- * the mmap on @backing_file.  It is important to note that the mmap operation\n--\nsecurity/selinux/hooks.c=4027=static int selinux_mmap_addr(unsigned long addr)\n--\nsecurity/selinux/hooks.c-4039-\nsecurity/selinux/hooks.c:4040:static int selinux_mmap_file_common(struct file *file, unsigned long prot,\nsecurity/selinux/hooks.c-4041-\t\t\t\t    bool shared, bool mounter_check)\n--\nsecurity/selinux/hooks.c-4058-\nsecurity/selinux/hooks.c:4059:static int selinux_mmap_file(struct file *file,\nsecurity/selinux/hooks.c-4060-\t\t\t     unsigned long reqprot __always_unused,\n--\nsecurity/selinux/hooks.c-4062-{\nsecurity/selinux/hooks.c:4063:\treturn selinux_mmap_file_common(file, prot,\nsecurity/selinux/hooks.c-4064-\t\t\t\t\t(flags \u0026 MAP_TYPE) == MAP_SHARED,\n--\nsecurity/selinux/hooks.c-4073- *\nsecurity/selinux/hooks.c:4074: * This is called after selinux_mmap_file() on stacked filesystems, and it\nsecurity/selinux/hooks.c-4075- * is this function's responsibility to verify access to @backing_file and\n--\nsecurity/selinux/hooks.c=4083=static int selinux_mmap_backing_file(struct vm_area_struct *vma,\n--\nsecurity/selinux/hooks.c-4096-\nsecurity/selinux/hooks.c:4097:\treturn selinux_mmap_file_common(backing_file, prot,\nsecurity/selinux/hooks.c-4098-\t\t\t\t\tvma-\u003evm_flags \u0026 VM_SHARED,\n--\nsecurity/selinux/hooks.c=7560=static struct security_hook_list selinux_hooks[] __ro_after_init = {\n--\nsecurity/selinux/hooks.c-7639-\tLSM_HOOK_INIT(file_ioctl_compat, selinux_file_ioctl_compat),\nsecurity/selinux/hooks.c:7640:\tLSM_HOOK_INIT(mmap_file, selinux_mmap_file),\nsecurity/selinux/hooks.c-7641-\tLSM_HOOK_INIT(mmap_backing_file, selinux_mmap_backing_file),\n--\nsecurity/smack/smack_lsm.c=1801=static int smack_file_fcntl(struct file *file, unsigned int cmd,\n--\nsecurity/smack/smack_lsm.c-1835-/**\nsecurity/smack/smack_lsm.c:1836: * smack_mmap_file - Check permissions for a mmap operation.\nsecurity/smack/smack_lsm.c-1837- * @file: contains the file structure for file to map (may be NULL).\n--\nsecurity/smack/smack_lsm.c-1845- */\nsecurity/smack/smack_lsm.c:1846:static int smack_mmap_file(struct file *file,\nsecurity/smack/smack_lsm.c-1847-\t\t\t   unsigned long reqprot, unsigned long prot,\n--\nsecurity/smack/smack_lsm.c=5155=static struct security_hook_list smack_hooks[] __ro_after_init = {\n--\nsecurity/smack/smack_lsm.c-5198-\tLSM_HOOK_INIT(file_fcntl, smack_file_fcntl),\nsecurity/smack/smack_lsm.c:5199:\tLSM_HOOK_INIT(mmap_file, smack_mmap_file),\nsecurity/smack/smack_lsm.c-5200-\tLSM_HOOK_INIT(mmap_addr, cap_mmap_addr),\n--\ntools/perf/tests/perf-record.c=48=static int test__PERF_RECORD(struct test_suite *test __maybe_unused, int subtest __maybe_unused)\n--\ntools/perf/tests/perf-record.c-64-\tconst char *argv[] = { cmd, \"1\", NULL, };\ntools/perf/tests/perf-record.c:65:\tchar *bname, *mmap_filename;\ntools/perf/tests/perf-record.c-66-\tu64 prev_time = 0;\n--\ntools/perf/tests/perf-record.c-273-\t\t\t\tcase PERF_RECORD_MMAP:\ntools/perf/tests/perf-record.c:274:\t\t\t\t\tmmap_filename = event-\u003emmap.filename;\ntools/perf/tests/perf-record.c-275-\t\t\t\t\tgoto check_bname;\ntools/perf/tests/perf-record.c-276-\t\t\t\tcase PERF_RECORD_MMAP2:\ntools/perf/tests/perf-record.c:277:\t\t\t\t\tmmap_filename = event-\u003emmap2.filename;\ntools/perf/tests/perf-record.c-278-\t\t\t\tcheck_bname:\ntools/perf/tests/perf-record.c:279:\t\t\t\t\tbname = strrchr(mmap_filename, '/');\ntools/perf/tests/perf-record.c-280-\t\t\t\t\tif (bname != NULL) {\n--\ntools/perf/tests/perf-record.c-289-\t\t\t\t\t} else if (!found_vdso_mmap)\ntools/perf/tests/perf-record.c:290:\t\t\t\t\t\tfound_vdso_mmap = !strcmp(mmap_filename, \"[vdso]\");\ntools/perf/tests/perf-record.c-291-\t\t\t\t\tbreak;\n--\ntools/testing/selftests/bpf/progs/verifier_lsm.c=155=__naked int disabled_hook_test3(void *ctx)\n--\ntools/testing/selftests/bpf/progs/verifier_lsm.c-162-\ntools/testing/selftests/bpf/progs/verifier_lsm.c:163:SEC(\"lsm/mmap_file\")\ntools/testing/selftests/bpf/progs/verifier_lsm.c:164:__description(\"not null checking nullable pointer in bpf_lsm_mmap_file\")\ntools/testing/selftests/bpf/progs/verifier_lsm.c-165-__failure __msg(\"R1 invalid mem access 'trusted_ptr_or_null_'\")\ntools/testing/selftests/bpf/progs/verifier_lsm.c=166=int BPF_PROG(no_null_check, struct file *file)\n--\ntools/testing/selftests/bpf/progs/verifier_lsm.c-175-\ntools/testing/selftests/bpf/progs/verifier_lsm.c:176:SEC(\"lsm/mmap_file\")\ntools/testing/selftests/bpf/progs/verifier_lsm.c:177:__description(\"null checking nullable pointer in bpf_lsm_mmap_file\")\ntools/testing/selftests/bpf/progs/verifier_lsm.c-178-__success\n--\ntools/testing/vma/include/dup.h=1544=static inline int mapping_map_writable(struct address_space *mapping)\n--\ntools/testing/vma/include/dup.h-1550-/* Did the driver provide valid mmap hook configuration? */\ntools/testing/vma/include/dup.h:1551:static inline bool can_mmap_file(struct file *file)\ntools/testing/vma/include/dup.h-1552-{\n--\ntools/testing/vma/include/stubs.h=328=static inline void vma_close(struct vm_area_struct *vma)\n--\ntools/testing/vma/include/stubs.h-331-\ntools/testing/vma/include/stubs.h:332:static inline int mmap_file(struct file *file, struct vm_area_struct *vma)\ntools/testing/vma/include/stubs.h-333-{\n"
}

13/2 2026/09/08 13:27 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 22564
							output: 29
							thoughts: 804
						

Thoughts:
**Diving into the mmap Implementation Details**

Alright, let's trace this `can_mmap_file` business. My first thought is to see where `mmap_file` and `mmap_zero_prepare` are actually being used. It looks like `mm/vma.c` is the place to start. Specifically, `__mmap_new_file_vma` calls `mmap_file` with the `vma->vm_file` and the vma itself. Then, I remember `mmap_zero_prepare` is defined in `mm/char-mem.c` as the `zero_fops.mmap_prepare` function.

I need to understand how the kernel recognizes /dev/zero. I’ll check `file_is_dev_zero` in `mm/char-mem.c`. Looks straightforward: it just verifies if the file operation (`f_op`) matches `&zero_fops`.

Now, let's dig into `mmap_zero_prepare` itself. In `mm/char-mem.c`, if it’s a shared VMA (`VMA_SHARED_BIT` set) then `shmem_zero_setup_desc` does the work, otherwise, in a private mapping case, it just returns. That makes sense; the core MM takes care of private semantics.

Okay, let's step up a level to `mm/vma.c` and look at `call_mmap_prepare`. This is the core mmap prepare function and it's calling `vfs_mmap_prepare`. That's where file system specific things are handled. It's also making sure `vm_ops` is still valid and then calls some action prepare function. If the mapping is a private `/dev/zero` mapping (which is an ancient way of making anonymous mappings), it's converted to a truly anonymous mapping using `map_set_anon`. Smart!

Time to look at the build environment. I need to make sure there aren't any weird config dependencies for `mm/char-mem.c` or the `/dev/zero` functionality. Looking in `mm/Makefile`, `char-mem.o` is always built (`obj-y`). And, given that I'm on amd64, `CONFIG_MMU` is a given, so that's not the issue. I'll take a quick scan of `mm/char-mem.c` to be completely sure.



14/2 2026/09/08 13:27 tool grepper
0m Args:
{
  "Expression": "CONFIG_",
  "PathPrefix": "mm/char-mem.c"
}

Results:
{
  "Output": "mm/char-mem.c=55=static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)\n--\nmm/char-mem.c-60-\nmm/char-mem.c:61:#ifdef CONFIG_STRICT_DEVMEM\nmm/char-mem.c-62-static inline int page_is_allowed(unsigned long pfn)\n--\nmm/char-mem.c=271=static pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,\n--\nmm/char-mem.c-283-\nmm/char-mem.c:284:#ifndef CONFIG_MMU\nmm/char-mem.c-285-static unsigned long get_unmapped_area_mem(struct file *file,\n--\nmm/char-mem.c=321=static const struct vm_operations_struct mmap_mem_ops = {\nmm/char-mem.c:322:#ifdef CONFIG_HAVE_IOREMAP_PROT\nmm/char-mem.c-323-\t.access = generic_access_phys\n--\nmm/char-mem.c=327=static int mmap_mem_prepare(struct vm_area_desc *desc)\n--\nmm/char-mem.c-366-\nmm/char-mem.c:367:#ifdef CONFIG_DEVPORT\nmm/char-mem.c-368-static ssize_t read_port(struct file *file, char __user *buf,\n--\nmm/char-mem.c=503=static int mmap_zero_prepare(struct vm_area_desc *desc)\nmm/char-mem.c-504-{\nmm/char-mem.c:505:#ifndef CONFIG_MMU\nmm/char-mem.c-506-\treturn -ENOSYS;\n--\nmm/char-mem.c-514-\nmm/char-mem.c:515:#ifndef CONFIG_MMU\nmm/char-mem.c-516-static unsigned long get_unmapped_area_zero(struct file *file,\n--\nmm/char-mem.c=523=static unsigned long get_unmapped_area_zero(struct file *file,\n--\nmm/char-mem.c-542-\t */\nmm/char-mem.c:543:#ifdef CONFIG_TRANSPARENT_HUGEPAGE\nmm/char-mem.c-544-\treturn thp_get_unmapped_area(file, addr, len, pgoff, flags);\n--\nmm/char-mem.c-548-}\nmm/char-mem.c:549:#endif /* CONFIG_MMU */\nmm/char-mem.c-550-\n--\nmm/char-mem.c=632=static const struct file_operations __maybe_unused mem_fops = {\n--\nmm/char-mem.c-637-\t.open\t\t= open_mem,\nmm/char-mem.c:638:#ifndef CONFIG_MMU\nmm/char-mem.c-639-\t.get_unmapped_area = get_unmapped_area_mem,\n--\nmm/char-mem.c=645=static const struct file_operations null_fops = {\n--\nmm/char-mem.c-654-\nmm/char-mem.c:655:#ifdef CONFIG_DEVPORT\nmm/char-mem.c-656-static const struct file_operations port_fops = {\n--\nmm/char-mem.c=664=static const struct file_operations zero_fops = {\n--\nmm/char-mem.c-673-\t.get_unmapped_area = get_unmapped_area_zero,\nmm/char-mem.c:674:#ifndef CONFIG_MMU\nmm/char-mem.c-675-\t.mmap_capabilities = zero_mmap_capabilities,\n--\nmm/char-mem.c=686=static const struct memdev {\n--\nmm/char-mem.c-691-} devlist[] = {\nmm/char-mem.c:692:#ifdef CONFIG_DEVMEM\nmm/char-mem.c-693-\t[DEVMEM_MINOR] = { \"mem\", \u0026mem_fops, 0, 0 },\n--\nmm/char-mem.c-695-\t[3] = { \"null\", \u0026null_fops, FMODE_NOWAIT, 0666 },\nmm/char-mem.c:696:#ifdef CONFIG_DEVPORT\nmm/char-mem.c-697-\t[4] = { \"port\", \u0026port_fops, 0, 0 },\n--\nmm/char-mem.c-702-\t[9] = { \"urandom\", \u0026urandom_fops, FMODE_NOWAIT, 0666 },\nmm/char-mem.c:703:#ifdef CONFIG_PRINTK\nmm/char-mem.c-704-\t[11] = { \"kmsg\", \u0026kmsg_fops, 0, 0644 },\n"
}

15/2 2026/09/08 13:27 llm patch-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 25215
							output: 135
							thoughts: 960
						

Thoughts:
**Focus Symbol Selection for /dev/zero Private Mapping Handling**

Okay, so I've been digging into this patch series for the /dev/zero handling, specifically the private mapping implementation. First things first, `/dev/zero` is minor 5, which doesn't seem to need any special configuration – standard `CONFIG_MMU` is all that's required.

Now, let's get into those FocusSymbols rules. I need to avoid those ubiquitous lifecycle hot-paths; things that get called by *everything* are a fuzzing distraction. Instead, I need to pinpoint the *specific* feature logic and entry points. Static inline functions are a bit trickier, but the goal is to identify their non-static callers.

Looking at the code, I've identified a few key functions that seem promising: `file_is_dev_zero` (in `mm/char-mem.c`), `mmap_zero_prepare` (also in `mm/char-mem.c`), `call_mmap_prepare` (in `mm/vma.c`), `__mmap_new_vma` (in `mm/vma.c`), and `__mmap_region` (in `mm/vma.c`).

Let's drill down:

*   `mmap_zero_prepare`: Yes, this is *exactly* the mmap preparation for /dev/zero, so it is a good focus symbol.
*   `file_is_dev_zero`: This function is *explicitly* checking if the file is /dev/zero, which is important for the path that we are reviewing.
*   `call_mmap_prepare`: This is the function where the `file_is_dev_zero()` check and the `map_set_anon()` is executed. It is also where the `!desc->vm_ops` error check is added.

I initially considered `__mmap_new_vma` and `__mmap_region`. But `__mmap_new_vma` is altered to use `map_is_anon(map)`. And while I'm a bit hesitant about `__mmap_region`, the prior functions are quite specific, so let's stick with them.

Therefore, for the fuzzing focus, my shortlist is `["file_is_dev_zero", "mmap_zero_prepare", "call_mmap_prepare"]`. These are all very specific to the /dev/zero mmap change.

Now, let's quickly tick off the remaining requirements:

1.  `WorthFuzzing`: Absolutely. The patch *directly* modifies executable code in `mm/vma.c` and `mm/char-mem.c`.
2.  `Reasoning`: The patch *moves* handling of `/dev/zero` `MAP_PRIVATE` mappings into the core memory management. It converts these private mappings into true anonymous mappings during `mmap_prepare`, so logic is being shifted between different parts of the mm layer. This involves changes in `mm/vma.c`, `mm/char-mem.c`, and internal VMA management.
3.  `FocusSymbols`: I've already nailed these down as `["file_is_dev_zero", "mmap_zero_prepare", "call_mmap_prepare"]`.
4.  `EnableConfigs`: `[]` or `["MMU"]` – `CONFIG_MMU` is standard, so no special configuration is needed.

I've given this a final once-over, and I'm confident that these are accurate, so I'm ready to invoke `set-results`.



16/2 2026/09/08 13:27 tool set-results
0m Args:
{
  "EnableConfigs": [
    "MMU"
  ],
  "FocusSymbols": [
    "call_mmap_prepare",
    "file_is_dev_zero",
    "mmap_zero_prepare"
  ],
  "Reasoning": "The patch refactors the handling of MAP_PRIVATE /dev/zero mappings so they become truly anonymous mappings within core mm rather than being treated as semi-anonymous file mappings. It modifies reachable logic in mm/vma.c, mm/char-mem.c, and header helpers, affecting VMA merging, page offset calculations, and mmap preparation.",
  "WorthFuzzing": true
}

Results:
{
  "EnableConfigs": [
    "MMU"
  ],
  "FocusSymbols": [
    "call_mmap_prepare",
    "file_is_dev_zero",
    "mmap_zero_prepare"
  ],
  "Reasoning": "The patch refactors the handling of MAP_PRIVATE /dev/zero mappings so they become truly anonymous mappings within core mm rather than being treated as semi-anonymous file mappings. It modifies reachable logic in mm/vma.c, mm/char-mem.c, and header helpers, affecting VMA merging, page offset calculations, and mmap preparation.",
  "WorthFuzzing": true
}

17/1 2026/09/08 13:27 action If
0m Args:
{
  "WorthFuzzing": true
}

Results:
null

18/2 2026/09/08 13:27 agent kmsan-evaluator
0m Model:
core

Args:
null

Results:
{
  "KMSANReasoning": "The patch series refactors the handling of MAP_PRIVATE /dev/zero mappings to make them truly anonymous VMAs within the core memory management subsystem (moving drivers/char/mem.c to mm/char-mem.c, updating mmap_prepare handling, and removing special-case workarounds for semi-anonymous VMAs).\n\nKMSAN vs. KASAN applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce or alter kernel-to-user copies, uninitialized buffer reads, or conditional branches on uninitialized data. All structures (e.g. struct vm_area_desc) are fully initialized before use.\n- Any bugs stemming from this refactoring (e.g. VMA merging discrepancies, page offset errors, or reference/lifetime management issues) are memory management/logic issues that would manifest as use-after-free or memory corruption, which are covered by KASAN and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Instruction:
You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.

CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
  a comprehensive suite of debugging tools and sanitizers, including KASAN
  (out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
  (locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
  or page allocations) and kernel-to-user memory info-leaks.

Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.

Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.

Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
   attributes, ioctl output arguments, socket options, or BPF buffers) where fields
   or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
   or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
   could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
   uninitialized bytes of existing buffers.

Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
  dereferences, locking deadlocks, or use-after-free bugs (these are already caught
  by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
  or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.

Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.


Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.

Prompt:
Target architecture: amd64

For your convenience, here is the diff of the changes:
commit 86396586e98d580888c81aef7f2d6b03669a4554
Author: syz-cluster <triage@syzkaller.com>
Date:   Tue Sep 8 13:26:38 2026 +0000

    syz-cluster: applied patch under review

diff --git a/MAINTAINERS b/MAINTAINERS
index 3a19da74d00c9..a0a5db444c663 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -17276,7 +17276,7 @@ F:	Documentation/ABI/testing/sysfs-kernel-mm-memory-tiers
 F:	Documentation/ABI/testing/sysfs-kernel-mm-numa
 F:	Documentation/admin-guide/mm/
 F:	Documentation/mm/
-F:	drivers/char/mem.c
+F:	mm/char-mem.c
 F:	include/linux/cma.h
 F:	include/linux/dmapool.h
 F:	include/linux/ioremap.h
@@ -17481,7 +17481,7 @@ L:	linux-mm@kvack.org
 S:	Maintained
 W:	http://www.linux-mm.org
 T:	git git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
-F:	drivers/char/mem.c
+F:	mm/char-mem.c
 F:	include/trace/events/mmap.h
 F:	fs/proc/task_mmu.c
 F:	fs/proc/task_nommu.c
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index a46d7bf7c4c82..bb3bf66937b37 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -3,7 +3,7 @@
 # Makefile for the kernel character device drivers.
 #
 
-obj-y				+= mem.o random.o
+obj-y				+= random.o
 obj-$(CONFIG_TTY_PRINTK)	+= ttyprintk.o
 obj-y				+= misc.o
 obj-$(CONFIG_TEST_MISC_MINOR)	+= misc_minor_kunit.o
diff --git a/include/linux/mm.h b/include/linux/mm.h
index dd09c438fa23e..864d5ac3704df 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -1551,11 +1551,6 @@ static inline void vma_set_anonymous(struct vm_area_struct *vma)
 	vma->vm_ops = NULL;
 }
 
-static inline void vma_desc_set_anonymous(struct vm_area_desc *desc)
-{
-	desc->vm_ops = NULL;
-}
-
 static inline bool vma_is_anonymous(const struct vm_area_struct *vma)
 {
 	return !vma->vm_ops;
@@ -4408,9 +4403,8 @@ static inline unsigned long vma_pages(const struct vm_area_struct *vma)
  * If @vma is a MAP_PRIVATE file-backed mapping, then this returns the
  * page offset within the file.
  *
- * Edge cases: nommu does not abide by these, MAP_PRIVATE-/dev/zero satisfies
- * vma_is_anonymous() but has file-backed page offset, and MAP_PRIVATE-pfnmap
- * regions have their page offset set to the first PFN in the range.
+ * Edge cases: nommu does not abide by these and CoW MAP_PRIVATE-pfnmap regions
+ * have their page offset set to the first PFN in the range.
  *
  * Returns: The page offset of the start of @vma.
  */
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 0adfa6605653d..939f3a5e973f6 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1128,8 +1128,7 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,
 	const pgoff_t pgoff = __linear_anon_page_index(vma, address);
 
 	VM_WARN_ON_ONCE(!vma_is_cow_mapping(vma));
-	/* Account for MAP_PRIVATE-/dev/zero which is only semi-anonymous. */
-	if (vma_is_anonymous(vma) && !vma->vm_file)
+	if (vma_is_anonymous(vma))
 		VM_WARN_ON_ONCE(pgoff != linear_page_index(vma, address));
 
 	return pgoff;
diff --git a/mm/Makefile b/mm/Makefile
index e7245cb88c665..2a3ec53d62eef 100644
--- a/mm/Makefile
+++ b/mm/Makefile
@@ -55,7 +55,8 @@ obj-y			:= filemap.o mempool.o oom_kill.o fadvise.o \
 			   mm_init.o percpu.o slab_common.o \
 			   compaction.o show_mem.o \
 			   interval_tree.o list_lru.o workingset.o \
-			   debug.o gup.o mmap_lock.o vma_init.o $(mmu-y)
+			   debug.o gup.o mmap_lock.o vma_init.o char-mem.o \
+			   $(mmu-y)
 
 # Give 'page_alloc' its own module-parameter namespace
 page-alloc-y := page_alloc.o
diff --git a/drivers/char/mem.c b/mm/char-mem.c
similarity index 97%
rename from drivers/char/mem.c
rename to mm/char-mem.c
index 63253d1de5d70..c0b5fb019223c 100644
--- a/drivers/char/mem.c
+++ b/mm/char-mem.c
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
- *  linux/drivers/char/mem.c
+ *  mm/char-mem.c
  *
  *  Copyright (C) 1991, 1992  Linus Torvalds
  *
@@ -31,6 +31,8 @@
 #include <linux/uaccess.h>
 #include <linux/security.h>
 
+#include "internal.h"
+
 #define DEVMEM_MINOR	1
 #define DEVPORT_MINOR	4
 
@@ -506,11 +508,7 @@ static int mmap_zero_prepare(struct vm_area_desc *desc)
 	if (vma_desc_test(desc, VMA_SHARED_BIT))
 		return shmem_zero_setup_desc(desc);
 
-	/*
-	 * This is a highly unique situation where we mark a MAP_PRIVATE mapping
-	 * of /dev/zero anonymous, despite it not being.
-	 */
-	vma_desc_set_anonymous(desc);
+	/* MAP_PRIVATE semantics are taken care of for us by core mm. */
 	return 0;
 }
 
@@ -707,6 +705,17 @@ static const struct memdev {
 #endif
 };
 
+/**
+ * file_is_dev_zero() - is the specified @file associated with the /dev/zero
+ * driver?
+ * @file: File to test.
+ * Returns: true if it is, false otherwise.
+ */
+bool file_is_dev_zero(const struct file *file)
+{
+	return file && file->f_op == &zero_fops;
+}
+
 static int memory_open(struct inode *inode, struct file *filp)
 {
 	int minor;
diff --git a/mm/internal.h b/mm/internal.h
index 38b1165212c94..2782924a277c9 100644
--- a/mm/internal.h
+++ b/mm/internal.h
@@ -237,15 +237,18 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma)
 {
 	int err = vfs_mmap(file, vma);
 
-	if (likely(!err))
-		return 0;
-
 	/*
-	 * OK, we tried to call the file hook for mmap(), but an error
-	 * arose. The mapping is in an inconsistent state and we must not invoke
-	 * any further hooks on it.
+	 * Either we tried to call the file hook for mmap() and an error arose
+	 * or a driver set vma->vm_ops = NULL intending there to be no VMA
+	 * operations.
+	 *
+	 * In the former case the VMA is in an inconsistent state and we mustn't
+	 * invoke any further hooks on it, in the latter case the hook actually
+	 * wanted no further hooks to be invoked, so fix both by setting dummy
+	 * VMA ops.
 	 */
-	vma->vm_ops = &vma_dummy_vm_ops;
+	if (unlikely(err || !vma->vm_ops))
+		vma->vm_ops = &vma_dummy_vm_ops;
 
 	return err;
 }
@@ -1654,4 +1657,7 @@ static inline bool can_spin_trylock(void)
 	return true;
 }
 
+/* char-mem.c */
+bool file_is_dev_zero(const struct file *file);
+
 #endif	/* __MM_INTERNAL_H */
diff --git a/mm/shmem.c b/mm/shmem.c
index 897fa2b61346f..c60763ef561cf 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -2786,7 +2786,7 @@ unsigned long shmem_get_unmapped_area(struct file *file,
 			sb = file_inode(file)->i_sb;
 		} else {
 			/*
-			 * Called directly from mm/mmap.c, or drivers/char/mem.c
+			 * Called directly from mm/mmap.c, or mm/char-mem.c
 			 * for "/dev/zero", to create a shared anonymous object.
 			 */
 			if (IS_ERR(shm_mnt))
diff --git a/mm/vma.c b/mm/vma.c
index 35e7a64855fad..6fdce4852ce61 100644
--- a/mm/vma.c
+++ b/mm/vma.c
@@ -2621,6 +2621,23 @@ static int __mmap_new_file_vma(struct mmap_state *map,
 	return 0;
 }
 
+static void map_set_anon(struct mmap_state *map)
+{
+	map->file = NULL;
+	map->vm_ops = NULL;
+	map->pgoff = map->addr >> PAGE_SHIFT;
+}
+
+static bool map_is_private(const struct mmap_state *map)
+{
+	return !vma_flags_test(&map->vma_flags, VMA_SHARED_BIT);
+}
+
+static bool map_is_anon(const struct mmap_state *map)
+{
+	return map_is_private(map) && !map->file;
+}
+
 /*
  * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not
  * possible.
@@ -2634,8 +2651,7 @@ static int __mmap_new_file_vma(struct mmap_state *map,
 static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap,
 	struct mmap_action *action)
 {
-	const bool is_anon = !map->file &&
-		!vma_flags_test(&map->vma_flags, VMA_SHARED_BIT);
+	const bool is_anon = map_is_anon(map);
 	struct vma_iterator *vmi = map->vmi;
 	int error = 0;
 	struct vm_area_struct *vma;
@@ -2777,6 +2793,10 @@ static int call_mmap_prepare(struct mmap_state *map,
 	if (err)
 		return err;
 
+	/* It's invalid for mmap_preprare hooks to clear vm_ops. */
+	if (!desc->vm_ops)
+		return -EINVAL;
+
 	err = call_action_prepare(map, desc);
 	if (err)
 		return err;
@@ -2793,16 +2813,21 @@ static int call_mmap_prepare(struct mmap_state *map,
 	map->vm_ops = desc->vm_ops;
 	map->vm_private_data = desc->private_data;
 
+	/*
+	 * MAP_PRIVATE-/dev/zero mappings are an ancient way of getting
+	 * anonymous mappings. Rather than allowing these mappings to be odd
+	 * outliers, simply make them truly anonymous.
+	 */
+	if (map_is_private(map) && file_is_dev_zero(map->file))
+		map_set_anon(map);
+
 	return 0;
 }
 
 static void set_vma_user_defined_fields(struct vm_area_struct *vma,
 		struct mmap_state *map)
 {
-	if (map->vm_ops)
-		vma->vm_ops = map->vm_ops;
-	else	/* Only /dev/zero should do this. */
-		vma_set_anonymous(vma);
+	vma->vm_ops = map->vm_ops;
 	vma->vm_private_data = map->vm_private_data;
 }
 
@@ -2882,7 +2907,7 @@ static unsigned long __mmap_region(struct file *file, unsigned long addr,
 		allocated_new = true;
 	}
 
-	if (have_mmap_prepare)
+	if (have_mmap_prepare && !map_is_anon(&map))
 		set_vma_user_defined_fields(vma, &map);
 
 	__mmap_complete(&map, vma);
diff --git a/mm/vma.h b/mm/vma.h
index 024fabe63560a..e97bd2dfa786d 100644
--- a/mm/vma.h
+++ b/mm/vma.h
@@ -267,9 +267,6 @@ static inline void assert_sane_pgoff(struct vm_area_struct *vma, pgoff_t pgoff)
 	 */
 	if (!vma_is_anonymous(vma))
 		return;
-	/* MAP_PRIVATE-/dev/zero is anon, non-NULL vm_file, but has file pgoff. */
-	if (vma->vm_file)
-		return;
 	/* If faulted in, could have been remapped. */
 	if (vma->anon_vma)
 		return;
diff --git a/tools/testing/selftests/mm/merge.c b/tools/testing/selftests/mm/merge.c
index 52b8727b6628e..7dd2933417c1d 100644
--- a/tools/testing/selftests/mm/merge.c
+++ b/tools/testing/selftests/mm/merge.c
@@ -1362,6 +1362,101 @@ TEST_F(merge, anon_and_page_offset_mismatch_memfd)
 	ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr + 5 * page_size);
 }
 
+TEST_F(merge, merge_map_private_dev_zero_unfaulted)
+{
+	struct procmap_fd *procmap = &self->procmap;
+	unsigned int page_size = self->page_size;
+	char *carveout = self->carveout;
+	char *ptr, *ptr2;
+	int fd_zero;
+
+	if (access("/dev/zero", F_OK))
+		SKIP(return, "No /dev/zero.");
+	fd_zero = open("/dev/zero", O_RDWR);
+	ASSERT_NE(fd_zero, -1);
+
+	/*
+	 * Map two MAP_PRIVATE-/dev/zero VMAs next to one another with offset 0
+	 * each.
+	 *
+	 * With these being made truly anonymous upon mapping, they will
+	 * merge. If they were file-backed VMAs the page offsets would prevent
+	 * the merge:
+	 *
+	 * |-----||------|    |-------------|
+	 * | ptr || ptr2 | -> |     ptr     |
+	 * |-----||------|    |-------------|
+	 */
+	ptr = mmap(carveout, 5 * page_size, PROT_READ | PROT_WRITE,
+		   MAP_FIXED | MAP_PRIVATE, fd_zero, 0);
+	ptr2 = mmap(&carveout[5 * page_size], 5 * page_size,
+		   PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE, fd_zero, 0);
+	close(fd_zero);
+	ASSERT_NE(ptr, MAP_FAILED);
+	ASSERT_NE(ptr2, MAP_FAILED);
+
+	/* Assert that they merged. */
+	ASSERT_TRUE(find_vma_procmap(procmap, ptr));
+	ASSERT_EQ(procmap->query.vma_start, (unsigned long)ptr);
+	ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr + 10 * page_size);
+}
+
+TEST_F(merge, merge_map_private_dev_zero_faulted_unfaulted)
+{
+	struct procmap_fd *procmap = &self->procmap;
+	unsigned int page_size = self->page_size;
+	char *carveout = self->carveout;
+	char *ptr, *ptr2;
+	int fd_zero;
+
+	if (access("/dev/zero", F_OK))
+		SKIP(return, "No /dev/zero.");
+	fd_zero = open("/dev/zero", O_RDWR);
+	ASSERT_NE(fd_zero, -1);
+
+	/*
+	 * Map a MAP_PRIVATE mapping of /dev/zero with page offset 0, then fault
+	 * it in:
+	 *
+	 * |-------------------------------|
+	 * |           faulted             |
+	 * |-------------------------------|
+	 */
+	ptr = mmap(carveout, 15 * page_size, PROT_READ | PROT_WRITE,
+		   MAP_FIXED | MAP_PRIVATE, fd_zero, 0);
+	ASSERT_NE(ptr, MAP_FAILED);
+	memset(ptr, 'x', 15 * page_size);
+
+	/*
+	 * Unmap the middle:
+	 *
+	 * |---------|           |---------|
+	 * | faulted |           | faulted |
+	 * |---------|           |---------|
+	 */
+	ASSERT_EQ(munmap(&ptr[5 * page_size], 5 * page_size), 0);
+
+	/*
+	 * Map in a new unfaulted mapping in the middle with page offset 0 -
+	 * this should merge and would not if it were treated as a file rather
+	 * than pure anon:
+	 *
+	 * |---------|-----------|---------|
+	 * | faulted | unfaulted | faulted |
+	 * |---------|-----------|---------|
+	 */
+	ptr2 = mmap(&carveout[5 * page_size], 5 * page_size,
+		    PROT_READ | PROT_WRITE, MAP_FIXED | MAP_PRIVATE,
+		    fd_zero, 0);
+	close(fd_zero);
+	ASSERT_NE(ptr2, MAP_FAILED);
+
+	/* Assert that they merged. */
+	ASSERT_TRUE(find_vma_procmap(procmap, ptr));
+	ASSERT_EQ(procmap->query.vma_start, (unsigned long)ptr);
+	ASSERT_EQ(procmap->query.vma_end, (unsigned long)ptr + 15 * page_size);
+}
+
 TEST_F(merge_with_fork, mremap_faulted_to_unfaulted_prev)
 {
 	struct procmap_fd *procmap = &self->procmap;
diff --git a/tools/testing/selftests/proc/proc-self-map-files-001.c b/tools/testing/selftests/proc/proc-self-map-files-001.c
index 4209c64283d6f..bbca9f9e27439 100644
--- a/tools/testing/selftests/proc/proc-self-map-files-001.c
+++ b/tools/testing/selftests/proc/proc-self-map-files-001.c
@@ -51,7 +51,7 @@ int main(void)
 	int fd;
 	unsigned long a, b;
 
-	fd = open("/dev/zero", O_RDONLY);
+	fd = open("/proc/self/exe", O_RDONLY);
 	if (fd == -1)
 		return 1;
 
diff --git a/tools/testing/selftests/proc/proc-self-map-files-002.c b/tools/testing/selftests/proc/proc-self-map-files-002.c
index e6aa00a183bcd..5786cdffbbf63 100644
--- a/tools/testing/selftests/proc/proc-self-map-files-002.c
+++ b/tools/testing/selftests/proc/proc-self-map-files-002.c
@@ -57,7 +57,7 @@ int main(void)
 	int fd;
 	unsigned long a, b;
 
-	fd = open("/dev/zero", O_RDONLY);
+	fd = open("/proc/self/exe", O_RDONLY);
 	if (fd == -1)
 		return 1;
 
diff --git a/tools/testing/vma/include/dup.h b/tools/testing/vma/include/dup.h
index 4c58487b764e9..5669081d91b9f 100644
--- a/tools/testing/vma/include/dup.h
+++ b/tools/testing/vma/include/dup.h
@@ -1638,9 +1638,15 @@ static inline pgoff_t linear_anon_page_index(const struct vm_area_struct *vma,
 	const pgoff_t pgoff = __linear_anon_page_index(vma, address);
 
 	VM_WARN_ON_ONCE(!vma_is_cow_mapping(vma));
-	/* Account for MAP_PRIVATE-/dev/zero which is only semi-anonymous. */
-	if (vma_is_anonymous(vma) && !vma->vm_file)
+	if (vma_is_anonymous(vma))
 		VM_WARN_ON_ONCE(pgoff != linear_page_index(vma, address));
 
 	return pgoff;
 }
+
+extern const struct file_operations zero_fops;
+
+static inline bool file_is_dev_zero(const struct file *file)
+{
+	return file && file->f_op == &zero_fops;
+}
diff --git a/tools/testing/vma/shared.c b/tools/testing/vma/shared.c
index 4a39c9d504896..8c4826499f405 100644
--- a/tools/testing/vma/shared.c
+++ b/tools/testing/vma/shared.c
@@ -12,6 +12,15 @@ const struct vm_operations_struct vma_dummy_vm_ops;
 struct anon_vma dummy_anon_vma;
 struct task_struct __current;
 
+static int mmap_zero_prepare(struct vm_area_desc *desc)
+{
+	return 0;
+}
+
+const struct file_operations zero_fops = {
+	.mmap_prepare = mmap_zero_prepare,
+};
+
 struct vm_area_struct *alloc_vma(struct mm_struct *mm,
 		unsigned long start, unsigned long end,
 		pgoff_t pgoff, vma_flags_t vma_flags)
diff --git a/tools/testing/vma/tests/mmap.c b/tools/testing/vma/tests/mmap.c
index c85bc000d1cb7..fa73faff22626 100644
--- a/tools/testing/vma/tests/mmap.c
+++ b/tools/testing/vma/tests/mmap.c
@@ -45,7 +45,44 @@ static bool test_mmap_region_basic(void)
 	return true;
 }
 
+static bool test_pure_anon_dev_zero(void)
+{
+	const vma_flags_t vma_flags = mk_vma_flags(VMA_READ_BIT, VMA_WRITE_BIT,
+			VMA_MAYREAD_BIT, VMA_MAYWRITE_BIT);
+	struct file file = {
+		.f_op = &zero_fops,
+	};
+	struct mm_struct mm = {};
+	struct vm_area_struct *vma;
+	unsigned long addr;
+	VMA_ITERATOR(vmi, &mm, 0);
+
+	current->mm = &mm;
+
+	/*
+	 * Map a MAP_PRIVATE-/dev/zero mapping at address 0x300000 with a page
+	 * offset of 0x10, which we expect to be reset to the anonymous page
+	 * offset.
+	 */
+	addr = __mmap_region(&file, 0x300000, 0x3000, vma_flags, 0x10, NULL);
+	ASSERT_EQ(addr, 0x300000);
+
+	/* Assert that it truly is an anonymous mapping. */
+	vma = vma_lookup(&mm, addr);
+	ASSERT_NE(vma, NULL);
+	ASSERT_TRUE(vma_is_anonymous(vma));
+	ASSERT_EQ(vma->vm_file, NULL);
+	ASSERT_EQ(vma->vm_private_data, NULL);
+	/* Expect anonymous page offsets. */
+	ASSERT_EQ(vma->vm_pgoff, 0x300);
+	ASSERT_EQ(vma_start_anon_pgoff(vma), 0x300);
+
+	cleanup_mm(&mm, &vmi);
+	return true;
+}
+
 static void run_mmap_tests(int *num_tests, int *num_fail)
 {
 	TEST(mmap_region_basic);
+	TEST(pure_anon_dev_zero);
 }

19/3 2026/09/08 13:27 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 8961
							output: 28
							thoughts: 936
						

Thoughts:
**KMSAN Fuzzing Session Assessment**

Okay, let's break down this patch and see if we need to fire up a dedicated KMSAN fuzzing session. First, I need to understand the changes. It looks like we're primarily dealing with a refactor, moving `drivers/char/mem.c` to `mm/char-mem.c`. That's not the critical part here. The meat of the change revolves around how `/dev/zero` MAP_PRIVATE mappings are handled.

Previously, there were some potentially "semi-anonymous" states. Now, it seems like we're making these truly anonymous by clearing the `file` pointer and `vm_ops` within `mmap_zero_prepare` and `map_set_anon`. The code seems to be explicitly checking for shared mappings and then handling private mappings of `/dev/zero`. There are a lot of details related to changes within `__mmap_region`, and I need to review those sections within `mm/vma.c` to understand the full impact of the change.

I see a new `file_is_dev_zero()` function, which is useful for simplifying the logic. Plus, there are some cleanups of comments and checks in various header files related to `/dev/zero` and `MAP_PRIVATE` cases. I'm also seeing added tests, which is good.

Now, the important part. Let's see if there is potential for uninitialized memory usage or leaks. Let's review the KMSAN requirements. The general rule is: If KASAN, LOCKDEP, or standard bug detectors can catch the bug, we don't need KMSAN. We only need KMSAN if the patch introduces or modifies things like:

1.  Kernel structures sent to user space (potential info leak).
2.  Conditional logic or branching that depends on uninitialized variables.
3.  Allocation or initialization of complex data structures where uninitialized fields could be read later.
4.  Bounds checks that allow access to uninitialized bytes.

And, we can set `NeedsKMSAN=false` if the changes primarily risk things like out-of-bounds access (KASAN) or if all structures are fully zeroed or initialized.

Let's carefully examine the `__mmap_region` and `call_mmap_prepare` and nearby code within `mm/vma.c`. Specifically, I need to see if we're now more aggressively clearing `file` and `vm_ops`. I need to ensure that clearing these pointers doesn't create a window for uninitialized memory to be read. I'll need to look for any new allocations, copy operations, or branching logic that touches these variables or memory regions. The key is to see if by handling these mappings with the changes, we've inadvertently created a path to read uninitialized memory. I'm going to search for `__mmap_region` in `mm/vma.c`, read the code around it, and follow the relevant paths, looking for anything that touches uninitialized memory.



20/3 2026/09/08 13:27 tool grepper
0m Args:
{
  "Expression": "call_mmap_prepare",
  "PathPrefix": "mm/"
}

Results:
{
  "Output": "mm/vma.c=2763=static int call_action_prepare(struct mmap_state *map,\n--\nmm/vma.c-2785- */\nmm/vma.c:2786:static int call_mmap_prepare(struct mmap_state *map,\nmm/vma.c-2787-\t\tstruct vm_area_desc *desc)\n--\nmm/vma.c=2863=static unsigned long __mmap_region(struct file *file, unsigned long addr,\n--\nmm/vma.c-2887-\tif (!error \u0026\u0026 have_mmap_prepare)\nmm/vma.c:2888:\t\terror = call_mmap_prepare(\u0026map, \u0026desc);\nmm/vma.c-2889-\tif (error)\n"
}

21/3 2026/09/08 13:27 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 10793
							output: 35
							thoughts: 25
						

Thoughts:
Here's my summary, as though I'm thinking through this:

**Digging into `mm/vma.c` - Lines 2760-2915**

Okay, time to dive into `mm/vma.c` again. I'm focusing on lines 2760 to 2915 specifically. I recall that area often deals with virtual memory area (VMA) management, and given the context I'm working with, I suspect this section contains the logic around [Insert the user's field expertise here - e.g., memory mapping for shared libraries, anonymous page allocation, handling of huge pages, or fault handling]. I'm expecting to see calls to functions dealing with VMAs, maybe related to insertion, removal, or modification. I'll need to pay close attention to the data structures involved, the locks being used (likely a spinlock or mutex related to the `mmap_sem`), and the conditions that trigger different code paths. I'll be looking for any hints on how the VMA is integrated with the page tables, and how the underlying physical pages are related to the VMA. I'm ready to spot the key variables and conditional checks that define the control flow for this section of code.



22/3 2026/09/08 13:27 tool read-file
0m Args:
{
  "File": "mm/vma.c",
  "FirstLine": 2780,
  "LineCount": 80
}

Results:
{
  "Contents": "2780:\t * that are permitted to be updated by the caller.\n2781:\t *\n2782:\t * All but user-defined fields will be pre-populated with original values.\n2783:\t *\n2784:\t * Returns 0 on success, or an error code otherwise.\n2785:\t */\n2786:\tstatic int call_mmap_prepare(struct mmap_state *map,\n2787:\t\t\tstruct vm_area_desc *desc)\n2788:\t{\n2789:\t\tint err;\n2790:\t\n2791:\t\t/* Invoke the hook. */\n2792:\t\terr = vfs_mmap_prepare(map-\u003efile, desc);\n2793:\t\tif (err)\n2794:\t\t\treturn err;\n2795:\t\n2796:\t\t/* It's invalid for mmap_preprare hooks to clear vm_ops. */\n2797:\t\tif (!desc-\u003evm_ops)\n2798:\t\t\treturn -EINVAL;\n2799:\t\n2800:\t\terr = call_action_prepare(map, desc);\n2801:\t\tif (err)\n2802:\t\t\treturn err;\n2803:\t\n2804:\t\t/* Update fields permitted to be changed. */\n2805:\t\tmap-\u003epgoff = desc-\u003epgoff;\n2806:\t\tif (desc-\u003evm_file != map-\u003efile) {\n2807:\t\t\tmap-\u003efile_doesnt_need_get = true;\n2808:\t\t\tmap-\u003efile = desc-\u003evm_file;\n2809:\t\t}\n2810:\t\tmap-\u003evma_flags = desc-\u003evma_flags;\n2811:\t\tmap-\u003epage_prot = desc-\u003epage_prot;\n2812:\t\t/* User-defined fields. */\n2813:\t\tmap-\u003evm_ops = desc-\u003evm_ops;\n2814:\t\tmap-\u003evm_private_data = desc-\u003eprivate_data;\n2815:\t\n2816:\t\t/*\n2817:\t\t * MAP_PRIVATE-/dev/zero mappings are an ancient way of getting\n2818:\t\t * anonymous mappings. Rather than allowing these mappings to be odd\n2819:\t\t * outliers, simply make them truly anonymous.\n2820:\t\t */\n2821:\t\tif (map_is_private(map) \u0026\u0026 file_is_dev_zero(map-\u003efile))\n2822:\t\t\tmap_set_anon(map);\n2823:\t\n2824:\t\treturn 0;\n2825:\t}\n2826:\t\n2827:\tstatic void set_vma_user_defined_fields(struct vm_area_struct *vma,\n2828:\t\t\tstruct mmap_state *map)\n2829:\t{\n2830:\t\tvma-\u003evm_ops = map-\u003evm_ops;\n2831:\t\tvma-\u003evm_private_data = map-\u003evm_private_data;\n2832:\t}\n2833:\t\n2834:\t/*\n2835:\t * Are we guaranteed no driver can change state such as to preclude KSM merging?\n2836:\t * If so, let's set the KSM mergeable flag early so we don't break VMA merging.\n2837:\t */\n2838:\tstatic bool can_set_ksm_flags_early(struct mmap_state *map)\n2839:\t{\n2840:\t\tstruct file *file = map-\u003efile;\n2841:\t\n2842:\t\t/* Anonymous mappings have no driver which can change them. */\n2843:\t\tif (!file)\n2844:\t\t\treturn true;\n2845:\t\n2846:\t\t/*\n2847:\t\t * If .mmap_prepare() is specified, then the driver will have already\n2848:\t\t * manipulated state prior to updating KSM flags. So no need to worry\n2849:\t\t * about mmap callbacks modifying VMA flags after the KSM flag has been\n2850:\t\t * updated here, which could otherwise affect KSM eligibility.\n2851:\t\t */\n2852:\t\tif (file-\u003ef_op-\u003emmap_prepare)\n2853:\t\t\treturn true;\n2854:\t\n2855:\t\t/* shmem is safe. */\n2856:\t\tif (shmem_file(file))\n2857:\t\t\treturn true;\n2858:\t\n2859:\t\t/* Any other .mmap callback is not safe. */\n"
}

23/3 2026/09/08 13:27 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 12304
							output: 35
							thoughts: 18
						

Thoughts:
Okay, here's my interpretation of that thought process, tailored for an expert audience, and written in the first person:

**Focusing In: Lines 2860-2920**

Alright, let's zoom in. My intuition tells me that the section from line 2860 to 2920 is crucial, and it's time to thoroughly examine that range. I need to understand the nuances of the argument presented there. What's the core point being conveyed within that specific section? I'm anticipating that this segment could be critical to confirming or refuting my preliminary hypothesis. This area is likely where the author really digs into the core issue. I'm especially interested in how the author supports the claims, the type of evidence they leverage, and if there are any subtle shifts in tone or approach that I might have initially missed. It's time for a close read.



24/3 2026/09/08 13:27 tool read-file
0m Args:
{
  "File": "mm/vma.c",
  "FirstLine": 2860,
  "LineCount": 60
}

Results:
{
  "Contents": "2860:\t\treturn false;\n2861:\t}\n2862:\t\n2863:\tstatic unsigned long __mmap_region(struct file *file, unsigned long addr,\n2864:\t\t\tunsigned long len, vma_flags_t vma_flags,\n2865:\t\t\tunsigned long pgoff, struct list_head *uf)\n2866:\t{\n2867:\t\tstruct mm_struct *mm = current-\u003emm;\n2868:\t\tstruct vm_area_struct *vma = NULL;\n2869:\t\tbool have_mmap_prepare = file \u0026\u0026 file-\u003ef_op-\u003emmap_prepare;\n2870:\t\tVMA_ITERATOR(vmi, mm, addr);\n2871:\t\tconst pgoff_t anon_pgoff = addr \u003e\u003e PAGE_SHIFT;\n2872:\t\tMMAP_STATE(map, mm, \u0026vmi, addr, len, pgoff, anon_pgoff, vma_flags, file);\n2873:\t\tstruct vm_area_desc desc = {\n2874:\t\t\t.mm = mm,\n2875:\t\t\t.file = file,\n2876:\t\t\t.action = {\n2877:\t\t\t\t.type = MMAP_NOTHING, /* Default to no further action. */\n2878:\t\t\t},\n2879:\t\t\t.vm_ops = \u0026vma_dummy_vm_ops,\n2880:\t\t};\n2881:\t\tbool allocated_new = false;\n2882:\t\tint error;\n2883:\t\n2884:\t\tmap.check_ksm_early = can_set_ksm_flags_early(\u0026map);\n2885:\t\n2886:\t\terror = __mmap_setup(\u0026map, \u0026desc, uf);\n2887:\t\tif (!error \u0026\u0026 have_mmap_prepare)\n2888:\t\t\terror = call_mmap_prepare(\u0026map, \u0026desc);\n2889:\t\tif (error)\n2890:\t\t\tgoto abort_munmap;\n2891:\t\n2892:\t\tif (map.check_ksm_early)\n2893:\t\t\tupdate_ksm_flags(\u0026map);\n2894:\t\n2895:\t\t/* Attempt to merge with adjacent VMAs... */\n2896:\t\tif (map.prev || map.next) {\n2897:\t\t\tVMG_MMAP_STATE(vmg, \u0026map, /* vma = */ NULL);\n2898:\t\n2899:\t\t\tvma = vma_merge_new_range(\u0026vmg);\n2900:\t\t}\n2901:\t\n2902:\t\t/* ...but if we can't, allocate a new VMA. */\n2903:\t\tif (!vma) {\n2904:\t\t\terror = __mmap_new_vma(\u0026map, \u0026vma, \u0026desc.action);\n2905:\t\t\tif (error)\n2906:\t\t\t\tgoto unacct_error;\n2907:\t\t\tallocated_new = true;\n2908:\t\t}\n2909:\t\n2910:\t\tif (have_mmap_prepare \u0026\u0026 !map_is_anon(\u0026map))\n2911:\t\t\tset_vma_user_defined_fields(vma, \u0026map);\n2912:\t\n2913:\t\t__mmap_complete(\u0026map, vma);\n2914:\t\n2915:\t\tif (have_mmap_prepare \u0026\u0026 allocated_new) {\n2916:\t\t\terror = mmap_action_complete(vma, \u0026desc.action,\n2917:\t\t\t\t\t\t     /*is_compat=*/false);\n2918:\t\t\tif (error)\n2919:\t\t\t\treturn error;\n"
}

25/3 2026/09/08 13:27 llm kmsan-evaluator
0m Model:
gemini-3.7-flash

Args:
null

Results:
null

Tokens:
							input: 13514
							output: 245
							thoughts: 807
						

Thoughts:
**My Assessment of the Patch's Memory Safety**

Okay, let's break this down. This patch is essentially refactoring how `/dev/zero` MAP_PRIVATE mappings are handled. Instead of the current semi-anonymous approach, it's making them truly anonymous within the core memory management (mm) code. That's a good cleanup, and the move from `drivers/char/mem.c` to `mm/char-mem.c` makes perfect sense.

My immediate concern, as always, is whether this introduces any memory safety issues. Let's dig in:

*   **Initialization:** Looking at the code, particularly within `__mmap_region`, the `desc` struct is initialized with designated initializers. Crucially, in `map_set_anon`, the patch explicitly sets `map->file = NULL`, `map->vm_ops = NULL`, and `map->pgoff` correctly. Nothing is left hanging. There are no obvious uninitialized struct fields.
*   **Data Flow:** I'm not seeing any new allocations or any new paths where uninitialized kernel memory could be read, copied to userspace, or influence branching logic. There's no `copy_to_user`, `put_user`, or anything like that that would expose kernel memory.
*   **KASAN vs. KMSAN:** The potential failure modes here are classic memory management problems: logic errors in VMA lifecycles, VMA merging bugs, page offset issues, and the dreaded memory corruption or use-after-free bugs. That's exactly the kind of stuff KASAN (Kernel Address Sanitizer) is designed to catch. KMSAN (Kernel Memory Sanitizer) is designed to catch uninitialized memory reads or information leaks to userspace. Since this patch doesn't introduce *either* of those risks, I don't see any need for KMSAN here.

Therefore, my final analysis is that, this patch can be deemed safe, and KMSAN is not required. It is time to call `set-results`.



26/3 2026/09/08 13:27 tool set-results
0m Args:
{
  "KMSANReasoning": "The patch series refactors the handling of MAP_PRIVATE /dev/zero mappings to make them truly anonymous VMAs within the core memory management subsystem (moving drivers/char/mem.c to mm/char-mem.c, updating mmap_prepare handling, and removing special-case workarounds for semi-anonymous VMAs).\n\nKMSAN vs. KASAN applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce or alter kernel-to-user copies, uninitialized buffer reads, or conditional branches on uninitialized data. All structures (e.g. struct vm_area_desc) are fully initialized before use.\n- Any bugs stemming from this refactoring (e.g. VMA merging discrepancies, page offset errors, or reference/lifetime management issues) are memory management/logic issues that would manifest as use-after-free or memory corruption, which are covered by KASAN and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

Results:
{
  "KMSANReasoning": "The patch series refactors the handling of MAP_PRIVATE /dev/zero mappings to make them truly anonymous VMAs within the core memory management subsystem (moving drivers/char/mem.c to mm/char-mem.c, updating mmap_prepare handling, and removing special-case workarounds for semi-anonymous VMAs).\n\nKMSAN vs. KASAN applicability:\n- KMSAN detects reads of uninitialized memory and information leaks to user space. This patch does not introduce or alter kernel-to-user copies, uninitialized buffer reads, or conditional branches on uninitialized data. All structures (e.g. struct vm_area_desc) are fully initialized before use.\n- Any bugs stemming from this refactoring (e.g. VMA merging discrepancies, page offset errors, or reference/lifetime management issues) are memory management/logic issues that would manifest as use-after-free or memory corruption, which are covered by KASAN and existing kernel debug checks.\n\nTherefore, a dedicated KMSAN fuzzing session is not warranted.",
  "NeedsKMSAN": false
}

LLM Calls Summary:
Total Calls Total Tokens Avg Tokens Total Duration (Seconds) Avg Duration (Seconds)
Tool Calls Summary:
Total Calls Total Duration (Seconds) Avg Duration (Seconds)