@@ -77,3 +77,5 @@ cve-2022-2590 dirtyc0w_shmem
# Tests below may cause kernel memory leak
cve-2020-25704 perf_event_open03
cve-2022-4378 cve-2022-4378
+# Tests below may cause kernel crash
+cve-2022-0185 fsconfig03
@@ -383,6 +383,7 @@ fremovexattr02 fremovexattr02
fsconfig01 fsconfig01
fsconfig02 fsconfig02
+fsconfig03 fsconfig03
fsmount01 fsmount01
fsmount02 fsmount02
@@ -1,2 +1,3 @@
/fsconfig01
/fsconfig02
+/fsconfig03
new file mode 100644
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Alejandro Guerrero <aguerrero@...lys.com>
+ * Copyright (c) 2023 Wei Gao <wegao@suse.com>
+ */
+
+
+/*\
+ * [Description]
+ *
+ * Test for CVE-2022-0185.
+ *
+ * References links:
+ * - https://www.openwall.com/lists/oss-security/2022/01/25/14
+ * - https://github.com/Crusaders-of-Rust/CVE-2022-0185
+ */
+
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+
+#define MNTPOINT "mntpoint"
+
+static int fd = -1;
+
+static void setup(void)
+{
+ fsopen_supported_by_kernel();
+}
+
+static void run(void)
+{
+ char *val = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
+ long pagesize;
+
+ TEST(fd = fsopen(tst_device->fs_type, 0));
+ if (fd == -1)
+ tst_brk(TBROK | TTERRNO, "fsopen() failed");
+
+ pagesize = sysconf(_SC_PAGESIZE);
+ if (pagesize == -1)
+ tst_brk(TBROK, "sysconf(_SC_PAGESIZE) failed");
+
+ for (size_t i = 0; i < 5000; i++) {
+ /* use same logic in kernel legacy_parse_param function */
+ const size_t len = i * (strlen(val) + 2) + (strlen(val) + 1) + 2;
+
+ if (!strcmp(tst_device->fs_type, "btrfs") && len <= (size_t)pagesize) {
+ TST_EXP_PASS_SILENT(fsconfig(fd, FSCONFIG_SET_STRING, "\x00", val, 0));
+ if (TST_ERR)
+ return;
+ } else {
+ TST_EXP_FAIL_SILENT(fsconfig(fd, FSCONFIG_SET_STRING, "\x00", val, 0),
+ EINVAL);
+ if (!TST_PASS)
+ return;
+ }
+ }
+
+ if (fd != -1)
+ SAFE_CLOSE(fd);
+
+ tst_res(TPASS, "fsconfig() overflow on %s haven't triggerred crash",
+ tst_device->fs_type);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .needs_root = 1,
+ .format_device = 1,
+ .mntpoint = MNTPOINT,
+ .all_filesystems = 1,
+ .skip_filesystems = (const char *const []){"ntfs", "vfat", NULL},
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "722d94847de29"},
+ {"CVE", "2022-0185"},
+ {}
+ }
+};