Files
android_kernel_motorola_sm6225/kernel/tracepoint.c
T
Nolen Johnson 59241bf898 Merge tag 'v4.19.325-cip135' of https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip into android13-4.19-kona
version 4.19.325-cip135

* tag 'v4.19.325-cip135' of https://git.kernel.org/pub/scm/linux/kernel/git/cip/linux-cip:
  CIP: Bump version suffix to -cip135 after merge from cip/linux-4.19.y-st tree
  Update localversion-st, tree is up-to-date with 5.10.260.
  nfsd: fix posix_acl leak on SETACL decode failure
  batman-adv: tp_meter: prevent parallel modifications of last_recv
  batman-adv: tp_meter: restrict number of unacked list entries
  batman-adv: bla: annotate lasttime access with READ/WRITE_ONCE
  net/sched: fix pedit partial COW leading to page cache corruption
  net/sched: act_api: use RCU with deferred freeing for action lifecycle
  arm64: errata: Mitigate TLBI errata on various Arm CPUs
  arm64: Add part number for Arm Cortex-A78AE
  arm64: cpufeature: Enable Qualcomm Falkor errata 1009 for Kryo
  arm64: Add workaround for Cortex-A76 erratum 1286807
  iio: gyro: adis16260: fix division by zero in write_raw
  scsi: target: iscsi: Fix CRC overread and double-free in iscsit_handle_text_cmd()
  netfilter: nf_queue: hold bridge skb->dev while queued
  batman-adv: stop tp_meter sessions during mesh teardown
  Bluetooth: L2CAP: reject BR/EDR signaling packets over MTUsig
  xfrm: esp: restore combined single-frag length gate
  batman-adv: tt: avoid empty VLAN responses
  batman-adv: tt: fix TOCTOU race for reported vlans
  KVM: SVM: Fix page overflow in sev_dbg_crypt() for ENCRYPT path
  mtd: spi-nor: sst: Fix write enable before AAI sequence
  sched: Use u64 for bandwidth ratio calculations
  net: phonet: free phonet_device after RCU grace period
  phonet: Pass net and ifindex to phonet_address_notify().
  phonet: Pass ifindex to fill_addr().
  hv: utils: handle and propagate errors in kvp_register
  bnxt_en: Fix NULL pointer dereference
  bnxt_en: Modify bnxt_disable_int_sync() to be called more than once.
  dlm: prevent NPD when writing a positive value to event_done
  fbdev: modedb: Fix misaligned fields in the 1920x1080-60 mode
  ocfs2: reject oversized group bitmap descriptors
  fpga: region: fix use-after-free in child_regions_with_firmware()
  f2fs: validate ACL entry sizes in f2fs_acl_from_disk()
  mac802154: llsec: add skb_cow_data() before in-place crypto
  ext4: add bounds check for inline data length in ext4_read_inline_page
  batman-adv: tvlv: avoid race of cifsnotfound handler state
  batman-adv: tvlv: enforce 2-byte alignment
  batman-adv: dat: prevent false sharing between VLANs
  batman-adv: tt: track roam count per VID
  batman-adv: tt: don't merge change entries with different VIDs
  batman-adv: tp_meter: annotate last_recv_time access with READ/WRITE_ONCE
  batman-adv: frag: avoid underflow of TTL
  batman-adv: frag: ensure fragment is writable before modifying TTL
  batman-adv: tp_meter: initialize last_recv_time during init
  batman-adv: tp_meter: add only finished tp_vars to lists
  batman-adv: tp_meter: handle seqno wrap-around for fast recovery detection
  batman-adv: tp_meter: fix fast recovery precondition
  batman-adv: tp_meter: avoid divide-by-zero for dec_cwnd
  batman-adv: tp_meter: avoid window underflow
  batman-adv: tp_meter: initialize dec_cwnd explicitly
  batman-adv: tp_meter: initialize dup_acks explicitly
  batman-adv: tp_meter: keep unacked list in ascending ordered
  crypto: qat - Return pointer directly in adf_ctl_alloc_resources
  crypto: qat - Replace kzalloc() + copy_from_user() with memdup_user()
  vc_screen: fix null-ptr-deref in vcs_notifier() during concurrent vcs_write
  agp/amd64: Fix broken error propagation in agp_amd64_probe()
  net: qualcomm: rmnet: fix endpoint use-after-free in rmnet_dellink()
  i2c: stub: Reject I2C block transfers with invalid length
  RDMA/bnxt_re: zero shared page before exposing to userspace
  batman-adv: tt: reject oversized local TVLV buffers
  net: 9p: fix refcount leak in p9_read_work() error handling
  drm/amd/display: Use krealloc_array() in dal_vector_reserve()
  net/sched: cls_u32: use skb_header_pointer_careful()
  net: add skb_header_pointer_careful() helper
  ip6_vti: set netns_immutable on the fallback device.
  drm/amd/display: Bound VBIOS record-chain walk loops
  fuse: limit FUSE_NOTIFY_RETRIEVE to uptodate folios
  media: rc: igorplugusb: fix control request setup packet
  media: rc: ttusbir: fix inverted error logic
  x86/CPU/AMD: Move the Zen3 BTC_NO detection to the Zen3 init function
  apparmor: validate default DFA states are in bounds
  arm64: cputype: Add C1-Premium definitions
  arm64: cputype: Add C1-Ultra definitions
  lib/crypto: mpi: Fix integer underflow in mpi_read_raw_from_sgl()
  usb: gadget: f_hid: fix device reference leak in hidg_alloc()
  usb: gadget: f_hid: tidy error handling in hidg_alloc
  net: skbuff: fix missing zerocopy reference in pskb_carve helpers
  iio: dac: ad5686: fix ref bit initialization for single-channel parts
  Bluetooth: L2CAP: use chan timer to close channels in cleanup_listen()
  mm/huge_memory: update file PMD counter before folio_put()
  tty: serial: qcom-geni-serial: remove unused symbols
  thunderbolt: property: Cap recursion depth in __tb_property_parse_dir()
  scsi: target: iscsi: Bound iscsi_encode_text_output() appends to rsp_buf
  Bluetooth: Init sk_peer_* on bt_sock_alloc
  Bluetooth: Consolidate code around sk_alloc into a helper function
  qed: fix double free in qed_cxt_tables_alloc()
  qed: Use the bitmap API to simplify some functions
  Bluetooth: fix UAF in l2cap_sock_cleanup_listen() vs l2cap_conn_del()
  spi: lantiq-ssc: fix controller deregistration
  spi: st-ssc4: fix controller deregistration
  f2fs: fix incorrect file address mapping when inline inode is unwritten
  btrfs: fix missing last_unlink_trans update when removing a directory
  dm-thin: fix metadata refcount underflow
  dm btree: improve btree residency
  pmdomain: core: Fix detach procedure for virtual devices in genpd
  btrfs: fix btrfs_ioctl_space_info() slot_count TOCTOU which can lead to info-leak
  fbcon: Avoid OOB font access if console rotation fails
  spi: tegra114: fix controller deregistration
  spi: tegra20-sflash: fix controller deregistration
  spi: sun6i: fix controller deregistration
  spi: ti-qspi: fix controller deregistration
  spi: sun4i: fix controller deregistration
  wifi: brcmfmac: Fix potential use-after-free issue when stopping watchdog task
  tracepoint: balance regfunc() on func_add() failure in tracepoint_add_func()
  ceph: only d_add() negative dentries when they are unhashed
  can: ucan: fix devres lifetime
  can: ucan: fix typos in comments
  Bluetooth: hci_event: fix potential UAF in SSP passkey handlers
  udf: fix partition descriptor append bookkeeping
  net: bridge: use a stable FDB dst snapshot in RCU readers
  ALSA: core: Fix potential data race at fasync handling
  media: rc: igorplugusb: heed coherency rules
  ALSA: aoa: Skip devices with no codecs in i2sbus_resume()
  media: rc: ttusbir: respect DMA coherency rules
  ALSA: aoa: Use guard() for mutex locks
  wifi: mwifiex: fix use-after-free in mwifiex_adapter_cleanup()
  thermal: core: Fix thermal zone governor cleanup issues
  drm/nouveau: fix u32 overflow in pushbuf reloc bounds check
  net/packet: fix TOCTOU race on mmap'd vnet_hdr in tpacket_snd()
  f2fs: fix UAF caused by decrementing sbi->nr_pages[] in f2fs_write_end_io()
  batman-adv: tp_meter: fix tp_num leak on kmalloc failure
  fs/fcntl: fix SOFTIRQ-unsafe lock order in fasync signaling
  thunderbolt: Limit XDomain response copy to actual frame size
  thunderbolt: Clamp XDomain response data copy to allocation size
  thunderbolt: Bound root directory content to block size
  thunderbolt: Reject zero-length property entries in validator
  sctp: stream: fully roll back denied add-stream state
  mmc: sdhci: add signal voltage switch in sdhci_resume_host
  mmc: core: Fix host controller programming for fixed driver type
  net: mv643xx: fix OF node refcount
  ipc/shm: serialize orphan cleanup with shm_nattch updates
  Input: atkbd - skip deactivate for HONOR BCC-N's internal keyboard
  Input: atkbd - add DMI quirk for Lenovo Yoga Air 14 (83QK)
  IB/isert: Reject login PDUs shorter than ISER_HEADERS_LEN
  vsock/vmci: fix sk_ack_backlog leak on failed handshake
  ARM: socfpga: Fix OF node refcount leak in SMP setup
  RDMA/srp: bound SRP_RSP sense copy by the received length
  drm/amd/display: Reject gpio_bitshift >= 32 in bios_parser_get_gpio_pin_info()
  USB: serial: kl5kusb105: fix bulk-out buffer overflow
  USB: serial: option: add usb-id for Dell Wireless DW5826e-m
  USB: serial: io_ti: fix heap overflow in build_i2c_fw_hdr()
  USB: serial: io_ti: fix heap overflow in get_manuf_info()
  netfilter: nft_tunnel: fix use-after-free on object destroy
  netfilter: nft_exthdr: fix register tracking for F_PRESENT flag
  netfilter: x_tables: avoid leaking percpu counter pointers
  ip6_vti: fix incorrect tunnel matching in vti6_tnl_lookup()
  net/rds: fix NULL deref in rds_ib_send_cqe_handler() on masked atomic completion
  net: guard timestamp cmsgs to real error queue skbs
  sctp: fix uninit-value in __sctp_rcv_asconf_lookup()
  net: openvswitch: fix possible kfree_skb of ERR_PTR
  ipv6: sit: reload inner IPv6 header after GSO offloads
  spi: meson-spicc: Fix double-put in remove path
  wifi: mac80211: check tdls flag in ieee80211_tdls_oper
  usbnet: Fix using smp_processor_id() in preemptible code warnings
  ext4: validate p_idx bounds in ext4_ext_correct_indexes
  signal: clear JOBCTL_PENDING_MASK for caller in zap_other_threads()
  sctp: purge outqueue on stale COOKIE-ECHO handling
  net/802/mrp: fix vector attribute parsing in mrp_pdu_parse_vecattr
  ieee802154: 6lowpan: only accept IPv6 packets in lowpan_xmit()
  ipv4: restrict IPOPT_SSRR and IPOPT_LSRR options
  Bluetooth: MGMT: validate advertising TLV before type checks
  Bluetooth: RFCOMM: hold listener socket in rfcomm_connect_ind()
  net: garp: fix unsigned integer underflow in garp_pdu_parse_attr
  pcnet32: stop holding device spin lock during napi_complete_done
  6lowpan: fix off-by-one in multicast context address compression
  dm cache policy smq: check allocation under invalidate lock
  netfilter: bridge: make ebt_snat ARP rewrite writable
  netfilter: conntrack_irc: fix possible out-of-bounds read
  ipvs: clear the svc scheduler ptr early on edit
  netfilter: xt_NFQUEUE: prefer raw_smp_processor_id
  tee: optee: prevent use-after-free when the client exits before the supplicant
  i2c: dev: prevent integer overflow in I2C_TIMEOUT ioctl
  USB: serial: mct_u232: fix memory corruption with small endpoint
  HID: core: Add printk_ratelimited variants to hid_warn() etc
  bpf: Free reuseport cBPF prog after RCU grace period.
  usb: core: Fix SuperSpeed root hub wMaxPacketSize
  team: Move team device type change at the end of team_port_add
  USB: serial: digi_acceleport: fix memory corruption with small endpoints
  USB: serial: cypress_m8: fix memory corruption with small endpoint
  Bluetooth: hci_core: Fix use-after-free in vhci_flush()
  serial: zs: Switch to using channel reset
  serial: zs: Fix bootconsole handover lockup
  serial: dz: Fix bootconsole message clobbering at chip reset
  serial: zs: Fix swapped RI/DSR modem line transition counting
  serial: sh-sci: fix memory region release in error path
  scsi: fcoe: Reject FIP descriptors with zero fip_dlen in CVL walker
  thunderbolt: property: Reject dir_len < 4 to prevent size_t underflow
  thunderbolt: property: Reject u32 wrap in tb_property_entry_valid()
  usb: gadget: dummy_hcd: Reject hub port requests for non-existent ports
  usb: gadget: net2280: Fix double free in probe error path
  USB: serial: mct_u232: fix missing interrupt-in transfer sanity check
  USB: serial: mxuport: fix memory corruption with small endpoint
  USB: serial: keyspan: fix missing indat transfer sanity check
  USB: serial: cypress_m8: validate interrupt packet headers
  USB: serial: belkin_sa: validate interrupt status length
  USB: serial: option: add missing RSVD(5) flag for Rolling RW135R-GL
  USB: serial: option: add MeiG SRM813Q
  usb: usbtmc: reject interrupt endpoints with small wMaxPacketSize
  usb: usbtmc: check URB actual_length for interrupt-IN notifications
  usb: storage: Add quirks for PNY Elite Portable SSD
  USB: quirks: add NO_LPM for Lenovo ThinkPad USB-C Dock Gen2 hub controllers
  tty: serial: pch_uart: add check for dma_alloc_coherent()
  comedi: comedi_test: Fix limiting of convert_arg in waveform_ai_cmdtest()
  comedi: comedi_test: fix check for valid scan_begin_src in waveform_ai_cmdtest()
  Input: atmel_mxt_ts - fix boundary check in mxt_prepare_cfg_mem
  netfilter: conntrack: tcp: do not force CLOSE on invalid-seq RST without direction check
  xfrm: route MIGRATE notifications to caller's netns
  nfc: hci: fix out-of-bounds read in HCP header parsing
  HID: wacom: Fix OOB write in wacom_hid_set_device_mode()
  ip6: vti: Use ip6_tnl.net in vti6_changelink().
  ipv6: validate extension header length before copying to cmsg
  ip6: vti: Use ip6_tnl.net in vti6_siocdevprivate().
  ipv6: exthdrs: refresh nh pointer after ipv6_hop_jumbo()
  Input: elan_i2c - validate firmware size before use
  usb: dwc2: Fix use after free in debug code
  USB: serial: omninet: fix memory corruption with small endpoint
  iio: buffer: hw-consumer: fix use-after-free in error path
  iio: light: cm3323: fix reg_conf not being initialized correctly
  iio: temperature: tsys01: fix broken PROM checksum validation
  iio: ssp_sensors: cancel delayed work_refresh on remove
  iio: gyro: itg3200: fix i2c read into the wrong stack location
  iio: adc: viperboard: Fix error handling in vprbrd_iio_read_raw
  iio: dac: ad5686: fix input raw value check
  iio: dac: max5821: fix return value check in powerdown sync
  iio: adc: xilinx-xadc: Fix sequencer mode in postdisable for dual mux
  parport: Fix race between port and client registration
  Bluetooth: L2CAP: fix chan ref leak in l2cap_chan_timeout() on !conn
  hpfs: fix a crash if hpfs_map_dnode_bitmap fails
  Bluetooth: btusb: Allow firmware re-download when version matches
  Input: ims-pcu - fix usb_free_coherent() size in ims_pcu_buffers_free()
  USB: serial: safe_serial: fix memory corruption with small endpoint
  usb: typec: wcove: don't write past struct pd_message in wcove_read_rx_buffer()
  usb: typec: altmodes/displayport: validate count before reading Status Update VDO
  batman-adv: bla: avoid double decrement of bla.num_requests
  batman-adv: tp_meter: avoid role confusion in tp_list
  batman-adv: tp_meter: fix race condition in send error reporting
  batman-adv: iv: recover OGM scheduling after forward packet error
  batman-adv: tvlv: reject oversized TVLV packets
  batman-adv: bla: avoid NULL-ptr deref for claim via dropped interface
  batman-adv: tvlv: abort OGM send on tvlv append failure
  sctp: fix race between sctp_wait_for_connect and peeloff
  Bluetooth: 6lowpan: check skb_clone() return value in send_mcast_pkt()
  vxlan: do not reuse cached ip_hdr() value after skb_tunnel_check_pmtu()
  ipv4: free net->ipv4.sysctl_local_reserved_ports after unregister_net_sysctl_table()
  net/iucv: fix locking in .getsockopt
  net/smc: Do not re-initialize smc hashtables
  net: netlink: don't set nsid on local notifications
  net: netlink: fix sending unassigned nsid after assigned one
  netfilter: ebtables: fix OOB read in compat_mtw_from_user
  netfilter: xt_cpu: prefer raw_smp_processor_id
  netfilter: synproxy: refresh tcphdr after skb_ensure_writable
  nfc: llcp: Fix use-after-free race in nfc_llcp_recv_cc()
  nfc: llcp: Fix use-after-free in llcp_sock_release()
  nfc: llcp: protect nfc_llcp_sock_unlink() calls
  net/sched: sch_sfb: Replace direct dequeue call with peek and qdisc_dequeue_peeked
  net/sched: cls_fw: fix NULL dereference of "old" filters before change()
  ALSA: usb-audio: fix null pointer dereference on pointer cs_desc
  Input: usbtouchscreen - clamp NEXIO data_len/x_len to URB buffer size

Change-Id: I31f1b66ac06bb8a4f27835e54972afd499525e8d
2026-08-06 18:18:48 +01:00

683 lines
18 KiB
C

/*
* Copyright (C) 2008-2014 Mathieu Desnoyers
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/types.h>
#include <linux/jhash.h>
#include <linux/list.h>
#include <linux/rcupdate.h>
#include <linux/tracepoint.h>
#include <linux/err.h>
#include <linux/slab.h>
#include <linux/sched/signal.h>
#include <linux/sched/task.h>
#include <linux/static_key.h>
extern tracepoint_ptr_t __start___tracepoints_ptrs[];
extern tracepoint_ptr_t __stop___tracepoints_ptrs[];
DEFINE_SRCU(tracepoint_srcu);
EXPORT_SYMBOL_GPL(tracepoint_srcu);
/* Set to 1 to enable tracepoint debug output */
static const int tracepoint_debug;
#ifdef CONFIG_MODULES
/*
* Tracepoint module list mutex protects the local module list.
*/
static DEFINE_MUTEX(tracepoint_module_list_mutex);
/* Local list of struct tp_module */
static LIST_HEAD(tracepoint_module_list);
#endif /* CONFIG_MODULES */
/*
* tracepoints_mutex protects the builtin and module tracepoints.
* tracepoints_mutex nests inside tracepoint_module_list_mutex.
*/
static DEFINE_MUTEX(tracepoints_mutex);
static struct rcu_head *early_probes;
static bool ok_to_free_tracepoints;
/*
* Note about RCU :
* It is used to delay the free of multiple probes array until a quiescent
* state is reached.
*/
struct tp_probes {
struct rcu_head rcu;
struct tracepoint_func probes[0];
};
/* Called in removal of a func but failed to allocate a new tp_funcs */
static void tp_stub_func(void)
{
return;
}
static inline void *allocate_probes(int count)
{
struct tp_probes *p = kmalloc(count * sizeof(struct tracepoint_func)
+ sizeof(struct tp_probes), GFP_KERNEL);
return p == NULL ? NULL : p->probes;
}
static void srcu_free_old_probes(struct rcu_head *head)
{
kfree(container_of(head, struct tp_probes, rcu));
}
static void rcu_free_old_probes(struct rcu_head *head)
{
call_srcu(&tracepoint_srcu, head, srcu_free_old_probes);
}
static __init int release_early_probes(void)
{
struct rcu_head *tmp;
ok_to_free_tracepoints = true;
while (early_probes) {
tmp = early_probes;
early_probes = tmp->next;
call_rcu_sched(tmp, rcu_free_old_probes);
}
return 0;
}
/* SRCU is initialized at core_initcall */
postcore_initcall(release_early_probes);
static inline void release_probes(struct tracepoint_func *old)
{
if (old) {
struct tp_probes *tp_probes = container_of(old,
struct tp_probes, probes[0]);
/*
* We can't free probes if SRCU is not initialized yet.
* Postpone the freeing till after SRCU is initialized.
*/
if (unlikely(!ok_to_free_tracepoints)) {
tp_probes->rcu.next = early_probes;
early_probes = &tp_probes->rcu;
return;
}
/*
* Tracepoint probes are protected by both sched RCU and SRCU,
* by calling the SRCU callback in the sched RCU callback we
* cover both cases. So let us chain the SRCU and sched RCU
* callbacks to wait for both grace periods.
*/
call_rcu_sched(&tp_probes->rcu, rcu_free_old_probes);
}
}
static void debug_print_probes(struct tracepoint_func *funcs)
{
int i;
if (!tracepoint_debug || !funcs)
return;
for (i = 0; funcs[i].func; i++)
printk(KERN_DEBUG "Probe %d : %p\n", i, funcs[i].func);
}
static struct tracepoint_func *
func_add(struct tracepoint_func **funcs, struct tracepoint_func *tp_func,
int prio)
{
struct tracepoint_func *old, *new;
int nr_probes = 0;
int stub_funcs = 0;
int pos = -1;
if (WARN_ON(!tp_func->func))
return ERR_PTR(-EINVAL);
debug_print_probes(*funcs);
old = *funcs;
if (old) {
/* (N -> N+1), (N != 0, 1) probes */
for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
/* Insert before probes of lower priority */
if (pos < 0 && old[nr_probes].prio < prio)
pos = nr_probes;
if (old[nr_probes].func == tp_func->func &&
old[nr_probes].data == tp_func->data)
return ERR_PTR(-EEXIST);
if (old[nr_probes].func == tp_stub_func)
stub_funcs++;
}
}
/* + 2 : one for new probe, one for NULL func - stub functions */
new = allocate_probes(nr_probes + 2 - stub_funcs);
if (new == NULL)
return ERR_PTR(-ENOMEM);
if (old) {
if (stub_funcs) {
/* Need to copy one at a time to remove stubs */
int probes = 0;
pos = -1;
for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
if (old[nr_probes].func == tp_stub_func)
continue;
if (pos < 0 && old[nr_probes].prio < prio)
pos = probes++;
new[probes++] = old[nr_probes];
}
nr_probes = probes;
if (pos < 0)
pos = probes;
else
nr_probes--; /* Account for insertion */
} else if (pos < 0) {
pos = nr_probes;
memcpy(new, old, nr_probes * sizeof(struct tracepoint_func));
} else {
/* Copy higher priority probes ahead of the new probe */
memcpy(new, old, pos * sizeof(struct tracepoint_func));
/* Copy the rest after it. */
memcpy(new + pos + 1, old + pos,
(nr_probes - pos) * sizeof(struct tracepoint_func));
}
} else
pos = 0;
new[pos] = *tp_func;
new[nr_probes + 1].func = NULL;
*funcs = new;
debug_print_probes(*funcs);
return old;
}
static void *func_remove(struct tracepoint_func **funcs,
struct tracepoint_func *tp_func)
{
int nr_probes = 0, nr_del = 0, i;
struct tracepoint_func *old, *new;
old = *funcs;
if (!old)
return ERR_PTR(-ENOENT);
debug_print_probes(*funcs);
/* (N -> M), (N > 1, M >= 0) probes */
if (tp_func->func) {
for (nr_probes = 0; old[nr_probes].func; nr_probes++) {
if ((old[nr_probes].func == tp_func->func &&
old[nr_probes].data == tp_func->data) ||
old[nr_probes].func == tp_stub_func)
nr_del++;
}
}
/*
* If probe is NULL, then nr_probes = nr_del = 0, and then the
* entire entry will be removed.
*/
if (nr_probes - nr_del == 0) {
/* N -> 0, (N > 1) */
*funcs = NULL;
debug_print_probes(*funcs);
return old;
} else {
int j = 0;
/* N -> M, (N > 1, M > 0) */
/* + 1 for NULL */
new = allocate_probes(nr_probes - nr_del + 1);
if (new) {
for (i = 0; old[i].func; i++)
if ((old[i].func != tp_func->func
|| old[i].data != tp_func->data)
&& old[i].func != tp_stub_func)
new[j++] = old[i];
new[nr_probes - nr_del].func = NULL;
*funcs = new;
} else {
/*
* Failed to allocate, replace the old function
* with calls to tp_stub_func.
*/
for (i = 0; old[i].func; i++)
if (old[i].func == tp_func->func &&
old[i].data == tp_func->data) {
old[i].func = tp_stub_func;
/* Set the prio to the next event. */
if (old[i + 1].func)
old[i].prio =
old[i + 1].prio;
else
old[i].prio = -1;
}
*funcs = old;
}
}
debug_print_probes(*funcs);
return old;
}
/*
* Add the probe function to a tracepoint.
*/
static int tracepoint_add_func(struct tracepoint *tp,
struct tracepoint_func *func, int prio,
bool warn)
{
struct tracepoint_func *old, *tp_funcs;
int ret;
if (tp->regfunc && !static_key_enabled(&tp->key)) {
ret = tp->regfunc();
if (ret < 0)
return ret;
}
tp_funcs = rcu_dereference_protected(tp->funcs,
lockdep_is_held(&tracepoints_mutex));
old = func_add(&tp_funcs, func, prio);
if (IS_ERR(old)) {
if (tp->unregfunc && !static_key_enabled(&tp->key))
tp->unregfunc();
WARN_ON_ONCE(warn && PTR_ERR(old) != -ENOMEM);
return PTR_ERR(old);
}
/*
* rcu_assign_pointer has as smp_store_release() which makes sure
* that the new probe callbacks array is consistent before setting
* a pointer to it. This array is referenced by __DO_TRACE from
* include/linux/tracepoint.h using rcu_dereference_sched().
*/
rcu_assign_pointer(tp->funcs, tp_funcs);
if (!static_key_enabled(&tp->key))
static_key_slow_inc(&tp->key);
release_probes(old);
return 0;
}
/*
* Remove a probe function from a tracepoint.
* Note: only waiting an RCU period after setting elem->call to the empty
* function insures that the original callback is not used anymore. This insured
* by preempt_disable around the call site.
*/
static int tracepoint_remove_func(struct tracepoint *tp,
struct tracepoint_func *func)
{
struct tracepoint_func *old, *tp_funcs;
tp_funcs = rcu_dereference_protected(tp->funcs,
lockdep_is_held(&tracepoints_mutex));
old = func_remove(&tp_funcs, func);
if (WARN_ON_ONCE(IS_ERR(old)))
return PTR_ERR(old);
if (tp_funcs == old)
/* Failed allocating new tp_funcs, replaced func with stub */
return 0;
if (!tp_funcs) {
/* Removed last function */
if (tp->unregfunc && static_key_enabled(&tp->key))
tp->unregfunc();
if (static_key_enabled(&tp->key))
static_key_slow_dec(&tp->key);
}
rcu_assign_pointer(tp->funcs, tp_funcs);
release_probes(old);
return 0;
}
/**
* tracepoint_probe_register_prio_may_exist - Connect a probe to a tracepoint with priority
* @tp: tracepoint
* @probe: probe handler
* @data: tracepoint data
* @prio: priority of this function over other registered functions
*
* Same as tracepoint_probe_register_prio() except that it will not warn
* if the tracepoint is already registered.
*/
int tracepoint_probe_register_prio_may_exist(struct tracepoint *tp, void *probe,
void *data, int prio)
{
struct tracepoint_func tp_func;
int ret;
mutex_lock(&tracepoints_mutex);
tp_func.func = probe;
tp_func.data = data;
tp_func.prio = prio;
ret = tracepoint_add_func(tp, &tp_func, prio, false);
mutex_unlock(&tracepoints_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(tracepoint_probe_register_prio_may_exist);
/**
* tracepoint_probe_register_prio - Connect a probe to a tracepoint with priority
* @tp: tracepoint
* @probe: probe handler
* @data: tracepoint data
* @prio: priority of this function over other registered functions
*
* Returns 0 if ok, error value on error.
* Note: if @tp is within a module, the caller is responsible for
* unregistering the probe before the module is gone. This can be
* performed either with a tracepoint module going notifier, or from
* within module exit functions.
*/
int tracepoint_probe_register_prio(struct tracepoint *tp, void *probe,
void *data, int prio)
{
struct tracepoint_func tp_func;
int ret;
mutex_lock(&tracepoints_mutex);
tp_func.func = probe;
tp_func.data = data;
tp_func.prio = prio;
ret = tracepoint_add_func(tp, &tp_func, prio, true);
mutex_unlock(&tracepoints_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(tracepoint_probe_register_prio);
/**
* tracepoint_probe_register - Connect a probe to a tracepoint
* @tp: tracepoint
* @probe: probe handler
* @data: tracepoint data
*
* Returns 0 if ok, error value on error.
* Note: if @tp is within a module, the caller is responsible for
* unregistering the probe before the module is gone. This can be
* performed either with a tracepoint module going notifier, or from
* within module exit functions.
*/
int tracepoint_probe_register(struct tracepoint *tp, void *probe, void *data)
{
return tracepoint_probe_register_prio(tp, probe, data, TRACEPOINT_DEFAULT_PRIO);
}
EXPORT_SYMBOL_GPL(tracepoint_probe_register);
/**
* tracepoint_probe_unregister - Disconnect a probe from a tracepoint
* @tp: tracepoint
* @probe: probe function pointer
* @data: tracepoint data
*
* Returns 0 if ok, error value on error.
*/
int tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data)
{
struct tracepoint_func tp_func;
int ret;
mutex_lock(&tracepoints_mutex);
tp_func.func = probe;
tp_func.data = data;
ret = tracepoint_remove_func(tp, &tp_func);
mutex_unlock(&tracepoints_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(tracepoint_probe_unregister);
static void for_each_tracepoint_range(
tracepoint_ptr_t *begin, tracepoint_ptr_t *end,
void (*fct)(struct tracepoint *tp, void *priv),
void *priv)
{
tracepoint_ptr_t *iter;
if (!begin)
return;
for (iter = begin; iter < end; iter++)
fct(tracepoint_ptr_deref(iter), priv);
}
#ifdef CONFIG_MODULES
bool trace_module_has_bad_taint(struct module *mod)
{
return mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP) |
(1 << TAINT_UNSIGNED_MODULE));
}
static BLOCKING_NOTIFIER_HEAD(tracepoint_notify_list);
/**
* register_tracepoint_notifier - register tracepoint coming/going notifier
* @nb: notifier block
*
* Notifiers registered with this function are called on module
* coming/going with the tracepoint_module_list_mutex held.
* The notifier block callback should expect a "struct tp_module" data
* pointer.
*/
int register_tracepoint_module_notifier(struct notifier_block *nb)
{
struct tp_module *tp_mod;
int ret;
mutex_lock(&tracepoint_module_list_mutex);
ret = blocking_notifier_chain_register(&tracepoint_notify_list, nb);
if (ret)
goto end;
list_for_each_entry(tp_mod, &tracepoint_module_list, list)
(void) nb->notifier_call(nb, MODULE_STATE_COMING, tp_mod);
end:
mutex_unlock(&tracepoint_module_list_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(register_tracepoint_module_notifier);
/**
* unregister_tracepoint_notifier - unregister tracepoint coming/going notifier
* @nb: notifier block
*
* The notifier block callback should expect a "struct tp_module" data
* pointer.
*/
int unregister_tracepoint_module_notifier(struct notifier_block *nb)
{
struct tp_module *tp_mod;
int ret;
mutex_lock(&tracepoint_module_list_mutex);
ret = blocking_notifier_chain_unregister(&tracepoint_notify_list, nb);
if (ret)
goto end;
list_for_each_entry(tp_mod, &tracepoint_module_list, list)
(void) nb->notifier_call(nb, MODULE_STATE_GOING, tp_mod);
end:
mutex_unlock(&tracepoint_module_list_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(unregister_tracepoint_module_notifier);
/*
* Ensure the tracer unregistered the module's probes before the module
* teardown is performed. Prevents leaks of probe and data pointers.
*/
static void tp_module_going_check_quiescent(struct tracepoint *tp, void *priv)
{
WARN_ON_ONCE(tp->funcs);
}
static int tracepoint_module_coming(struct module *mod)
{
struct tp_module *tp_mod;
int ret = 0;
if (!mod->num_tracepoints)
return 0;
/*
* We skip modules that taint the kernel, especially those with different
* module headers (for forced load), to make sure we don't cause a crash.
* Staging, out-of-tree, and unsigned GPL modules are fine.
*/
if (trace_module_has_bad_taint(mod))
return 0;
mutex_lock(&tracepoint_module_list_mutex);
tp_mod = kmalloc(sizeof(struct tp_module), GFP_KERNEL);
if (!tp_mod) {
ret = -ENOMEM;
goto end;
}
tp_mod->mod = mod;
list_add_tail(&tp_mod->list, &tracepoint_module_list);
blocking_notifier_call_chain(&tracepoint_notify_list,
MODULE_STATE_COMING, tp_mod);
end:
mutex_unlock(&tracepoint_module_list_mutex);
return ret;
}
static void tracepoint_module_going(struct module *mod)
{
struct tp_module *tp_mod;
if (!mod->num_tracepoints)
return;
mutex_lock(&tracepoint_module_list_mutex);
list_for_each_entry(tp_mod, &tracepoint_module_list, list) {
if (tp_mod->mod == mod) {
blocking_notifier_call_chain(&tracepoint_notify_list,
MODULE_STATE_GOING, tp_mod);
list_del(&tp_mod->list);
kfree(tp_mod);
/*
* Called the going notifier before checking for
* quiescence.
*/
for_each_tracepoint_range(mod->tracepoints_ptrs,
mod->tracepoints_ptrs + mod->num_tracepoints,
tp_module_going_check_quiescent, NULL);
break;
}
}
/*
* In the case of modules that were tainted at "coming", we'll simply
* walk through the list without finding it. We cannot use the "tainted"
* flag on "going", in case a module taints the kernel only after being
* loaded.
*/
mutex_unlock(&tracepoint_module_list_mutex);
}
static int tracepoint_module_notify(struct notifier_block *self,
unsigned long val, void *data)
{
struct module *mod = data;
int ret = 0;
switch (val) {
case MODULE_STATE_COMING:
ret = tracepoint_module_coming(mod);
break;
case MODULE_STATE_LIVE:
break;
case MODULE_STATE_GOING:
tracepoint_module_going(mod);
break;
case MODULE_STATE_UNFORMED:
break;
}
return notifier_from_errno(ret);
}
static struct notifier_block tracepoint_module_nb = {
.notifier_call = tracepoint_module_notify,
.priority = 0,
};
static __init int init_tracepoints(void)
{
int ret;
ret = register_module_notifier(&tracepoint_module_nb);
if (ret)
pr_warn("Failed to register tracepoint module enter notifier\n");
return ret;
}
__initcall(init_tracepoints);
#endif /* CONFIG_MODULES */
/**
* for_each_kernel_tracepoint - iteration on all kernel tracepoints
* @fct: callback
* @priv: private data
*/
void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
void *priv)
{
for_each_tracepoint_range(__start___tracepoints_ptrs,
__stop___tracepoints_ptrs, fct, priv);
}
EXPORT_SYMBOL_GPL(for_each_kernel_tracepoint);
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
/* NB: reg/unreg are called while guarded with the tracepoints_mutex */
static int sys_tracepoint_refcount;
int syscall_regfunc(void)
{
struct task_struct *p, *t;
if (!sys_tracepoint_refcount) {
read_lock(&tasklist_lock);
for_each_process_thread(p, t) {
set_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
}
read_unlock(&tasklist_lock);
}
sys_tracepoint_refcount++;
return 0;
}
void syscall_unregfunc(void)
{
struct task_struct *p, *t;
sys_tracepoint_refcount--;
if (!sys_tracepoint_refcount) {
read_lock(&tasklist_lock);
for_each_process_thread(p, t) {
clear_tsk_thread_flag(t, TIF_SYSCALL_TRACEPOINT);
}
read_unlock(&tasklist_lock);
}
}
#endif