summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/user_events
diff options
context:
space:
mode:
authorBeau Belgrave <beaub@linux.microsoft.com>2023-04-26 00:51:04 +0200
committerSteven Rostedt (Google) <rostedt@goodmis.org>2023-04-26 03:03:46 +0200
commitcd98c93286a30cc4588dfd02453bec63c2f4acf4 (patch)
tree7bb663ac6965bdb99ddacaace92b5f52aebfbe2f /tools/testing/selftests/user_events
parentseq_buf: Add seq_buf_do_printk() helper (diff)
downloadlinux-cd98c93286a30cc4588dfd02453bec63c2f4acf4.tar.xz
linux-cd98c93286a30cc4588dfd02453bec63c2f4acf4.zip
tracing/user_events: Ensure write index cannot be negative
The write index indicates which event the data is for and accesses a per-file array. The index is passed by user processes during write() calls as the first 4 bytes. Ensure that it cannot be negative by returning -EINVAL to prevent out of bounds accesses. Update ftrace self-test to ensure this occurs properly. Link: https://lkml.kernel.org/r/20230425225107.8525-2-beaub@linux.microsoft.com Fixes: 7f5a08c79df3 ("user_events: Add minimal support for trace_event into ftrace") Reported-by: Doug Cook <dcook@linux.microsoft.com> Signed-off-by: Beau Belgrave <beaub@linux.microsoft.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Diffstat (limited to 'tools/testing/selftests/user_events')
-rw-r--r--tools/testing/selftests/user_events/ftrace_test.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/testing/selftests/user_events/ftrace_test.c
index aceafacfb126..91272f9d6fce 100644
--- a/tools/testing/selftests/user_events/ftrace_test.c
+++ b/tools/testing/selftests/user_events/ftrace_test.c
@@ -296,6 +296,11 @@ TEST_F(user, write_events) {
ASSERT_NE(-1, writev(self->data_fd, (const struct iovec *)io, 3));
after = trace_bytes();
ASSERT_GT(after, before);
+
+ /* Negative index should fail with EINVAL */
+ reg.write_index = -1;
+ ASSERT_EQ(-1, writev(self->data_fd, (const struct iovec *)io, 3));
+ ASSERT_EQ(EINVAL, errno);
}
TEST_F(user, write_fault) {