linux/samples
Linus Torvalds 6205562c59 tracing fixes for 7.2:
- Free field in error path of synthetic event parse
 
   In __create_synth_event() the field was allocated but was not freed in the
   error path.
 
 - Fix ring_buffer_event_length() on 8 byte aligned architectures
 
   On architectures with CONFIG_HAVE_64BIT_ALIGNED_ACCESS set to y,
   the ring_buffer_event_length() may return the wrong size. This
   is because archs with that config set will always use the "big
   event meta header" as that is 8 bytes keeping the payload 8 bytes
   aligned, even when a 4 byte header could hold the size of the
   event.
 
   But ring_buffer_event_length() doesn't take this into account and only
   subtracts 4 bytes for the meta header in the length when it should have
   subtracted 8 bytes.
 
 - Have osnoise wait for a full rcu synchronization on unregister
 
   osnoise_unregister_instance() used to call synchronize_rcu() before
   freeing its copy of the instance but was switched to kfree_rcu().
   The osniose tracer has code that traverses the instances that it
   uses, and inst is just a pointer to that instance. By using kfree_rcu()
   instead of synchronize_rcu(), the instance that the inst pointer is
   pointing to can be freed while the osnoise code is still referencing it.
 
   That is, a rmdir on an instance first unregisters the tracer. When the
   unregister finishes, the rmdir expects that the tracer is finished with
   the instance that it is using. By putting back the synchronize_rcu()
   in osnoise_unregister_instance() the unregistering of osnoise will now
   return when all the users of the instance have finished.
 
 - Remove an unused setting of "ret" in tracing_set_tracer()
 
 - Fix ring_buffer_read_page() copying events
 
   The commit that changed ring_buffer_read_page() to show dropped events
   from the buffer itself, split the "commit" variable between the commit
   value (with flags) and "size" that holds the size of the sub-buffer.
   A cut and paste error changed the test of the reading from checking the
   size of the buffer to the size of the event causing reads to only read one
   event at a time.
 
 - Make tracepoint_printk a static variable
 
   When the tracing sysctl knobs were move from sysctl.c to trace.c, the
   variable tracepoint_printk no longer needed to be global. Make it static.
 
 - Fix some typos
 
 - Fix NULL pointer dereference in func_set_flag()
 
   The flags update of the function tracer first checks if the value of the
   flag is the same and exits if they are, and then it checks if the current
   tracer is the function tracer and exits if it isn't. The problem is that
   these checks need to be in a reversed order, as if the tracer isn't the
   function tracer, then the flag being checked may not exist. Reverse the
   order of these checks.
 
 - Fix ufs core trace events to not dereference a pointer in TP_printk()
 
   The TP_printk() part of the TRACE_EVENT() macro is called when the user
   reads the "trace" file. This can be seconds, minutes, hours, days, weeks,
   and even months after the data was recorded into the ring buffer. Thus,
   saving a pointer to an object into the ring buffer and then dereferencing
   it from TP_printk() can cause harm as the object the pointer is pointing
   to may no longer exist.
 
   Fix all the trace events in ufs core to save the device name in the ring
   buffer instead of dereferencing the device descriptor from TP_printk().
 
 - Prevent out-of-bound reads in glob matching of trace events
 
   The filter logic of events allows simple glob logic to add wild cards to
   filter on strings. But some events have fields that may not have a
   terminating 'nul' character. This may cause the glob matching to go beyond
   the string. Change the logic to always pass in the length of the field
   that is being matched.
 
 - Add no-rcu-check version of trace_##event##_enabled()
 
   The trace_##event##_enabled() usually wraps trace events to do extra work
   that is only needed when the trace event is enabled. But this can hide
   events that are placed in locations where RCU is not watching, and can
   make lockdep not see these bugs when the event is not enabled.
 
   The trace_##event##_enabled() was updated to always test to make sure RCU
   is watching to catch locations that may call events without RCU being
   active.
 
   This caused a false positive for the irq_disabled() and related events. As
   that use trace_irq_disabled_enabled() to force RCU to be watching when the
   event is enabled via the ct_irq_enter() function, calls the event, and
   then calls ct_irq_exit() to put RCU back to its original state.
 
   The trace_irq_disabled_enabled() should not trigger a warning when RCU is
   not watching because the code within its block handles the case properly.
   Make a __trace_##event##_enabled() version for this event to use that
   doesn't check RCU is watching as it handles the case when it isn't.
 
 - Fix use-after-free in user_event_mm_dup()
 
   When the enabler is removed from the link list, it is freed immediately.
   But it is protected via RCU and needs to be freed after an RCU
   grace period. Use queue_rcu_work() so that the event_mutex can also
   be taken as user_event_put() takes the mutex on the last reference
   is released.
 
 - Free type string in error path of parse_synth_field()
 
   There's an error path in parse_synth_field() where the allocated type
   string is not freed.
 
 - Add selftest that tests deferred event teardown
 
 - Fix leak in error path of trace_remote_alloc_buffer()
 
   If page allocation fails, the desc->nr_cpus is not incremented for the
   current CPU and the allocations done for it are not freed.
 
 - Fix allocation length in trace_remote_alloc_buffer()
 
   The logic to calculate the struct_len was doing a double count and setting
   the value too large. Calculate the size upfront to fix the error and
   simplify the logic.
 
 - Fix sparse CPU masks in ring_buffer_desc()
 
   If there are sparse CPUs (gaps in the numbering), the ring_buffer_desc()
   will fail as it tests the CPU number against the number of CPUs that are
   used.
 -----BEGIN PGP SIGNATURE-----
 
 iQJIBAABCgAyFiEEXtmkj8VMCiLR0IBM68Js21pW3nMFAmpTv/cUHHJvc3RlZHRA
 Z29vZG1pcy5vcmcACgkQ68Js21pW3nN80w/9HEbliUUrJVNw8QCY8BmeBEzfCRhZ
 2CeDzTg+UrLMb2BtqUhA9EjQnRPawe8mPxAfpZ750SdFnCkRhbfNwYmKar3M/8iW
 y2Bhsvd3Hz6nRiHvKhG/1RkflgKOWLYf/TQSByKlakYLV8t4uffa0fe0N0zcnikK
 XPGrhrTeRDJ7s94vb1u7p7mSSp2iy4ZhfXbagk966X3I4zvseIYNn5IIzyM3IIPT
 M7mE60SxvgSRz0QqTJqihmqjXYSeNOQ2iU18wnvp4QfcT0IVuLKm027JnK/YpjWS
 ZasMNGzO1kp5uo6hkXLrMlT3LjaNEMFTGogs1m9o9auhbMf443LK8GtZ1m1rwnTG
 cXn1PocBevQIaXWPbnxMrSwIuN7YMUqjgX6SCxbXpDxSSuE5i/x1VmE08CjxnSm6
 TdAdom9bE44FvMgaAz9+KhIUgm013c2rFDNiFroYtfkma5FqpfnfglA4/TkJvexY
 e2L75cR3lrDEDiXXMQDndmvxNMhppwNlAH3mOZLiaCmGyFQFHhgAaG250K2Y6a5K
 HtIfJkT6RQ3rWifV0E0+zlyRiOrvVCCA8WwNArWb1dTWrVU86Hr7q58jAq9p0Yrz
 FnhpjdE3eWoUHZ5f28AMR2k5lMG3o6mOGT55JyUVCLw+rPSG5358UIg2xZiEo22k
 RFlT26FFHbMW50Y=
 =+//w
 -----END PGP SIGNATURE-----

Merge tag 'trace-v7.2-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing fixes from Steven Rostedt:

 - Free field in error path of synthetic event parse

   In __create_synth_event() the field was allocated but was not freed
   in the error path

 - Fix ring_buffer_event_length() on 8 byte aligned architectures

   On architectures with CONFIG_HAVE_64BIT_ALIGNED_ACCESS set to y, the
   ring_buffer_event_length() may return the wrong size. This is because
   archs with that config set will always use the "big event meta
   header" as that is 8 bytes keeping the payload 8 bytes aligned, even
   when a 4 byte header could hold the size of the event

   But ring_buffer_event_length() doesn't take this into account and
   only subtracts 4 bytes for the meta header in the length when it
   should have subtracted 8 bytes

 - Have osnoise wait for a full rcu synchronization on unregister

   osnoise_unregister_instance() used to call synchronize_rcu() before
   freeing its copy of the instance but was switched to kfree_rcu(). The
   osniose tracer has code that traverses the instances that it uses,
   and inst is just a pointer to that instance. By using kfree_rcu()
   instead of synchronize_rcu(), the instance that the inst pointer is
   pointing to can be freed while the osnoise code is still referencing
   it

   That is, a rmdir on an instance first unregisters the tracer. When
   the unregister finishes, the rmdir expects that the tracer is
   finished with the instance that it is using. By putting back the
   synchronize_rcu() in osnoise_unregister_instance() the unregistering
   of osnoise will now return when all the users of the instance have
   finished

 - Remove an unused setting of "ret" in tracing_set_tracer()

 - Fix ring_buffer_read_page() copying events

   The commit that changed ring_buffer_read_page() to show dropped
   events from the buffer itself, split the "commit" variable between
   the commit value (with flags) and "size" that holds the size of the
   sub-buffer. A cut and paste error changed the test of the reading
   from checking the size of the buffer to the size of the event causing
   reads to only read one event at a time

 - Make tracepoint_printk a static variable

   When the tracing sysctl knobs were move from sysctl.c to trace.c, the
   variable tracepoint_printk no longer needed to be global. Make it
   static

 - Fix some typos

 - Fix NULL pointer dereference in func_set_flag()

   The flags update of the function tracer first checks if the value of
   the flag is the same and exits if they are, and then it checks if the
   current tracer is the function tracer and exits if it isn't. The
   problem is that these checks need to be in a reversed order, as if
   the tracer isn't the function tracer, then the flag being checked may
   not exist. Reverse the order of these checks

 - Fix ufs core trace events to not dereference a pointer in TP_printk()

   The TP_printk() part of the TRACE_EVENT() macro is called when the
   user reads the "trace" file. This can be seconds, minutes, hours,
   days, weeks, and even months after the data was recorded into the
   ring buffer. Thus, saving a pointer to an object into the ring buffer
   and then dereferencing it from TP_printk() can cause harm as the
   object the pointer is pointing to may no longer exist

   Fix all the trace events in ufs core to save the device name in the
   ring buffer instead of dereferencing the device descriptor from
   TP_printk()

 - Prevent out-of-bound reads in glob matching of trace events

   The filter logic of events allows simple glob logic to add wild cards
   to filter on strings. But some events have fields that may not have a
   terminating 'nul' character. This may cause the glob matching to go
   beyond the string. Change the logic to always pass in the length of
   the field that is being matched

 - Add no-rcu-check version of trace_##event##_enabled()

   The trace_##event##_enabled() usually wraps trace events to do extra
   work that is only needed when the trace event is enabled. But this
   can hide events that are placed in locations where RCU is not
   watching, and can make lockdep not see these bugs when the event is
   not enabled

   The trace_##event##_enabled() was updated to always test to make sure
   RCU is watching to catch locations that may call events without RCU
   being active

   This caused a false positive for the irq_disabled() and related
   events. As that use trace_irq_disabled_enabled() to force RCU to be
   watching when the event is enabled via the ct_irq_enter() function,
   calls the event, and then calls ct_irq_exit() to put RCU back to its
   original state

   The trace_irq_disabled_enabled() should not trigger a warning when
   RCU is not watching because the code within its block handles the
   case properly. Make a __trace_##event##_enabled() version for this
   event to use that doesn't check RCU is watching as it handles the
   case when it isn't

 - Fix use-after-free in user_event_mm_dup()

   When the enabler is removed from the link list, it is freed
   immediately. But it is protected via RCU and needs to be freed after
   an RCU grace period. Use queue_rcu_work() so that the event_mutex can
   also be taken as user_event_put() takes the mutex on the last
   reference is released

 - Free type string in error path of parse_synth_field()

   There's an error path in parse_synth_field() where the allocated type
   string is not freed

 - Add selftest that tests deferred event teardown

 - Fix leak in error path of trace_remote_alloc_buffer()

   If page allocation fails, the desc->nr_cpus is not incremented for
   the current CPU and the allocations done for it are not freed

 - Fix allocation length in trace_remote_alloc_buffer()

   The logic to calculate the struct_len was doing a double count and
   setting the value too large. Calculate the size upfront to fix the
   error and simplify the logic

 - Fix sparse CPU masks in ring_buffer_desc()

   If there are sparse CPUs (gaps in the numbering), the
   ring_buffer_desc() will fail as it tests the CPU number against the
   number of CPUs that are used

* tag 'trace-v7.2-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
  ring-buffer: Allow sparse CPU masks in ring_buffer_desc()
  tracing/remotes: Fix struct_len in trace_remote_alloc_buffer()
  tracing/remotes: Fix leak in trace_remote_alloc_buffer() error path
  selftests/user_events: Wait for deferred event teardown after unregister
  tracing/synthetic: Free type string on error path
  tracing/user_events: Fix use-after-free in user_event_mm_dup()
  tracing: Add a no-rcu-check version of trace_##event##_enabled()
  tracing: Prevent out-of-bounds read in glob matching
  ufs: core: tracing: Do not dereference pointers in TP_printk()
  tracing: Fix NULL pointer dereference in func_set_flag()
  samples: ftrace: Fix typos in benchmark comment
  tracing: Make tracepoint_printk static as not exported
  ring-buffer: Fix ring_buffer_read_page() copying only one event per page
  tracing: Remove unused ret assignment in tracing_set_tracer()
  tracing/osnoise: Call synchronize_rcu() when unregistering
  ring-buffer: Fix event length with forced 8-byte alignment
  tracing/synthetic: Free pending field on error path
2026-07-12 09:46:37 -07:00
..
acrn
auxdisplay
binderfs
bpf samples/bpf: Fix spelling typos in samples/bpf 2025-10-18 19:26:23 -07:00
cgroup samples/cgroup: rm unused MEMCG_EVENTS macro 2025-09-21 14:22:26 -07:00
check-exec
configfs samples: configfs: Constify struct configfs_item_operations and configfs_group_operations 2026-01-15 09:27:27 +01:00
connector
coresight
damon samples/damon/mtier: fail early if address range parameters are invalid 2026-07-01 19:02:56 -07:00
fanotify samples: fix building fs-monitor on musl systems 2025-07-28 18:14:15 +02:00
fprobe
ftrace samples: ftrace: Fix typos in benchmark comment 2026-07-07 10:42:28 -04:00
hid
hidraw
hung_task samples: enhance hung_task detector test with read-write semaphore support 2025-07-19 19:08:26 -07:00
hw_breakpoint
kdb
kfifo
kmemleak
kobject samples/kobject: constify 'struct foo_attribute' 2025-11-26 15:16:35 +01:00
kprobes
landlock samples/landlock: Add quiet flag support to sandboxer 2026-06-14 20:17:20 +02:00
livepatch
mei samples: mei: Fix building on musl libc 2025-07-16 14:17:47 +02:00
nitro_enclaves
pfsm
pidfd
pktgen
qmi samples: qmi: Use the unified QMI service ID instead of defining it locally 2026-03-15 20:54:39 -05:00
rpmsg
rust Char/Misc/IIO/FPGA/GPIB/etc driver updates for 7.2-rc1 2026-06-22 12:20:21 -07:00
seccomp
timers
trace_events tracing/events: Fix to check the simple_tsk_fn creation 2026-06-30 23:58:19 +09:00
trace_printk
tsm-mr sample/tsm-mr: Use SHA-2 library APIs 2026-03-19 10:57:15 -07:00
uhid
user_events
v4l media: v4l2-pci-skeleton: Rename second ioctl handlers argument to 'void *priv' 2025-08-13 08:33:59 +02:00
vfio-mdev vfio: Adapt drivers to use the core helper vfio_check_precopy_ioctl 2026-03-19 12:32:09 -06:00
vfs Significant patch series in this pull request: 2025-12-06 14:01:20 -08:00
watch_queue samples: work around glibc redefining some of our defines wrong 2025-11-21 09:29:02 -08:00
watchdog
workqueue/stall_detector workqueue: Add stall detector sample module 2026-03-05 07:30:49 -10:00
Kconfig sample/tsm-mr: Use SHA-2 library APIs 2026-03-19 10:57:15 -07:00
Makefile - The 11 patch series "Add folio_mk_pte()" from Matthew Wilcox 2025-05-31 15:44:16 -07:00