Patch "tracing/user_events: Ensure write index cannot be negative" has been added to the 6.2-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    tracing/user_events: Ensure write index cannot be negative

to the 6.2-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     tracing-user_events-ensure-write-index-cannot-be-neg.patch
and it can be found in the queue-6.2 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 9c3a74bd3208566652109977459a54699d909421
Author: Beau Belgrave <beaub@xxxxxxxxxxxxxxxxxxx>
Date:   Tue Apr 25 15:51:04 2023 -0700

    tracing/user_events: Ensure write index cannot be negative
    
    [ Upstream commit cd98c93286a30cc4588dfd02453bec63c2f4acf4 ]
    
    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@xxxxxxxxxxxxxxxxxxx
    
    Fixes: 7f5a08c79df3 ("user_events: Add minimal support for trace_event into ftrace")
    Reported-by: Doug Cook <dcook@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Beau Belgrave <beaub@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Steven Rostedt (Google) <rostedt@xxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/kernel/trace/trace_events_user.c b/kernel/trace/trace_events_user.c
index 908e8a13c675b..625cab4b9d945 100644
--- a/kernel/trace/trace_events_user.c
+++ b/kernel/trace/trace_events_user.c
@@ -1398,6 +1398,9 @@ static ssize_t user_events_write_core(struct file *file, struct iov_iter *i)
 	if (unlikely(copy_from_iter(&idx, sizeof(idx), i) != sizeof(idx)))
 		return -EFAULT;
 
+	if (idx < 0)
+		return -EINVAL;
+
 	rcu_read_lock_sched();
 
 	refs = rcu_dereference_sched(info->refs);
diff --git a/tools/testing/selftests/user_events/ftrace_test.c b/tools/testing/selftests/user_events/ftrace_test.c
index 404a2713dcae8..1bc26e6476fc3 100644
--- a/tools/testing/selftests/user_events/ftrace_test.c
+++ b/tools/testing/selftests/user_events/ftrace_test.c
@@ -294,6 +294,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) {



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux