Steven Rostedt (Google)
6a42eb0d21
tracing: Inform kmemleak of saved_cmdlines allocation
...
commit 2394ac4145ea91b92271e675a09af2a9ea6840b7 upstream.
The allocation of the struct saved_cmdlines_buffer structure changed from:
s = kmalloc(sizeof(*s), GFP_KERNEL);
s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL);
to:
orig_size = sizeof(*s) + val * TASK_COMM_LEN;
order = get_order(orig_size);
size = 1 << (order + PAGE_SHIFT);
page = alloc_pages(GFP_KERNEL, order);
if (!page)
return NULL;
s = page_address(page);
memset(s, 0, sizeof(*s));
s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL);
Where that s->saved_cmdlines allocation looks to be a dangling allocation
to kmemleak. That's because kmemleak only keeps track of kmalloc()
allocations. For allocations that use page_alloc() directly, the kmemleak
needs to be explicitly informed about it.
Add kmemleak_alloc() and kmemleak_free() around the page allocation so
that it doesn't give the following false positive:
unreferenced object 0xffff8881010c8000 (size 32760):
comm "swapper", pid 0, jiffies 4294667296
hex dump (first 32 bytes):
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................
backtrace (crc ae6ec1b9):
[<ffffffff86722405>] kmemleak_alloc+0x45/0x80
[<ffffffff8414028d>] __kmalloc_large_node+0x10d/0x190
[<ffffffff84146ab1>] __kmalloc+0x3b1/0x4c0
[<ffffffff83ed7103>] allocate_cmdlines_buffer+0x113/0x230
[<ffffffff88649c34>] tracer_alloc_buffers.isra.0+0x124/0x460
[<ffffffff8864a174>] early_trace_init+0x14/0xa0
[<ffffffff885dd5ae>] start_kernel+0x12e/0x3c0
[<ffffffff885f5758>] x86_64_start_reservations+0x18/0x30
[<ffffffff885f582b>] x86_64_start_kernel+0x7b/0x80
[<ffffffff83a001c3>] secondary_startup_64_no_verify+0x15e/0x16b
Link: https://lore.kernel.org/linux-trace-kernel/87r0hfnr9r.fsf@kernel.org/
Link: https://lore.kernel.org/linux-trace-kernel/20240214112046.09a322d6@gandalf.local.home
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Fixes: 44dc5c41b5b1 ("tracing: Fix wasted memory in saved_cmdlines logic")
Reported-by: Kalle Valo <kvalo@kernel.org>
Tested-by: Kalle Valo <kvalo@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-02-23 08:42:30 +01:00
..
2024-02-23 08:42:07 +01:00
2023-10-25 11:54:16 +02:00
2024-01-25 14:37:56 -08:00
2024-01-25 14:37:45 -08:00
2023-01-04 11:39:22 +01:00
2024-02-23 08:42:15 +01:00
2023-11-20 11:06:44 +01:00
2023-01-14 10:16:24 +01:00
2023-11-28 16:54:58 +00:00
2023-07-27 08:43:57 +02:00
2023-11-20 11:06:52 +01:00
2023-12-08 08:46:09 +01:00
2024-02-23 08:41:52 +01:00
2023-09-19 12:20:21 +02:00
2023-11-28 16:54:57 +00:00
2023-11-20 11:06:43 +01:00
2024-02-23 08:42:22 +01:00
2024-02-23 08:42:30 +01:00
2021-05-11 14:47:37 +02:00
2023-01-14 10:16:14 +01:00
2024-02-23 08:41:53 +01:00
2022-08-31 17:15:13 +02:00
2021-09-03 10:09:31 +02:00
2023-11-28 16:54:56 +00:00
2024-02-23 08:42:03 +01:00
2022-04-08 14:40:00 +02:00
2020-08-23 17:36:59 -05:00
2023-09-19 12:20:13 +02:00
2020-10-13 09:17:34 -07:00
2023-04-05 11:23:45 +02:00
2021-09-15 09:50:40 +02:00
2023-12-13 18:26:56 +01:00
2021-06-23 14:42:52 +02:00
2023-12-20 15:44:30 +01:00
2023-02-01 08:23:21 +01:00
2023-03-11 16:40:18 +01:00
2023-09-23 11:01:05 +02:00
2021-04-07 15:00:14 +02:00
2020-10-13 09:17:34 -07:00
2020-11-02 12:14:19 -08:00
2021-07-20 16:05:58 +02:00
2020-10-25 14:51:49 -07:00
2021-01-09 13:46:24 +01:00
2020-08-12 10:58:02 -07:00
2023-07-27 08:43:40 +02:00
2023-06-21 15:45:37 +02:00
2023-04-20 12:10:29 +02:00
2023-04-20 12:10:29 +02:00
2023-05-17 11:47:33 +02:00
2020-08-12 10:58:01 -07:00
2024-01-25 14:37:51 -08:00
2023-04-20 12:10:29 +02:00
2021-09-03 10:09:31 +02:00
2023-01-14 10:15:20 +01:00
2021-03-25 09:04:11 +01:00
2021-03-25 09:04:11 +01:00
2023-09-19 12:20:02 +02:00
2020-09-01 09:58:03 +02:00
2023-11-28 16:54:51 +00:00
2023-02-01 08:23:21 +01:00
2020-10-29 17:22:59 -05:00
2023-03-11 16:39:19 +01:00
2021-01-09 13:46:24 +01:00
2022-08-21 15:16:05 +02:00
2022-06-09 10:20:49 +02:00
2020-10-16 11:11:19 -07:00
2023-11-28 16:54:58 +00:00
2023-05-17 11:47:34 +02:00
2023-03-11 16:40:04 +01:00
2022-04-08 14:40:03 +02:00
2023-09-23 11:01:05 +02:00
2020-08-07 11:33:25 -07:00
2021-08-18 08:59:06 +02:00
2023-01-04 11:39:23 +01:00
2022-04-20 09:23:29 +02:00
2021-07-14 16:55:50 +02:00
2020-09-16 15:18:56 +02:00
2022-02-23 12:01:00 +01:00
2020-09-18 14:24:16 +01:00
2021-09-08 08:49:00 +02:00
2020-10-26 12:12:27 +01:00
2022-08-31 17:15:13 +02:00
2023-04-26 11:27:38 +02:00
2023-06-28 10:28:09 +02:00
2023-01-04 11:39:23 +01:00
2020-10-02 19:11:12 -07:00
2023-08-30 16:23:17 +02:00
2021-09-03 10:09:30 +02:00
2022-01-27 10:54:33 +01:00
2021-09-08 08:49:00 +02:00
2020-10-06 10:31:52 -07:00
2021-05-14 09:50:46 +02:00
2021-09-08 08:49:00 +02:00
2021-03-30 14:32:03 +02:00
2023-03-17 08:45:13 +01:00
2023-07-27 08:43:40 +02:00
2023-11-28 16:54:56 +00:00
2023-12-08 08:46:13 +01:00