Skip to contentSkip to conversation

tracing: Fix missing trace_boot_init_histograms kstrdup NULL checks

PATCH In review Mathieu Desnoyers 3 participants 3 messages Oct 15, 2021 – Oct 26, 2021 Tracing

lore
Share & tools
lore

Mathieu Desnoyers

author reviewer
#0 lore raw

PATCH 1/1 tracing: Fix missing trace_boot_init_histograms kstrdup NULL checks

trace_boot_init_histograms misses NULL pointer checks for kstrdup failure.

---
 kernel/trace/trace_boot.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/trace_boot.c +4 -0
index 8d252f63cd78..0580287d7a0d 100644
@@ -430,6 +430,8 @@ trace_boot_init_histograms(struct trace_event_file *file,
 		/* All digit started node should be instances. */
 		if (trace_boot_compose_hist_cmd(node, buf, size) == 0) {
 			tmp = kstrdup(buf, GFP_KERNEL);
+			if (!tmp)
+				return;
 			if (trigger_process_regex(file, buf) < 0)
 				pr_err("Failed to apply hist trigger: %s\n", tmp);
 			kfree(tmp);
@@ -439,6 +441,8 @@ trace_boot_init_histograms(struct trace_event_file *file,
 	if (xbc_node_find_subkey(hnode, "keys")) {
 		if (trace_boot_compose_hist_cmd(hnode, buf, size) == 0) {
 			tmp = kstrdup(buf, GFP_KERNEL);
+			if (!tmp)
+				return;
 			if (trigger_process_regex(file, buf) < 0)
 				pr_err("Failed to apply hist trigger: %s\n", tmp);
 			kfree(tmp);
Signature · 1 line
2.20.1
maintainer
#1 lore raw
Quoted 5 lines · On Fri, 15 Oct 2021 15:55:50 -0400 Mathieu Desnoyers…

trace_boot_init_histograms misses NULL pointer checks for kstrdup failure.

Masami,

Can you ack this?

-- Steve

Quoted 26 lines
---
 kernel/trace/trace_boot.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/trace_boot.c +4 -0
index 8d252f63cd78..0580287d7a0d 100644
@@ -430,6 +430,8 @@ trace_boot_init_histograms(struct trace_event_file *file,
 		/* All digit started node should be instances. */
 		if (trace_boot_compose_hist_cmd(node, buf, size) == 0) {
 			tmp = kstrdup(buf, GFP_KERNEL);
+			if (!tmp)
+				return;
 			if (trigger_process_regex(file, buf) < 0)
 				pr_err("Failed to apply hist trigger: %s\n", tmp);
 			kfree(tmp);
@@ -439,6 +441,8 @@ trace_boot_init_histograms(struct trace_event_file *file,
 	if (xbc_node_find_subkey(hnode, "keys")) {
 		if (trace_boot_compose_hist_cmd(hnode, buf, size) == 0) {
 			tmp = kstrdup(buf, GFP_KERNEL);
+			if (!tmp)
+				return;
 			if (trigger_process_regex(file, buf) < 0)
 				pr_err("Failed to apply hist trigger: %s\n", tmp);
 			kfree(tmp);
maintainer Acked-by
#2 lore raw
Quoted 6 lines · On Mon, 25 Oct 2021 23:10:17 -0400 Steven Rostedt <[email protected]> wrote:
Quoted 3 lines · On Fri, 15 Oct 2021 15:55:50 -0400 Mathieu Desnoyers…

trace_boot_init_histograms misses NULL pointer checks for kstrdup failure.

Quoted 6 lines
Quoted 2 lines

Masami,

Can you ack this?

Yes, thanks for reporting this!

Thank you!

Quoted 30 lines

-- Steve

Quoted 26 lines
---
 kernel/trace/trace_boot.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/trace/trace_boot.c +4 -0
index 8d252f63cd78..0580287d7a0d 100644
@@ -430,6 +430,8 @@ trace_boot_init_histograms(struct trace_event_file *file,
 		/* All digit started node should be instances. */
 		if (trace_boot_compose_hist_cmd(node, buf, size) == 0) {
 			tmp = kstrdup(buf, GFP_KERNEL);
+			if (!tmp)
+				return;
 			if (trigger_process_regex(file, buf) < 0)
 				pr_err("Failed to apply hist trigger: %s\n", tmp);
 			kfree(tmp);
@@ -439,6 +441,8 @@ trace_boot_init_histograms(struct trace_event_file *file,
 	if (xbc_node_find_subkey(hnode, "keys")) {
 		if (trace_boot_compose_hist_cmd(hnode, buf, size) == 0) {
 			tmp = kstrdup(buf, GFP_KERNEL);
+			if (!tmp)
+				return;
 			if (trigger_process_regex(file, buf) < 0)
 				pr_err("Failed to apply hist trigger: %s\n", tmp);
 			kfree(tmp);
Signature · 1 line
Masami Hiramatsu <[email protected]>