kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bug report] tracing: Add a probe that attaches to trace events
@ 2021-08-24 11:42 Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2021-08-24 11:42 UTC (permalink / raw)
  To: tz.stoyanov; +Cc: Steven Rostedt, kernel-janitors

Hello Tzvetomir Stoyanov (VMware),

The patch 7491e2c44278: "tracing: Add a probe that attaches to trace
events" from Aug 19, 2021, leads to the following
Smatch static checker warning:

	kernel/trace/trace_eprobe.c:664 enable_trace_eprobe()
	error: we previously assumed 'file' could be null (see line 652)

kernel/trace/trace_eprobe.c
    638 static int enable_trace_eprobe(struct trace_event_call *call,
    639 			       struct trace_event_file *file)
    640 {
    641 	struct trace_probe *pos, *tp;
    642 	struct trace_eprobe *ep;
    643 	bool enabled;
    644 	int ret = 0;
    645 
    646 	tp = trace_probe_primary_from_call(call);
    647 	if (WARN_ON_ONCE(!tp))
    648 		return -ENODEV;
    649 	enabled = trace_probe_is_enabled(tp);
    650 
    651 	/* This also changes "enabled" state */

Since adding a file sets it to enabled, then shouldn't we set
enabled = true on this path?

    652 	if (file) {
                    ^^^^
Check for NULL

    653 		ret = trace_probe_add_file(tp, file);
    654 		if (ret)
    655 			return ret;
    656 	} else
    657 		trace_probe_set_flag(tp, TP_FLAG_PROFILE);
    658 
    659 	if (enabled)
    660 		return 0;
    661 
    662 	list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
    663 		ep = container_of(pos, struct trace_eprobe, tp);
--> 664 		ret = enable_eprobe(ep, file);
                                                ^^^^
Unchecked dereference.  See also:

kernel/trace/trace_eprobe.c:705 disable_trace_eprobe() error: we previously assumed 'file' could be null (see line 693)

    665 		if (ret)
    666 			break;
    667 		enabled = true;
    668 	}
    669 
    670 	if (ret) {
    671 		/* Failed to enable one of them. Roll back all */
    672 		if (enabled)
    673 			disable_eprobe(ep, file->tr);
    674 		if (file)
    675 			trace_probe_remove_file(tp, file);
    676 		else
    677 			trace_probe_clear_flag(tp, TP_FLAG_PROFILE);
    678 	}
    679 
    680 	return ret;
    681 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread
* [bug report] tracing: Add a probe that attaches to trace events
@ 2021-08-24  9:07 Dan Carpenter
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Carpenter @ 2021-08-24  9:07 UTC (permalink / raw)
  To: tz.stoyanov; +Cc: kernel-janitors

Hello Tzvetomir Stoyanov (VMware),

This is a semi-automatic email about new static checker warnings.

The patch 7491e2c44278: "tracing: Add a probe that attaches to trace
events" from Aug 19, 2021, leads to the following Smatch complaint:

    kernel/trace/trace_eprobe.c:674 enable_trace_eprobe()
    warn: variable dereferenced before check 'file' (see line 664)

kernel/trace/trace_eprobe.c
   638  static int enable_trace_eprobe(struct trace_event_call *call,
   639                                 struct trace_event_file *file)
   640  {
   641          struct trace_probe *pos, *tp;
   642          struct trace_eprobe *ep;
   643          bool enabled;
   644          int ret = 0;
   645  
   646          tp = trace_probe_primary_from_call(call);
   647          if (WARN_ON_ONCE(!tp))
   648                  return -ENODEV;
   649          enabled = trace_probe_is_enabled(tp);
   650  
   651          /* This also changes "enabled" state */
   652          if (file) {
   653                  ret = trace_probe_add_file(tp, file);
   654                  if (ret)
   655                          return ret;
   656          } else
   657                  trace_probe_set_flag(tp, TP_FLAG_PROFILE);
   658  
   659          if (enabled)
   660                  return 0;
   661  
   662          list_for_each_entry(pos, trace_probe_probe_list(tp), list) {
   663			ep = container_of(pos, struct trace_eprobe, tp);
   664			ret = enable_eprobe(ep, file);
                                                ^^^^
"file" is dereferenced here.

   665			if (ret)
   666				break;
   667			enabled = true;
   668		}
   669	
   670		if (ret) {
   671			/* Failed to enable one of them. Roll back all */
   672			if (enabled)
   673				disable_eprobe(ep, file->tr);
   674			if (file)
                            ^^^^
This check is too late.

   675				trace_probe_remove_file(tp, file);
   676			else

regards,
dan carpenter

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

end of thread, other threads:[~2021-08-24 11:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 11:42 [bug report] tracing: Add a probe that attaches to trace events Dan Carpenter
  -- strict thread matches above, loose matches on Subject: below --
2021-08-24  9:07 Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).