[PATCH 1/4] rt-tests: cyclicdeadline: fix segmentation fault on close

Kurt Kanzenbach
2019-04-04T13:48:43Z

The current code generates a segmentation fault in the last free() call.

$ sudo ./cyclicdeadline
Using all CPUS
/sys/kernel/debug/sched_features: Success
interval: 600:1000
Tested at 5us of 600us
deadline thread 2963
thread[2963] runtime=600us deadline=1000us
main thread 2962
fail 2 0
T: 0 ( 2963) I:1000 C: 1268 Min: 7 Act: 55 Avg: 56 Max: 256
[1] 2961 segmentation fault sudo ./cyclicdeadline

This is caused by a buffer overflow in setup_ftrace_marker(). The appended
string is 21 not 14 characters wide. Fix it by using strlen() like the other
function do.

Signed-off-by: Kurt Kanzenbach <kurt@linutronix.de>
---
src/sched_deadline/cyclicdeadline.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 08460107c464..303b5e96647a 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -283,7 +283,7 @@ static void setup_ftrace_marker(void)
{
struct stat st;
const char *debugfs = find_debugfs();
- char files[strlen(debugfs) + 14];
+ char files[strlen(debugfs) + strlen("/tracing/trace_marker") + 1];
int ret;

if (strlen(debugfs) == 0)
--
2.11.0