aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/coredump/stackdump_test.c
diff options
context:
space:
mode:
authorChristian Brauner <[email protected]>2025-06-12 13:25:22 +0000
committerChristian Brauner <[email protected]>2025-06-16 15:01:22 +0000
commit8a25350fa430a28d0595a6d14af661d4f151b123 (patch)
treef04bcedb07bd5bc40c758495e8afe9a1556c1929 /tools/testing/selftests/coredump/stackdump_test.c
parentcoredump: validate socket path in coredump_parse() (diff)
downloadkernel-8a25350fa430a28d0595a6d14af661d4f151b123.tar.gz
kernel-8a25350fa430a28d0595a6d14af661d4f151b123.zip
selftests/coredump: make sure invalid paths are rejected
Link: https://lore.kernel.org/[email protected] Signed-off-by: Christian Brauner <[email protected]>
Diffstat (limited to 'tools/testing/selftests/coredump/stackdump_test.c')
-rw-r--r--tools/testing/selftests/coredump/stackdump_test.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/tools/testing/selftests/coredump/stackdump_test.c b/tools/testing/selftests/coredump/stackdump_test.c
index 9a789156f27e..a4ac80bb1003 100644
--- a/tools/testing/selftests/coredump/stackdump_test.c
+++ b/tools/testing/selftests/coredump/stackdump_test.c
@@ -241,16 +241,19 @@ out:
static bool set_core_pattern(const char *pattern)
{
- FILE *file;
- int ret;
+ int fd;
+ ssize_t ret;
- file = fopen("/proc/sys/kernel/core_pattern", "w");
- if (!file)
+ fd = open("/proc/sys/kernel/core_pattern", O_WRONLY | O_CLOEXEC);
+ if (fd < 0)
return false;
- ret = fprintf(file, "%s", pattern);
- fclose(file);
+ ret = write(fd, pattern, strlen(pattern));
+ close(fd);
+ if (ret < 0)
+ return false;
+ fprintf(stderr, "Set core_pattern to '%s' | %zu == %zu\n", pattern, ret, strlen(pattern));
return ret == strlen(pattern);
}
@@ -1804,4 +1807,21 @@ out:
wait_and_check_coredump_server(pid_coredump_server, _metadata, self);
}
+TEST_F(coredump, socket_invalid_paths)
+{
+ ASSERT_FALSE(set_core_pattern("@ /tmp/coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@/tmp/../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@/tmp/coredump.socket/.."));
+ ASSERT_FALSE(set_core_pattern("@.."));
+
+ ASSERT_FALSE(set_core_pattern("@@ /tmp/coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@@/tmp/../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@@../coredump.socket"));
+ ASSERT_FALSE(set_core_pattern("@@/tmp/coredump.socket/.."));
+ ASSERT_FALSE(set_core_pattern("@@.."));
+
+ ASSERT_FALSE(set_core_pattern("@@@/tmp/coredump.socket"));
+}
+
TEST_HARNESS_MAIN