FAILED: patch "[PATCH] tracing: Fix return value of trace_pid_write()" failed to apply to 5.4-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From b27f266f74fbda4ee36c2b2b04d15992860cf23b Mon Sep 17 00:00:00 2001
From: Wonhyuk Yang <[email protected]>
Date: Tue, 3 May 2022 14:05:46 +0900
Subject: [PATCH] tracing: Fix return value of trace_pid_write()
Setting set_event_pid with trailing whitespace lead to endless write system calls like below.
$ strace echo "123 " > /sys/kernel/debug/tracing/set_event_pid
execve("/usr/bin/echo", ["echo", "123 "], ...) = 0
...
write(1, "123 \n", 5) = 4
write(1, "\n", 1) = 0
write(1, "\n", 1) = 0
write(1, "\n", 1) = 0
write(1, "\n", 1) = 0
write(1, "\n", 1) = 0
....This is because, the result of trace_get_user's are not returned when it read at least one pid. To fix it, update read variable even if parser->idx == 0.
The result of applied patch is below.
$ strace echo "123 " > /sys/kernel/debug/tracing/set_event_pid
execve("/usr/bin/echo", ["echo", "123 "], ...) = 0
...
write(1, "123 \n", 5) = 5
close(1) = 0kernel/trace/trace.c +4 -2
@@ -721,13 +721,16 @@ int trace_pid_write(struct trace_pid_list *filtered_pids, pos =0 ; ret =trace_get_user (&parser, ubuf, cnt, &pos); -if (ret <0 || !trace_parser_loaded (&parser)) +if (ret <0 )break ; read += ret; ubuf += ret; cnt -= ret; +if (!trace_parser_loaded (&parser)) +break ; + ret = -EINVAL ;if (kstrtoul (parser.buffer,0 , &val))break ;
@@ -753,7 +756,6 @@ int trace_pid_write(struct trace_pid_list *filtered_pids,if (!nr_pids) {/* Cleared the list of pids */ trace_pid_list_free (pid_list); - read = ret; pid_list =NULL ; }