public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH 0/2] Two tracing patches for trace_events_hist.c
@ 2022-04-17 18:53 Ammar Faizi
  2022-04-17 18:53 ` [PATCH 1/2] tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse() Ammar Faizi
  2022-04-17 18:53 ` [PATCH 2/2] tracing: Change `if (strlen(glob))` to `if (glob[0])` Ammar Faizi
  0 siblings, 2 replies; 3+ messages in thread
From: Ammar Faizi @ 2022-04-17 18:53 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar
  Cc: Ammar Faizi, GNU/Weeb Mailing List, Linux Kernel Mailing List,
	Linux Trace Devel Mailing List

Hi,

Two patches here.

## Patch 1
If `WARN_ON(!glob)` is ever triggered, we will still continue executing
the next lines. This will trigger the more serious problem, a NULL
pointer dereference bug. Just return -EINVAL if @glob is NULL.

## Patch 2
Change `if (strlen(glob))` to `if (glob[0])`. No need to traverse to
the end of string. If the first byte is not a NUL char, it's
guaranteed `if (strlen(glob))` is true.


Signed-off-by: Ammar Faizi <[email protected]>
---

Ammar Faizi (2):
  tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse()
  tracing: Change `if (strlen(glob))` to `if (glob[0])`

 kernel/trace/trace_events_hist.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)


base-commit: a1901b464e7e3e28956ae7423db2847dbbfb5be8
-- 
Ammar Faizi


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse()
  2022-04-17 18:53 [PATCH 0/2] Two tracing patches for trace_events_hist.c Ammar Faizi
@ 2022-04-17 18:53 ` Ammar Faizi
  2022-04-17 18:53 ` [PATCH 2/2] tracing: Change `if (strlen(glob))` to `if (glob[0])` Ammar Faizi
  1 sibling, 0 replies; 3+ messages in thread
From: Ammar Faizi @ 2022-04-17 18:53 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar
  Cc: Ammar Faizi, GNU/Weeb Mailing List, Linux Kernel Mailing List,
	Linux Trace Devel Mailing List

If `WARN_ON(!glob)` is ever triggered, we will still continue executing
the next lines. This will trigger the more serious problem, a NULL
pointer dereference bug.

Just return -EINVAL if @glob is NULL.

Signed-off-by: Ammar Faizi <[email protected]>
---
 kernel/trace/trace_events_hist.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 44db5ba9cabb..0b99ad68e3fa 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -6186,7 +6186,8 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 
 	lockdep_assert_held(&event_mutex);
 
-	WARN_ON(!glob);
+	if (WARN_ON(!glob))
+		return -EINVAL;
 
 	if (strlen(glob)) {
 		hist_err_clear();
-- 
Ammar Faizi


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] tracing: Change `if (strlen(glob))` to `if (glob[0])`
  2022-04-17 18:53 [PATCH 0/2] Two tracing patches for trace_events_hist.c Ammar Faizi
  2022-04-17 18:53 ` [PATCH 1/2] tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse() Ammar Faizi
@ 2022-04-17 18:53 ` Ammar Faizi
  1 sibling, 0 replies; 3+ messages in thread
From: Ammar Faizi @ 2022-04-17 18:53 UTC (permalink / raw)
  To: Steven Rostedt, Ingo Molnar
  Cc: Ammar Faizi, GNU/Weeb Mailing List, Linux Kernel Mailing List,
	Linux Trace Devel Mailing List

No need to traverse to the end of string. If the first byte is not a NUL
char, it's guaranteed `if (strlen(glob))` is true.

Signed-off-by: Ammar Faizi <[email protected]>
---
 kernel/trace/trace_events_hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 0b99ad68e3fa..1968e497ef44 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -6189,7 +6189,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 	if (WARN_ON(!glob))
 		return -EINVAL;
 
-	if (strlen(glob)) {
+	if (glob[0]) {
 		hist_err_clear();
 		last_cmd_set(file, param);
 	}
-- 
Ammar Faizi


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-17 18:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-17 18:53 [PATCH 0/2] Two tracing patches for trace_events_hist.c Ammar Faizi
2022-04-17 18:53 ` [PATCH 1/2] tracing: Return -EINVAL if WARN_ON(!glob) triggered in event_hist_trigger_parse() Ammar Faizi
2022-04-17 18:53 ` [PATCH 2/2] tracing: Change `if (strlen(glob))` to `if (glob[0])` Ammar Faizi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox