| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/06 09:43 | flow | patch-triage |
0mArgs:null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"KMSANReasoning": "",
"NeedsKMSAN": false,
"Reasoning": "The patch only modifies documentation and kselftest user-space test files under tools/testing/selftests/, with no changes affecting the compiled kernel image (vmlinux) or kernel modules.",
"WorthFuzzing": false
} |
| 1/1 | 2026/10/06 09:43 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 34808c3917fc92c0e22ec347b238d2b20957c4d1\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Oct 6 09:43:11 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst\nindex 64c0ec7428a27..fc4dc1f9dc931 100644\n--- a/Documentation/dev-tools/kselftest.rst\n+++ b/Documentation/dev-tools/kselftest.rst\n@@ -230,6 +230,24 @@ section::\n \n .. _tar's auto-compress: https://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress\n \n+Build and test on nommu target\n+==============================\n+\n+The nommu selftests detect NOMMU at runtime by checking for the ``MmapCopy``\n+entry in ``/proc/meminfo``. Ensure procfs is mounted at ``/proc`` before\n+building and running the tests.\n+\n+::\n+\n+ $ make ARCH=um O=build kselftest-all TARGETS=nommu # \u003c= build-only\n+ $ make ARCH=um O=build kselftest-install TARGETS=nommu\n+ $ ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu\n+\n+The C tests report a skip if ``/proc/meminfo`` is unavailable. On a NOMMU\n+system, the runner needs that file to avoid wrapping the tests in ``timeout``\n+before they can report a skip. Mounting procfs is therefore a prerequisite\n+for running this target through the kselftest runner.\n+\n Contributing new tests\n ======================\n \ndiff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh\nindex 311811dc55a07..45fb8ec384932 100644\n--- a/tools/testing/selftests/kselftest/runner.sh\n+++ b/tools/testing/selftests/kselftest/runner.sh\n@@ -36,10 +36,19 @@ tap_prefix()\n \tfi\n }\n \n+is_nommu()\n+{\n+\tgrep -q '^MmapCopy:' /proc/meminfo 2\u003e/dev/null\n+}\n+\n tap_timeout()\n {\n+\t# nommu doesn't support timeout command (missing fork(2))\n+\tif is_nommu; then\n+\t\techo \"timeout isn't supported for NOMMU\"\n+\t\t$1\n \t# Make sure tests will time out if utility is available.\n-\tif [ -x /usr/bin/timeout ] ; then\n+\telif [ -x /usr/bin/timeout ]; then\n \t\t/usr/bin/timeout --foreground \"$kselftest_timeout\" \\\n \t\t\t/usr/bin/timeout \"$kselftest_timeout\" $1\n \telse\ndiff --git a/tools/testing/selftests/nommu/Makefile b/tools/testing/selftests/nommu/Makefile\nnew file mode 100644\nindex 0000000000000..87bc3bbfa2fd0\n--- /dev/null\n+++ b/tools/testing/selftests/nommu/Makefile\n@@ -0,0 +1,7 @@\n+# SPDX-License-Identifier: GPL-2.0\n+# Makefile for nommu selftests\n+\n+TEST_GEN_PROGS += nommu_mmap_test\n+TEST_GEN_PROGS += nommu_mremap_test\n+\n+include ../lib.mk\ndiff --git a/tools/testing/selftests/nommu/nommu.h b/tools/testing/selftests/nommu/nommu.h\nnew file mode 100644\nindex 0000000000000..2c9a2f4e013ac\n--- /dev/null\n+++ b/tools/testing/selftests/nommu/nommu.h\n@@ -0,0 +1,33 @@\n+/* SPDX-License-Identifier: GPL-2.0 */\n+#ifndef NOMMU_H\n+#define NOMMU_H\n+\n+#include \u003cstdio.h\u003e\n+#include \u003cstring.h\u003e\n+\n+/* Returns 1 for NOMMU, 0 for MMU, and -1 if /proc/meminfo is unavailable. */\n+static inline int ksft_is_nommu(void)\n+{\n+\tFILE *fp;\n+\tchar line[256];\n+\tint nommu = 0;\n+\n+\tfp = fopen(\"/proc/meminfo\", \"r\");\n+\tif (!fp)\n+\t\treturn -1;\n+\n+\twhile (fgets(line, sizeof(line), fp)) {\n+\t\tif (strncmp(line, \"MmapCopy:\", sizeof(\"MmapCopy:\") - 1) == 0) {\n+\t\t\tnommu = 1;\n+\t\t\tbreak;\n+\t\t}\n+\t}\n+\n+\tif (ferror(fp))\n+\t\tnommu = -1;\n+\tfclose(fp);\n+\n+\treturn nommu;\n+}\n+\n+#endif\ndiff --git a/tools/testing/selftests/nommu/nommu_mmap_test.c b/tools/testing/selftests/nommu/nommu_mmap_test.c\nnew file mode 100644\nindex 0000000000000..2b3639cf72efb\n--- /dev/null\n+++ b/tools/testing/selftests/nommu/nommu_mmap_test.c\n@@ -0,0 +1,264 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#define _GNU_SOURCE\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003csys/mman.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003cerrno.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003climits.h\u003e\n+#include \"kselftest.h\"\n+#include \"nommu.h\"\n+\n+#include \u003csys/vfs.h\u003e\n+#ifndef RAMFS_MAGIC\n+#define RAMFS_MAGIC 0x858458f6\n+#endif\n+\n+static size_t ps;\n+static int nommu;\n+\n+struct test_case_t {\n+\tconst char *name;\n+\tconst char *pathname;\n+\tint open_flags;\n+\tint mmap_prot;\n+\tint mmap_flags;\n+\tint exp_err;\n+\tint (*resolve_exp_err)(const char *path);\n+};\n+\n+static int get_shm_expected_error(const char *path)\n+{\n+\tstruct statfs fs;\n+\n+\tif (!nommu)\n+\t\treturn 0;\n+\n+\tif (statfs(path, \u0026fs) == 0) {\n+\t\tif (fs.f_type == RAMFS_MAGIC)\n+\t\t\treturn 0; /* ramfs succeed with contiguous memory */\n+\t}\n+\t /* hostfs, etc returns ENODEV due to lack of contiguous allocation */\n+\treturn ENODEV;\n+}\n+\n+static struct test_case_t test_cases[] = {\n+\t{\n+\t\t.name = \"anonymous private allocation\",\n+\t\t.pathname = NULL,\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ | PROT_WRITE,\n+\t\t.mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = NULL,\n+\t},\n+\t{\n+\t\t.name = \"non-anonymous private file mapping (rw-)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-reg-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ | PROT_WRITE,\n+\t\t.mmap_flags = MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = NULL,\n+\t},\n+\t{\n+\t\t.name = \"non-anonymous private file mapping (r--)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-reg-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ,\n+\t\t.mmap_flags = MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = NULL,\n+\t},\n+\t{\n+\t\t.name = \"non-anonymous shared file mapping (rw-)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-shm-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ | PROT_WRITE,\n+\t\t.mmap_flags = MAP_SHARED,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = get_shm_expected_error,\n+\t},\n+\t{\n+\t\t.name = \"non-anonymous shared file mapping (r--)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-shm-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ,\n+\t\t.mmap_flags = MAP_SHARED,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = get_shm_expected_error,\n+\t},\n+};\n+\n+static int run_mapping_matrix_test(struct test_case_t *tcase)\n+{\n+\tint fd;\n+\tvoid *ptr = MAP_FAILED;\n+\tchar path_buf[PATH_MAX];\n+\tconst char *path = tcase-\u003epathname;\n+\tint rc = KSFT_PASS;\n+\tint expected_error;\n+\n+\tksft_print_msg(\"[RUN] %s\\n\", tcase-\u003ename);\n+\n+\tif (tcase-\u003epathname == NULL) {\n+\t\tfd = -1;\n+\t} else if (strstr(tcase-\u003epathname, \"XXXXXX\")) {\n+\t\tstrncpy(path_buf, tcase-\u003epathname, sizeof(path_buf) - 1);\n+\t\tpath_buf[sizeof(path_buf) - 1] = '\\0';\n+\t\tfd = mkstemp(path_buf);\n+\t\tif (fd \u003c 0) {\n+\t\t\tksft_print_msg(\"Failed to setup temp node: %s\\n\",\n+\t\t\t\ttcase-\u003epathname);\n+\t\t\tksft_test_result_skip(\"%s\\n\", tcase-\u003ename);\n+\t\t\treturn KSFT_SKIP;\n+\t\t}\n+\t\tif (ftruncate(fd, ps) != 0) {\n+\t\t\tksft_print_msg(\"ftruncate failed for: %s\\n\", tcase-\u003epathname);\n+\t\t\trc = KSFT_FAIL;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\tpath = path_buf;\n+\t} else {\n+\t\tfd = open(tcase-\u003epathname, tcase-\u003eopen_flags, 0600);\n+\t\tif (fd \u003c 0) {\n+\t\t\tksft_print_msg(\"Device node not accessible: %s\\n\",\n+\t\t\t\t tcase-\u003epathname);\n+\t\t\tksft_test_result_skip(\"%s\\n\", tcase-\u003ename);\n+\t\t\treturn KSFT_SKIP;\n+\t\t}\n+\t}\n+\n+\texpected_error = tcase-\u003eexp_err;\n+\tif (tcase-\u003eresolve_exp_err \u0026\u0026 fd \u003e= 0)\n+\t\texpected_error = tcase-\u003eresolve_exp_err(path);\n+\n+\tptr = mmap(NULL, ps, tcase-\u003emmap_prot, tcase-\u003emmap_flags, fd, 0);\n+\n+\tif (expected_error != 0) {\n+\t\tif (ptr != MAP_FAILED) {\n+\t\t\tksft_print_msg(\"mmap unexpectedly succeeded (exp error %d)\\n\",\n+\t\t\t\t\t expected_error);\n+\t\t\trc = KSFT_FAIL;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\tif (errno != expected_error) {\n+\t\t\tksft_print_msg(\"mmap failed with %d (%s), but expected %d\\n\",\n+\t\t\t\terrno, strerror(errno), expected_error);\n+\t\t\trc = KSFT_FAIL;\n+\t\t\tgoto cleanup;\n+\t\t}\n+\t\tksft_print_msg(\"Correctly rejected with expected error %s(%d)\\n\",\n+\t\t\tstrerror(expected_error), expected_error);\n+\t\trc = KSFT_PASS;\n+\t\tgoto cleanup;\n+\t}\n+\n+\tif (ptr == MAP_FAILED) {\n+\t\tksft_print_msg(\"mmap failed unexpectedly: %s\\n\", strerror(errno));\n+\t\trc = KSFT_FAIL;\n+\t\tgoto cleanup;\n+\t}\n+\n+cleanup:\n+\tif (ptr != MAP_FAILED \u0026\u0026 munmap(ptr, ps)) {\n+\t\tksft_print_msg(\"munmap failed: %s\\n\", strerror(errno));\n+\t\trc = KSFT_FAIL;\n+\t}\n+\tif (fd \u003e= 0) {\n+\t\tclose(fd);\n+\t\tif (tcase-\u003epathname \u0026\u0026 strstr(tcase-\u003epathname, \"XXXXXX\") \u0026\u0026\n+\t\t unlink(path_buf)) {\n+\t\t\tksft_print_msg(\"unlink failed for %s: %s\\n\",\n+\t\t\t\t path_buf, strerror(errno));\n+\t\t\trc = KSFT_FAIL;\n+\t\t}\n+\t}\n+\tksft_test_result_report(rc, \"%s\\n\", tcase-\u003ename);\n+\treturn rc;\n+}\n+\n+static int test_map_fixed(void)\n+{\n+\tvoid *fixed_addr;\n+\tvoid *ptr;\n+\n+\tksft_print_msg(\"[RUN] %s\\n\", __func__);\n+\n+\tfixed_addr = mmap(NULL, ps, PROT_READ | PROT_WRITE,\n+\t\t\tMAP_PRIVATE | MAP_ANONYMOUS, -1, 0);\n+\tif (fixed_addr == MAP_FAILED) {\n+\t\tksft_print_msg(\"Unable to reserve test address: %s\\n\",\n+\t\t\t\tstrerror(errno));\n+\t\tksft_test_result_skip(\"MAP_FIXED behavior\\n\");\n+\t\treturn KSFT_SKIP;\n+\t}\n+\n+\tif (munmap(fixed_addr, ps)) {\n+\t\tksft_print_msg(\"Unable to release test address: %s\\n\",\n+\t\t\tstrerror(errno));\n+\t\tksft_test_result_fail(\"MAP_FIXED behavior\\n\");\n+\t\treturn KSFT_FAIL;\n+\t}\n+\n+\tptr = mmap(fixed_addr, ps, PROT_READ | PROT_WRITE,\n+\t\tMAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);\n+\n+\tif (nommu) {\n+\t\tif (ptr == MAP_FAILED \u0026\u0026 (errno == ENODEV || errno == EINVAL)) {\n+\t\t\tksft_print_msg(\"MAP_FIXED correctly rejected under nommu\\n\");\n+\t\t\tksft_test_result_pass(\"MAP_FIXED behavior\\n\");\n+\t\t\treturn KSFT_PASS;\n+\t\t}\n+\t\tif (ptr != MAP_FAILED) {\n+\t\t\tksft_print_msg(\"MAP_FIXED unexpectedly allowed under nommu\\n\");\n+\t\t\tksft_test_result_fail(\"MAP_FIXED behavior\\n\");\n+\t\t\tif (munmap(ptr, ps))\n+\t\t\t\tksft_print_msg(\"munmap failed: %s\\n\", strerror(errno));\n+\t\t\treturn KSFT_FAIL;\n+\t\t}\n+\t\tksft_print_msg(\"MAP_FIXED failed under NOMMU: %s\\n\",\n+\t\t\t\t strerror(errno));\n+\t\tksft_test_result_fail(\"MAP_FIXED behavior\\n\");\n+\t\treturn KSFT_FAIL;\n+\t}\n+\tif (ptr != MAP_FAILED) {\n+\t\tksft_print_msg(\"MAP_FIXED successfully allocated under MMU\\n\");\n+\t\tif (munmap(ptr, ps)) {\n+\t\t\tksft_print_msg(\"munmap failed: %s\\n\", strerror(errno));\n+\t\t\tksft_test_result_fail(\"MAP_FIXED behavior\\n\");\n+\t\t\treturn KSFT_FAIL;\n+\t\t}\n+\t\tksft_test_result_pass(\"MAP_FIXED behavior\\n\");\n+\t\treturn KSFT_PASS;\n+\t}\n+\tksft_print_msg(\"MAP_FIXED failed allocation under MMU\\n\");\n+\tksft_test_result_fail(\"MAP_FIXED behavior\\n\");\n+\treturn KSFT_FAIL;\n+}\n+\n+int main(int argc, char **argv)\n+{\n+\tint i;\n+\n+\tnommu = ksft_is_nommu();\n+\tif (nommu \u003c 0)\n+\t\tksft_exit_skip(\"Cannot read /proc/meminfo; mount procfs at /proc\\n\");\n+\n+\tps = sysconf(_SC_PAGESIZE);\n+\tksft_print_header();\n+\tksft_set_plan(ARRAY_SIZE(test_cases) + 1);\n+\n+\tif (nommu)\n+\t\tksft_print_msg(\"Running strict MMAP test criteria under nommu architecture\\n\");\n+\telse\n+\t\tksft_print_msg(\"Running MMAP test criteria under MMU architecture\\n\");\n+\n+\ttest_map_fixed();\n+\tfor (i = 0; i \u003c (int)ARRAY_SIZE(test_cases); i++)\n+\t\trun_mapping_matrix_test(\u0026test_cases[i]);\n+\n+\tksft_finished();\n+}\ndiff --git a/tools/testing/selftests/nommu/nommu_mremap_test.c b/tools/testing/selftests/nommu/nommu_mremap_test.c\nnew file mode 100644\nindex 0000000000000..6ee89cb25f61a\n--- /dev/null\n+++ b/tools/testing/selftests/nommu/nommu_mremap_test.c\n@@ -0,0 +1,356 @@\n+// SPDX-License-Identifier: GPL-2.0\n+#define _GNU_SOURCE\n+#include \u003cstdio.h\u003e\n+#include \u003cstdlib.h\u003e\n+#include \u003csys/mman.h\u003e\n+#include \u003cunistd.h\u003e\n+#include \u003cfcntl.h\u003e\n+#include \u003cerrno.h\u003e\n+#include \u003cstring.h\u003e\n+#include \u003climits.h\u003e\n+#include \"kselftest.h\"\n+#include \"nommu.h\"\n+\n+#include \u003csys/vfs.h\u003e\n+#ifndef RAMFS_MAGIC\n+#define RAMFS_MAGIC 0x858458f6\n+#endif\n+\n+static size_t ps;\n+static int nommu;\n+\n+static long get_fs_type(const char *path)\n+{\n+\tstruct statfs fs;\n+\n+\tif (statfs(path, \u0026fs) == 0)\n+\t\treturn fs.f_type;\n+\n+\treturn 0;\n+}\n+\n+static void munmap_shrink_test(void)\n+{\n+\tvoid *addr;\n+\tint ret;\n+\n+\t/* munmap shrink test */\n+\tfor (int i = 0; i \u003c 4; i++) {\n+\t\taddr = mmap(NULL, ps * 4, PROT_READ | PROT_WRITE,\n+\t\t\t MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);\n+\t\tif (addr == MAP_FAILED) {\n+\t\t\tksft_print_msg(\"mmap failed: %s(%d)\\n\", strerror(errno), errno);\n+\t\t\tksft_test_result_fail(\"munmap shrink\\n\");\n+\t\t\treturn;\n+\t\t}\n+\t\tret = munmap((char *)addr + ps * i, ps);\n+\t\tif (ret != 0) {\n+\t\t\tksft_print_msg(\"memory %p isn't unmapped at %p\\n\",\n+\t\t\t\taddr, (char *)addr + ps * i);\n+\t\t\tgoto error;\n+\t\t}\n+\n+\t\tif (i == 0) {\n+\t\t\tif (munmap(addr + ps, ps * 3))\n+\t\t\t\tgoto error;\n+\t\t} else if (i == 1) {\n+\t\t\tif (munmap(addr, ps) || munmap(addr + (ps * 2), ps * 2))\n+\t\t\t\tgoto error;\n+\t\t} else if (i == 2) {\n+\t\t\tif (munmap(addr, ps * 2) || munmap(addr + (ps * 3), ps))\n+\t\t\t\tgoto error;\n+\t\t} else if (i == 3) {\n+\t\t\tif (munmap(addr, ps * 3))\n+\t\t\t\tgoto error;\n+\t\t}\n+\t}\n+\n+\tksft_test_result_pass(\"munmap shrink\\n\");\n+\treturn;\n+error:\n+\tfor (int j = 0; j \u003c 4; j++) {\n+\t\tif (munmap((char *)addr + j * ps, ps))\n+\t\t\tksft_print_msg(\"cleanup munmap failed: %s\\n\", strerror(errno));\n+\t}\n+\tksft_print_msg(\"clean up failures\\n\");\n+\tksft_test_result_fail(\"munmap shrink\\n\");\n+}\n+\n+static size_t page_align(size_t len)\n+{\n+\treturn (len + ps - 1) / ps * ps;\n+}\n+\n+static void mremap_shrink_test(void)\n+{\n+\tvoid *addr, *addr2;\n+\tsize_t current_len;\n+\tsize_t old_len, new_len;\n+\tstruct param {\n+\t\tsize_t old;\n+\t\tsize_t new;\n+\t} params[] = {\n+\t\t/* should not happen any shrink */\n+\t\t{ .old = ps * 4 - 1, .new = ps * 4 - 2 },\n+\t\t/* should not happen any shrink */\n+\t\t{ .old = ps * 4 - 1, .new = ps * 4 },\n+\t\t{ .old = ps * 4, .new = ps * 2 },\n+\t\t/* should not happen any shrink */\n+\t\t{ .old = ps * 2, .new = ps * 2 - 2 },\n+\t\t{ .old = ps * 2 - 2, .new = ps * 1 },\n+\t};\n+\n+\t/* mremap shrink test */\n+\tcurrent_len = page_align(ps * 4 - 1);\n+\taddr = mmap(NULL, ps * 4 - 1, PROT_READ | PROT_WRITE,\n+\t\t MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);\n+\tif (addr == MAP_FAILED) {\n+\t\tksft_print_msg(\"mmap failed: %s(%d)\\n\", strerror(errno), errno);\n+\t\tksft_test_result_fail(\"mremap shrink\\n\");\n+\t\treturn;\n+\t}\n+\n+\tfor (int i = 0; i \u003c ARRAY_SIZE(params); i++) {\n+\t\told_len = params[i].old;\n+\t\tnew_len = params[i].new;\n+\t\tcurrent_len = page_align(new_len);\n+\t\taddr2 = mremap(addr, old_len, new_len, MREMAP_MAYMOVE);\n+\t\tif (addr2 == MAP_FAILED) {\n+\t\t\tksft_print_msg(\"memory %p isn't remapped at %p\\n\", addr, addr2);\n+\t\t\tksft_test_result_fail(\"mremap shrink\\n\");\n+\t\t\tmunmap(addr, page_align(old_len));\n+\t\t\treturn;\n+\t\t}\n+\n+\t\taddr = addr2;\n+\t}\n+\n+\tif (munmap(addr, current_len)) {\n+\t\tksft_print_msg(\"cleanup failed: %s\\n\", strerror(errno));\n+\t\tksft_test_result_fail(\"mremap shrink\\n\");\n+\t\treturn;\n+\t}\n+\tksft_test_result_pass(\"mremap shrink\\n\");\n+}\n+\n+static int get_shared_writable_file_expected_error(const char *path)\n+{\n+\tif (nommu \u0026\u0026 get_fs_type(path) == RAMFS_MAGIC)\n+\t\treturn EPERM; /* ramfs failed */\n+\n+\treturn 0;\n+}\n+\n+struct mremap_case_t {\n+\tconst char *name;\n+\tconst char *pathname;\n+\tint open_flags;\n+\tint mmap_prot;\n+\tint mmap_flags;\n+\tint exp_err;\n+\tint nommu_exp_err;\n+\tint (*resolve_exp_err)(const char *path);\n+\tunsigned int old_pages;\n+\tunsigned int new_pages;\n+};\n+\n+static struct mremap_case_t mremap_cases[] = {\n+\t{\n+\t\t.name = \"anonymous shrink (r--)\",\n+\t\t.pathname = NULL,\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ,\n+\t\t.mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = 0,\n+\t},\n+\t{\n+\t\t.name = \"shared file shrink (r--)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-remap-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ,\n+\t\t.mmap_flags = MAP_SHARED,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = get_shared_writable_file_expected_error,\n+\t},\n+\t{\n+\t\t.name = \"private file unchanged length (r-)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-remap-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ,\n+\t\t.mmap_flags = MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.nommu_exp_err = EPERM,\n+\t\t.resolve_exp_err = 0,\n+\t\t.old_pages = 4,\n+\t\t.new_pages = 4,\n+\t},\n+\t{\n+\t\t.name = \"private file unchanged length (rw-)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-remap-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ | PROT_WRITE,\n+\t\t.mmap_flags = MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.resolve_exp_err = 0,\n+\t\t.old_pages = 4,\n+\t\t.new_pages = 4,\n+\t},\n+\t{\n+\t\t.name = \"private file growth (r-)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-remap-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ,\n+\t\t.mmap_flags = MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.nommu_exp_err = EPERM,\n+\t\t.resolve_exp_err = 0,\n+\t\t.old_pages = 4,\n+\t\t.new_pages = 8,\n+\t},\n+\t{\n+\t\t.name = \"private file growth (rw-)\",\n+\t\t.pathname = \"/tmp/ksft.nommu-remap-XXXXXX\",\n+\t\t.open_flags = O_CREAT | O_RDWR | O_EXCL,\n+\t\t.mmap_prot = PROT_READ | PROT_WRITE,\n+\t\t.mmap_flags = MAP_PRIVATE,\n+\t\t.exp_err = 0,\n+\t\t.nommu_exp_err = ENOMEM,\n+\t\t.resolve_exp_err = 0,\n+\t\t.old_pages = 4,\n+\t\t.new_pages = 8,\n+\t},\n+};\n+\n+static int run_mremap_test(struct mremap_case_t *tcase)\n+{\n+\tint fd = -1;\n+\tvoid *addr, *addr2;\n+\tchar pb[PATH_MAX];\n+\tconst char *path = tcase-\u003epathname;\n+\tint rc = KSFT_PASS;\n+\tint expected_error;\n+\tunsigned int old_pages = tcase-\u003eold_pages ?: 4;\n+\tunsigned int new_pages = tcase-\u003enew_pages ?: 2;\n+\tunsigned int file_pages = old_pages \u003e new_pages ?\n+\t\t\t\t old_pages : new_pages;\n+\n+\tksft_print_msg(\"[RUN] Testing mremap: %s\\n\", tcase-\u003ename);\n+\n+\tif (tcase-\u003epathname \u0026\u0026 strstr(tcase-\u003epathname, \"XXXXXX\")) {\n+\t\tstrncpy(pb, tcase-\u003epathname, sizeof(pb) - 1);\n+\t\tpb[sizeof(pb) - 1] = '\\0';\n+\t\tfd = mkstemp(pb);\n+\t\tif (fd \u003c 0) {\n+\t\t\tksft_print_msg(\"Failed to setup file backing\\n\");\n+\t\t\tksft_test_result_skip(\"%s\\n\", tcase-\u003ename);\n+\t\t\treturn KSFT_SKIP;\n+\t\t}\n+\t\tif (ftruncate(fd, ps * file_pages) != 0) {\n+\t\t\tksft_print_msg(\"Failed to setup file backing\\n\");\n+\t\t\trc = KSFT_FAIL;\n+\t\t\tgoto out;\n+\t\t}\n+\n+\t\tif (nommu \u0026\u0026 (tcase-\u003emmap_flags \u0026 MAP_SHARED) \u0026\u0026\n+\t\t get_fs_type(pb) != RAMFS_MAGIC) {\n+\t\t\tksft_print_msg(\"Skip the test under non-ramfs filesystem (%s)\\n\",\n+\t\t\t\tpb);\n+\t\t\trc = KSFT_SKIP;\n+\t\t\tgoto out;\n+\t\t}\n+\t\tpath = pb;\n+\t} else if (tcase-\u003epathname) {\n+\t\tfd = open(tcase-\u003epathname, tcase-\u003eopen_flags, 0600);\n+\t\tif (fd \u003c 0) {\n+\t\t\tksft_print_msg(\"Backing node not accessible\\n\");\n+\t\t\tksft_test_result_skip(\"%s\\n\", tcase-\u003ename);\n+\t\t\treturn KSFT_SKIP;\n+\t\t}\n+\n+\t\tif (nommu \u0026\u0026 (tcase-\u003emmap_flags \u0026 MAP_SHARED) \u0026\u0026\n+\t\t get_fs_type(tcase-\u003epathname) != RAMFS_MAGIC) {\n+\t\t\tksft_print_msg(\"Skip the test under non-ramfs filesystem (%s)\\n\",\n+\t\t\t\t\t tcase-\u003epathname);\n+\t\t\trc = KSFT_SKIP;\n+\t\t\tgoto out;\n+\t\t}\n+\t}\n+\n+\taddr = mmap(NULL, ps * old_pages, tcase-\u003emmap_prot,\n+\t\t tcase-\u003emmap_flags, fd, 0);\n+\tif (addr == MAP_FAILED) {\n+\t\tksft_print_msg(\"mmap mapping failed %s(%d)\\n\", strerror(errno), errno);\n+\t\trc = KSFT_FAIL;\n+\t\tgoto out;\n+\t}\n+\n+\texpected_error = nommu ? tcase-\u003enommu_exp_err : tcase-\u003eexp_err;\n+\tif (tcase-\u003eresolve_exp_err \u0026\u0026 fd \u003e= 0)\n+\t\texpected_error = tcase-\u003eresolve_exp_err(path);\n+\n+\taddr2 = mremap(addr, ps * old_pages, ps * new_pages,\n+\t\t MREMAP_MAYMOVE);\n+\n+\tif (expected_error != 0) {\n+\t\tif (addr2 != MAP_FAILED) {\n+\t\t\tksft_print_msg(\"Expected error %d, but mremap unexpectedly succeeded\\n\",\n+\t\t\t\t expected_error);\n+\t\t\trc = KSFT_FAIL;\n+\t\t} else if (errno != expected_error) {\n+\t\t\tksft_print_msg(\"Expected error %d, got %s(%d)\\n\",\n+\t\t\t\t expected_error, strerror(errno), errno);\n+\t\t\trc = KSFT_FAIL;\n+\t\t} else {\n+\t\t\tksft_print_msg(\"%s: Handled expected error path (errno=%d)\\n\",\n+\t\t\t\t tcase-\u003ename, expected_error);\n+\t\t}\n+\t} else if (addr2 == MAP_FAILED) {\n+\t\tksft_print_msg(\"mremap shrink failed unexpectedly: %s\\n\",\n+\t\t\t strerror(errno));\n+\t\trc = KSFT_FAIL;\n+\t} else {\n+\t\tksft_print_msg(\"%s step successful\\n\", tcase-\u003ename);\n+\t}\n+\n+\t/* clean up */\n+\tif (munmap(addr2 == MAP_FAILED ? addr : addr2,\n+\t\t addr2 == MAP_FAILED ? ps * old_pages : ps * new_pages)) {\n+\t\tksft_print_msg(\"munmap failed: %s\\n\", strerror(errno));\n+\t\trc = KSFT_FAIL;\n+\t}\n+\n+out:\n+\tif (fd \u003e= 0) {\n+\t\tclose(fd);\n+\t\tif (tcase-\u003epathname \u0026\u0026 strstr(tcase-\u003epathname, \"XXXXXX\") \u0026\u0026\n+\t\t unlink(pb)) {\n+\t\t\tksft_print_msg(\"unlink failed for %s: %s\\n\", pb, strerror(errno));\n+\t\t\trc = KSFT_FAIL;\n+\t\t}\n+\t}\n+\n+\tksft_test_result_report(rc, \"%s\\n\", tcase-\u003ename);\n+\treturn rc;\n+}\n+\n+int main(int argc, char **argv)\n+{\n+\tint i;\n+\n+\tnommu = ksft_is_nommu();\n+\tif (nommu \u003c 0)\n+\t\tksft_exit_skip(\"Cannot read /proc/meminfo; mount procfs at /proc\\n\");\n+\n+\tps = sysconf(_SC_PAGESIZE);\n+\tksft_print_header();\n+\tksft_set_plan(ARRAY_SIZE(mremap_cases) + 2);\n+\n+\tmunmap_shrink_test();\n+\tmremap_shrink_test();\n+\n+\tfor (i = 0; i \u003c (int)ARRAY_SIZE(mremap_cases); i++)\n+\t\trun_mremap_test(\u0026mremap_cases[i]);\n+\n+\tksft_finished();\n+}\n"
} |
| 2/1 | 2026/10/06 09:43 | agent | patch-evaluator |
0mModel:core Args: null Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only modifies documentation and kselftest user-space test files under tools/testing/selftests/, with no changes affecting the compiled kernel image (vmlinux) or kernel modules.",
"WorthFuzzing": false
}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 34808c3917fc92c0e22ec347b238d2b20957c4d1
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Oct 6 09:43:11 2026 +0000
syz-cluster: applied patch under review
diff --git a/Documentation/dev-tools/kselftest.rst b/Documentation/dev-tools/kselftest.rst
index 64c0ec7428a27..fc4dc1f9dc931 100644
--- a/Documentation/dev-tools/kselftest.rst
+++ b/Documentation/dev-tools/kselftest.rst
@@ -230,6 +230,24 @@ section::
.. _tar's auto-compress: https://www.gnu.org/software/tar/manual/html_node/gzip.html#auto_002dcompress
+Build and test on nommu target
+==============================
+
+The nommu selftests detect NOMMU at runtime by checking for the ``MmapCopy``
+entry in ``/proc/meminfo``. Ensure procfs is mounted at ``/proc`` before
+building and running the tests.
+
+::
+
+ $ make ARCH=um O=build kselftest-all TARGETS=nommu # <= build-only
+ $ make ARCH=um O=build kselftest-install TARGETS=nommu
+ $ ./build/kselftest/kselftest_install/run_kselftest.sh -p -c nommu
+
+The C tests report a skip if ``/proc/meminfo`` is unavailable. On a NOMMU
+system, the runner needs that file to avoid wrapping the tests in ``timeout``
+before they can report a skip. Mounting procfs is therefore a prerequisite
+for running this target through the kselftest runner.
+
Contributing new tests
======================
diff --git a/tools/testing/selftests/kselftest/runner.sh b/tools/testing/selftests/kselftest/runner.sh
index 311811dc55a07..45fb8ec384932 100644
--- a/tools/testing/selftests/kselftest/runner.sh
+++ b/tools/testing/selftests/kselftest/runner.sh
@@ -36,10 +36,19 @@ tap_prefix()
fi
}
+is_nommu()
+{
+ grep -q '^MmapCopy:' /proc/meminfo 2>/dev/null
+}
+
tap_timeout()
{
+ # nommu doesn't support timeout command (missing fork(2))
+ if is_nommu; then
+ echo "timeout isn't supported for NOMMU"
+ $1
# Make sure tests will time out if utility is available.
- if [ -x /usr/bin/timeout ] ; then
+ elif [ -x /usr/bin/timeout ]; then
/usr/bin/timeout --foreground "$kselftest_timeout" \
/usr/bin/timeout "$kselftest_timeout" $1
else
diff --git a/tools/testing/selftests/nommu/Makefile b/tools/testing/selftests/nommu/Makefile
new file mode 100644
index 0000000000000..87bc3bbfa2fd0
--- /dev/null
+++ b/tools/testing/selftests/nommu/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0
+# Makefile for nommu selftests
+
+TEST_GEN_PROGS += nommu_mmap_test
+TEST_GEN_PROGS += nommu_mremap_test
+
+include ../lib.mk
diff --git a/tools/testing/selftests/nommu/nommu.h b/tools/testing/selftests/nommu/nommu.h
new file mode 100644
index 0000000000000..2c9a2f4e013ac
--- /dev/null
+++ b/tools/testing/selftests/nommu/nommu.h
@@ -0,0 +1,33 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef NOMMU_H
+#define NOMMU_H
+
+#include <stdio.h>
+#include <string.h>
+
+/* Returns 1 for NOMMU, 0 for MMU, and -1 if /proc/meminfo is unavailable. */
+static inline int ksft_is_nommu(void)
+{
+ FILE *fp;
+ char line[256];
+ int nommu = 0;
+
+ fp = fopen("/proc/meminfo", "r");
+ if (!fp)
+ return -1;
+
+ while (fgets(line, sizeof(line), fp)) {
+ if (strncmp(line, "MmapCopy:", sizeof("MmapCopy:") - 1) == 0) {
+ nommu = 1;
+ break;
+ }
+ }
+
+ if (ferror(fp))
+ nommu = -1;
+ fclose(fp);
+
+ return nommu;
+}
+
+#endif
diff --git a/tools/testing/selftests/nommu/nommu_mmap_test.c b/tools/testing/selftests/nommu/nommu_mmap_test.c
new file mode 100644
index 0000000000000..2b3639cf72efb
--- /dev/null
+++ b/tools/testing/selftests/nommu/nommu_mmap_test.c
@@ -0,0 +1,264 @@
+// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <limits.h>
+#include "kselftest.h"
+#include "nommu.h"
+
+#include <sys/vfs.h>
+#ifndef RAMFS_MAGIC
+#define RAMFS_MAGIC 0x858458f6
+#endif
+
+static size_t ps;
+static int nommu;
+
+struct test_case_t {
+ const char *name;
+ const char *pathname;
+ int open_flags;
+ int mmap_prot;
+ int mmap_flags;
+ int exp_err;
+ int (*resolve_exp_err)(const char *path);
+};
+
+static int get_shm_expected_error(const char *path)
+{
+ struct statfs fs;
+
+ if (!nommu)
+ return 0;
+
+ if (statfs(path, &fs) == 0) {
+ if (fs.f_type == RAMFS_MAGIC)
+ return 0; /* ramfs succeed with contiguous memory */
+ }
+ /* hostfs, etc returns ENODEV due to lack of contiguous allocation */
+ return ENODEV;
+}
+
+static struct test_case_t test_cases[] = {
+ {
+ .name = "anonymous private allocation",
+ .pathname = NULL,
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ | PROT_WRITE,
+ .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE,
+ .exp_err = 0,
+ .resolve_exp_err = NULL,
+ },
+ {
+ .name = "non-anonymous private file mapping (rw-)",
+ .pathname = "/tmp/ksft.nommu-reg-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ | PROT_WRITE,
+ .mmap_flags = MAP_PRIVATE,
+ .exp_err = 0,
+ .resolve_exp_err = NULL,
+ },
+ {
+ .name = "non-anonymous private file mapping (r--)",
+ .pathname = "/tmp/ksft.nommu-reg-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ,
+ .mmap_flags = MAP_PRIVATE,
+ .exp_err = 0,
+ .resolve_exp_err = NULL,
+ },
+ {
+ .name = "non-anonymous shared file mapping (rw-)",
+ .pathname = "/tmp/ksft.nommu-shm-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ | PROT_WRITE,
+ .mmap_flags = MAP_SHARED,
+ .exp_err = 0,
+ .resolve_exp_err = get_shm_expected_error,
+ },
+ {
+ .name = "non-anonymous shared file mapping (r--)",
+ .pathname = "/tmp/ksft.nommu-shm-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ,
+ .mmap_flags = MAP_SHARED,
+ .exp_err = 0,
+ .resolve_exp_err = get_shm_expected_error,
+ },
+};
+
+static int run_mapping_matrix_test(struct test_case_t *tcase)
+{
+ int fd;
+ void *ptr = MAP_FAILED;
+ char path_buf[PATH_MAX];
+ const char *path = tcase->pathname;
+ int rc = KSFT_PASS;
+ int expected_error;
+
+ ksft_print_msg("[RUN] %s\n", tcase->name);
+
+ if (tcase->pathname == NULL) {
+ fd = -1;
+ } else if (strstr(tcase->pathname, "XXXXXX")) {
+ strncpy(path_buf, tcase->pathname, sizeof(path_buf) - 1);
+ path_buf[sizeof(path_buf) - 1] = '\0';
+ fd = mkstemp(path_buf);
+ if (fd < 0) {
+ ksft_print_msg("Failed to setup temp node: %s\n",
+ tcase->pathname);
+ ksft_test_result_skip("%s\n", tcase->name);
+ return KSFT_SKIP;
+ }
+ if (ftruncate(fd, ps) != 0) {
+ ksft_print_msg("ftruncate failed for: %s\n", tcase->pathname);
+ rc = KSFT_FAIL;
+ goto cleanup;
+ }
+ path = path_buf;
+ } else {
+ fd = open(tcase->pathname, tcase->open_flags, 0600);
+ if (fd < 0) {
+ ksft_print_msg("Device node not accessible: %s\n",
+ tcase->pathname);
+ ksft_test_result_skip("%s\n", tcase->name);
+ return KSFT_SKIP;
+ }
+ }
+
+ expected_error = tcase->exp_err;
+ if (tcase->resolve_exp_err && fd >= 0)
+ expected_error = tcase->resolve_exp_err(path);
+
+ ptr = mmap(NULL, ps, tcase->mmap_prot, tcase->mmap_flags, fd, 0);
+
+ if (expected_error != 0) {
+ if (ptr != MAP_FAILED) {
+ ksft_print_msg("mmap unexpectedly succeeded (exp error %d)\n",
+ expected_error);
+ rc = KSFT_FAIL;
+ goto cleanup;
+ }
+ if (errno != expected_error) {
+ ksft_print_msg("mmap failed with %d (%s), but expected %d\n",
+ errno, strerror(errno), expected_error);
+ rc = KSFT_FAIL;
+ goto cleanup;
+ }
+ ksft_print_msg("Correctly rejected with expected error %s(%d)\n",
+ strerror(expected_error), expected_error);
+ rc = KSFT_PASS;
+ goto cleanup;
+ }
+
+ if (ptr == MAP_FAILED) {
+ ksft_print_msg("mmap failed unexpectedly: %s\n", strerror(errno));
+ rc = KSFT_FAIL;
+ goto cleanup;
+ }
+
+cleanup:
+ if (ptr != MAP_FAILED && munmap(ptr, ps)) {
+ ksft_print_msg("munmap failed: %s\n", strerror(errno));
+ rc = KSFT_FAIL;
+ }
+ if (fd >= 0) {
+ close(fd);
+ if (tcase->pathname && strstr(tcase->pathname, "XXXXXX") &&
+ unlink(path_buf)) {
+ ksft_print_msg("unlink failed for %s: %s\n",
+ path_buf, strerror(errno));
+ rc = KSFT_FAIL;
+ }
+ }
+ ksft_test_result_report(rc, "%s\n", tcase->name);
+ return rc;
+}
+
+static int test_map_fixed(void)
+{
+ void *fixed_addr;
+ void *ptr;
+
+ ksft_print_msg("[RUN] %s\n", __func__);
+
+ fixed_addr = mmap(NULL, ps, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (fixed_addr == MAP_FAILED) {
+ ksft_print_msg("Unable to reserve test address: %s\n",
+ strerror(errno));
+ ksft_test_result_skip("MAP_FIXED behavior\n");
+ return KSFT_SKIP;
+ }
+
+ if (munmap(fixed_addr, ps)) {
+ ksft_print_msg("Unable to release test address: %s\n",
+ strerror(errno));
+ ksft_test_result_fail("MAP_FIXED behavior\n");
+ return KSFT_FAIL;
+ }
+
+ ptr = mmap(fixed_addr, ps, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS | MAP_FIXED, -1, 0);
+
+ if (nommu) {
+ if (ptr == MAP_FAILED && (errno == ENODEV || errno == EINVAL)) {
+ ksft_print_msg("MAP_FIXED correctly rejected under nommu\n");
+ ksft_test_result_pass("MAP_FIXED behavior\n");
+ return KSFT_PASS;
+ }
+ if (ptr != MAP_FAILED) {
+ ksft_print_msg("MAP_FIXED unexpectedly allowed under nommu\n");
+ ksft_test_result_fail("MAP_FIXED behavior\n");
+ if (munmap(ptr, ps))
+ ksft_print_msg("munmap failed: %s\n", strerror(errno));
+ return KSFT_FAIL;
+ }
+ ksft_print_msg("MAP_FIXED failed under NOMMU: %s\n",
+ strerror(errno));
+ ksft_test_result_fail("MAP_FIXED behavior\n");
+ return KSFT_FAIL;
+ }
+ if (ptr != MAP_FAILED) {
+ ksft_print_msg("MAP_FIXED successfully allocated under MMU\n");
+ if (munmap(ptr, ps)) {
+ ksft_print_msg("munmap failed: %s\n", strerror(errno));
+ ksft_test_result_fail("MAP_FIXED behavior\n");
+ return KSFT_FAIL;
+ }
+ ksft_test_result_pass("MAP_FIXED behavior\n");
+ return KSFT_PASS;
+ }
+ ksft_print_msg("MAP_FIXED failed allocation under MMU\n");
+ ksft_test_result_fail("MAP_FIXED behavior\n");
+ return KSFT_FAIL;
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ nommu = ksft_is_nommu();
+ if (nommu < 0)
+ ksft_exit_skip("Cannot read /proc/meminfo; mount procfs at /proc\n");
+
+ ps = sysconf(_SC_PAGESIZE);
+ ksft_print_header();
+ ksft_set_plan(ARRAY_SIZE(test_cases) + 1);
+
+ if (nommu)
+ ksft_print_msg("Running strict MMAP test criteria under nommu architecture\n");
+ else
+ ksft_print_msg("Running MMAP test criteria under MMU architecture\n");
+
+ test_map_fixed();
+ for (i = 0; i < (int)ARRAY_SIZE(test_cases); i++)
+ run_mapping_matrix_test(&test_cases[i]);
+
+ ksft_finished();
+}
diff --git a/tools/testing/selftests/nommu/nommu_mremap_test.c b/tools/testing/selftests/nommu/nommu_mremap_test.c
new file mode 100644
index 0000000000000..6ee89cb25f61a
--- /dev/null
+++ b/tools/testing/selftests/nommu/nommu_mremap_test.c
@@ -0,0 +1,356 @@
+// SPDX-License-Identifier: GPL-2.0
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <limits.h>
+#include "kselftest.h"
+#include "nommu.h"
+
+#include <sys/vfs.h>
+#ifndef RAMFS_MAGIC
+#define RAMFS_MAGIC 0x858458f6
+#endif
+
+static size_t ps;
+static int nommu;
+
+static long get_fs_type(const char *path)
+{
+ struct statfs fs;
+
+ if (statfs(path, &fs) == 0)
+ return fs.f_type;
+
+ return 0;
+}
+
+static void munmap_shrink_test(void)
+{
+ void *addr;
+ int ret;
+
+ /* munmap shrink test */
+ for (int i = 0; i < 4; i++) {
+ addr = mmap(NULL, ps * 4, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (addr == MAP_FAILED) {
+ ksft_print_msg("mmap failed: %s(%d)\n", strerror(errno), errno);
+ ksft_test_result_fail("munmap shrink\n");
+ return;
+ }
+ ret = munmap((char *)addr + ps * i, ps);
+ if (ret != 0) {
+ ksft_print_msg("memory %p isn't unmapped at %p\n",
+ addr, (char *)addr + ps * i);
+ goto error;
+ }
+
+ if (i == 0) {
+ if (munmap(addr + ps, ps * 3))
+ goto error;
+ } else if (i == 1) {
+ if (munmap(addr, ps) || munmap(addr + (ps * 2), ps * 2))
+ goto error;
+ } else if (i == 2) {
+ if (munmap(addr, ps * 2) || munmap(addr + (ps * 3), ps))
+ goto error;
+ } else if (i == 3) {
+ if (munmap(addr, ps * 3))
+ goto error;
+ }
+ }
+
+ ksft_test_result_pass("munmap shrink\n");
+ return;
+error:
+ for (int j = 0; j < 4; j++) {
+ if (munmap((char *)addr + j * ps, ps))
+ ksft_print_msg("cleanup munmap failed: %s\n", strerror(errno));
+ }
+ ksft_print_msg("clean up failures\n");
+ ksft_test_result_fail("munmap shrink\n");
+}
+
+static size_t page_align(size_t len)
+{
+ return (len + ps - 1) / ps * ps;
+}
+
+static void mremap_shrink_test(void)
+{
+ void *addr, *addr2;
+ size_t current_len;
+ size_t old_len, new_len;
+ struct param {
+ size_t old;
+ size_t new;
+ } params[] = {
+ /* should not happen any shrink */
+ { .old = ps * 4 - 1, .new = ps * 4 - 2 },
+ /* should not happen any shrink */
+ { .old = ps * 4 - 1, .new = ps * 4 },
+ { .old = ps * 4, .new = ps * 2 },
+ /* should not happen any shrink */
+ { .old = ps * 2, .new = ps * 2 - 2 },
+ { .old = ps * 2 - 2, .new = ps * 1 },
+ };
+
+ /* mremap shrink test */
+ current_len = page_align(ps * 4 - 1);
+ addr = mmap(NULL, ps * 4 - 1, PROT_READ | PROT_WRITE,
+ MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+ if (addr == MAP_FAILED) {
+ ksft_print_msg("mmap failed: %s(%d)\n", strerror(errno), errno);
+ ksft_test_result_fail("mremap shrink\n");
+ return;
+ }
+
+ for (int i = 0; i < ARRAY_SIZE(params); i++) {
+ old_len = params[i].old;
+ new_len = params[i].new;
+ current_len = page_align(new_len);
+ addr2 = mremap(addr, old_len, new_len, MREMAP_MAYMOVE);
+ if (addr2 == MAP_FAILED) {
+ ksft_print_msg("memory %p isn't remapped at %p\n", addr, addr2);
+ ksft_test_result_fail("mremap shrink\n");
+ munmap(addr, page_align(old_len));
+ return;
+ }
+
+ addr = addr2;
+ }
+
+ if (munmap(addr, current_len)) {
+ ksft_print_msg("cleanup failed: %s\n", strerror(errno));
+ ksft_test_result_fail("mremap shrink\n");
+ return;
+ }
+ ksft_test_result_pass("mremap shrink\n");
+}
+
+static int get_shared_writable_file_expected_error(const char *path)
+{
+ if (nommu && get_fs_type(path) == RAMFS_MAGIC)
+ return EPERM; /* ramfs failed */
+
+ return 0;
+}
+
+struct mremap_case_t {
+ const char *name;
+ const char *pathname;
+ int open_flags;
+ int mmap_prot;
+ int mmap_flags;
+ int exp_err;
+ int nommu_exp_err;
+ int (*resolve_exp_err)(const char *path);
+ unsigned int old_pages;
+ unsigned int new_pages;
+};
+
+static struct mremap_case_t mremap_cases[] = {
+ {
+ .name = "anonymous shrink (r--)",
+ .pathname = NULL,
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ,
+ .mmap_flags = MAP_ANONYMOUS | MAP_PRIVATE,
+ .exp_err = 0,
+ .resolve_exp_err = 0,
+ },
+ {
+ .name = "shared file shrink (r--)",
+ .pathname = "/tmp/ksft.nommu-remap-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ,
+ .mmap_flags = MAP_SHARED,
+ .exp_err = 0,
+ .resolve_exp_err = get_shared_writable_file_expected_error,
+ },
+ {
+ .name = "private file unchanged length (r-)",
+ .pathname = "/tmp/ksft.nommu-remap-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ,
+ .mmap_flags = MAP_PRIVATE,
+ .exp_err = 0,
+ .nommu_exp_err = EPERM,
+ .resolve_exp_err = 0,
+ .old_pages = 4,
+ .new_pages = 4,
+ },
+ {
+ .name = "private file unchanged length (rw-)",
+ .pathname = "/tmp/ksft.nommu-remap-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ | PROT_WRITE,
+ .mmap_flags = MAP_PRIVATE,
+ .exp_err = 0,
+ .resolve_exp_err = 0,
+ .old_pages = 4,
+ .new_pages = 4,
+ },
+ {
+ .name = "private file growth (r-)",
+ .pathname = "/tmp/ksft.nommu-remap-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ,
+ .mmap_flags = MAP_PRIVATE,
+ .exp_err = 0,
+ .nommu_exp_err = EPERM,
+ .resolve_exp_err = 0,
+ .old_pages = 4,
+ .new_pages = 8,
+ },
+ {
+ .name = "private file growth (rw-)",
+ .pathname = "/tmp/ksft.nommu-remap-XXXXXX",
+ .open_flags = O_CREAT | O_RDWR | O_EXCL,
+ .mmap_prot = PROT_READ | PROT_WRITE,
+ .mmap_flags = MAP_PRIVATE,
+ .exp_err = 0,
+ .nommu_exp_err = ENOMEM,
+ .resolve_exp_err = 0,
+ .old_pages = 4,
+ .new_pages = 8,
+ },
+};
+
+static int run_mremap_test(struct mremap_case_t *tcase)
+{
+ int fd = -1;
+ void *addr, *addr2;
+ char pb[PATH_MAX];
+ const char *path = tcase->pathname;
+ int rc = KSFT_PASS;
+ int expected_error;
+ unsigned int old_pages = tcase->old_pages ?: 4;
+ unsigned int new_pages = tcase->new_pages ?: 2;
+ unsigned int file_pages = old_pages > new_pages ?
+ old_pages : new_pages;
+
+ ksft_print_msg("[RUN] Testing mremap: %s\n", tcase->name);
+
+ if (tcase->pathname && strstr(tcase->pathname, "XXXXXX")) {
+ strncpy(pb, tcase->pathname, sizeof(pb) - 1);
+ pb[sizeof(pb) - 1] = '\0';
+ fd = mkstemp(pb);
+ if (fd < 0) {
+ ksft_print_msg("Failed to setup file backing\n");
+ ksft_test_result_skip("%s\n", tcase->name);
+ return KSFT_SKIP;
+ }
+ if (ftruncate(fd, ps * file_pages) != 0) {
+ ksft_print_msg("Failed to setup file backing\n");
+ rc = KSFT_FAIL;
+ goto out;
+ }
+
+ if (nommu && (tcase->mmap_flags & MAP_SHARED) &&
+ get_fs_type(pb) != RAMFS_MAGIC) {
+ ksft_print_msg("Skip the test under non-ramfs filesystem (%s)\n",
+ pb);
+ rc = KSFT_SKIP;
+ goto out;
+ }
+ path = pb;
+ } else if (tcase->pathname) {
+ fd = open(tcase->pathname, tcase->open_flags, 0600);
+ if (fd < 0) {
+ ksft_print_msg("Backing node not accessible\n");
+ ksft_test_result_skip("%s\n", tcase->name);
+ return KSFT_SKIP;
+ }
+
+ if (nommu && (tcase->mmap_flags & MAP_SHARED) &&
+ get_fs_type(tcase->pathname) != RAMFS_MAGIC) {
+ ksft_print_msg("Skip the test under non-ramfs filesystem (%s)\n",
+ tcase->pathname);
+ rc = KSFT_SKIP;
+ goto out;
+ }
+ }
+
+ addr = mmap(NULL, ps * old_pages, tcase->mmap_prot,
+ tcase->mmap_flags, fd, 0);
+ if (addr == MAP_FAILED) {
+ ksft_print_msg("mmap mapping failed %s(%d)\n", strerror(errno), errno);
+ rc = KSFT_FAIL;
+ goto out;
+ }
+
+ expected_error = nommu ? tcase->nommu_exp_err : tcase->exp_err;
+ if (tcase->resolve_exp_err && fd >= 0)
+ expected_error = tcase->resolve_exp_err(path);
+
+ addr2 = mremap(addr, ps * old_pages, ps * new_pages,
+ MREMAP_MAYMOVE);
+
+ if (expected_error != 0) {
+ if (addr2 != MAP_FAILED) {
+ ksft_print_msg("Expected error %d, but mremap unexpectedly succeeded\n",
+ expected_error);
+ rc = KSFT_FAIL;
+ } else if (errno != expected_error) {
+ ksft_print_msg("Expected error %d, got %s(%d)\n",
+ expected_error, strerror(errno), errno);
+ rc = KSFT_FAIL;
+ } else {
+ ksft_print_msg("%s: Handled expected error path (errno=%d)\n",
+ tcase->name, expected_error);
+ }
+ } else if (addr2 == MAP_FAILED) {
+ ksft_print_msg("mremap shrink failed unexpectedly: %s\n",
+ strerror(errno));
+ rc = KSFT_FAIL;
+ } else {
+ ksft_print_msg("%s step successful\n", tcase->name);
+ }
+
+ /* clean up */
+ if (munmap(addr2 == MAP_FAILED ? addr : addr2,
+ addr2 == MAP_FAILED ? ps * old_pages : ps * new_pages)) {
+ ksft_print_msg("munmap failed: %s\n", strerror(errno));
+ rc = KSFT_FAIL;
+ }
+
+out:
+ if (fd >= 0) {
+ close(fd);
+ if (tcase->pathname && strstr(tcase->pathname, "XXXXXX") &&
+ unlink(pb)) {
+ ksft_print_msg("unlink failed for %s: %s\n", pb, strerror(errno));
+ rc = KSFT_FAIL;
+ }
+ }
+
+ ksft_test_result_report(rc, "%s\n", tcase->name);
+ return rc;
+}
+
+int main(int argc, char **argv)
+{
+ int i;
+
+ nommu = ksft_is_nommu();
+ if (nommu < 0)
+ ksft_exit_skip("Cannot read /proc/meminfo; mount procfs at /proc\n");
+
+ ps = sysconf(_SC_PAGESIZE);
+ ksft_print_header();
+ ksft_set_plan(ARRAY_SIZE(mremap_cases) + 2);
+
+ munmap_shrink_test();
+ mremap_shrink_test();
+
+ for (i = 0; i < (int)ARRAY_SIZE(mremap_cases); i++)
+ run_mremap_test(&mremap_cases[i]);
+
+ ksft_finished();
+}
|
| 3/2 | 2026/10/06 09:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11468 output: 71 thoughts: 691 Thoughts: **Evaluating This Git Commit for Syzkaller Fuzzing** Alright, let's break this down. The task is to determine if this git commit is worth fuzzing with syzkaller. First, I need to understand the scope of the changes. The provided diff lists several modified files: `Documentation/dev-tools/kselftest.rst`, and a suite of files under `tools/testing/selftests/nommu/` and `tools/testing/selftests/kselftest/`. Now, I need to apply the established rules. I know there's a section on when to *not* consider a commit worthy of fuzzing – the negative criteria. Specifically, the rules state that I should return `WorthFuzzing=false` if *all* the modified code falls into certain categories. The relevant categories here are: changes to documentation, user-space tools, self-tests and scripts that don't affect the kernel image or modules. That's a key distinction. Looking at the files, it's immediately apparent that everything is confined to documentation and self-tests. Specifically, changes are happening in `Documentation/` and `tools/testing/selftests/`. I can confirm this against my mental model of the kernel source tree structure; nothing in the `mm/`, `kernel/`, `drivers/`, `fs/`, or `include/` directories is touched. This is a clear-cut case. These changes are strictly within the specified "not worth fuzzing" categories: documentation and user-space self-tests. They have zero impact on the compiled kernel image (vmlinux) or any kernel modules. I'm satisfied that a deeper git log dive isn't necessary here; the diff is comprehensive, and the path structure of modified files is unambiguous. Therefore, the conclusion is: `WorthFuzzing = false`. No kernel code is touched, so no configuration adjustments or symbol focus are needed. The rationale is straightforward: "The patch only modifies Documentation and kselftest selftests under tools/testing/selftests/, with no changes to the kernel image or modules." Now, I'll invoke the `set-results` tool with these findings. |
| 4/2 | 2026/10/06 09:43 | tool | set-results |
0mArgs:{
"EnableConfigs": [],
"FocusSymbols": [],
"Reasoning": "The patch only modifies documentation and kselftest user-space test files under tools/testing/selftests/, with no changes affecting the compiled kernel image (vmlinux) or kernel modules.",
"WorthFuzzing": false
}Results: {
"EnableConfigs": null,
"FocusSymbols": [],
"Reasoning": "The patch only modifies documentation and kselftest user-space test files under tools/testing/selftests/, with no changes affecting the compiled kernel image (vmlinux) or kernel modules.",
"WorthFuzzing": false
} |
| 5/1 | 2026/10/06 09:43 | action | If |
0mArgs:{
"WorthFuzzing": false
}Results: null |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|