OrangePi_CM5/include/trace/events
David Collins dd02510fb4 spmi: trace: fix stack-out-of-bound access in SPMI tracing functions
commit 2af28b241eea816e6f7668d1954f15894b45d7e3 upstream.

trace_spmi_write_begin() and trace_spmi_read_end() both call
memcpy() with a length of "len + 1".  This leads to one extra
byte being read beyond the end of the specified buffer.  Fix
this out-of-bound memory access by using a length of "len"
instead.

Here is a KASAN log showing the issue:

BUG: KASAN: stack-out-of-bounds in trace_event_raw_event_spmi_read_end+0x1d0/0x234
Read of size 2 at addr ffffffc0265b7540 by task thermal@2.0-ser/1314
...
Call trace:
 dump_backtrace+0x0/0x3e8
 show_stack+0x2c/0x3c
 dump_stack_lvl+0xdc/0x11c
 print_address_description+0x74/0x384
 kasan_report+0x188/0x268
 kasan_check_range+0x270/0x2b0
 memcpy+0x90/0xe8
 trace_event_raw_event_spmi_read_end+0x1d0/0x234
 spmi_read_cmd+0x294/0x3ac
 spmi_ext_register_readl+0x84/0x9c
 regmap_spmi_ext_read+0x144/0x1b0 [regmap_spmi]
 _regmap_raw_read+0x40c/0x754
 regmap_raw_read+0x3a0/0x514
 regmap_bulk_read+0x418/0x494
 adc5_gen3_poll_wait_hs+0xe8/0x1e0 [qcom_spmi_adc5_gen3]
 ...
 __arm64_sys_read+0x4c/0x60
 invoke_syscall+0x80/0x218
 el0_svc_common+0xec/0x1c8
 ...

addr ffffffc0265b7540 is located in stack of task thermal@2.0-ser/1314 at offset 32 in frame:
 adc5_gen3_poll_wait_hs+0x0/0x1e0 [qcom_spmi_adc5_gen3]

this frame has 1 object:
 [32, 33) 'status'

Memory state around the buggy address:
 ffffffc0265b7400: 00 00 00 00 00 00 00 00 00 00 00 00 f1 f1 f1 f1
 ffffffc0265b7480: 04 f3 f3 f3 00 00 00 00 00 00 00 00 00 00 00 00
>ffffffc0265b7500: 00 00 00 00 f1 f1 f1 f1 01 f3 f3 f3 00 00 00 00
                                           ^
 ffffffc0265b7580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 ffffffc0265b7600: f1 f1 f1 f1 01 f2 07 f2 f2 f2 01 f3 00 00 00 00
==================================================================

Fixes: a9fce37481 ("spmi: add command tracepoints for SPMI")
Cc: stable@vger.kernel.org
Reviewed-by: Stephen Boyd <sboyd@kernel.org>
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: David Collins <quic_collinsd@quicinc.com>
Link: https://lore.kernel.org/r/20220627235512.2272783-1-quic_collinsd@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-08-21 15:16:15 +02:00
..
9p.h
…
afs.h afs: Fix tracepoint string placement with built-in AFS 2021-07-28 14:35:41 +02:00
alarmtimer.h
…
asoc.h
…
avc.h selinux: add basic filtering for audit trace events 2020-08-21 17:07:29 -04:00
bcache.h bcache: add set_uuid in struct cache_set 2020-10-02 14:25:30 -06:00
block.h block: remove the request_queue to argument request based tracepoints 2022-08-21 15:15:36 +02:00
bpf_test_run.h
…
bridge.h
…
btrfs.h btrfs: use own btree inode io_tree owner id 2020-10-07 12:13:22 +02:00
cachefiles.h
…
cgroup.h cgroup: Trace event cgroup id fields should be u64 2022-01-27 10:53:52 +01:00
clk.h
…
cma.h
…
compaction.h mm/page_alloc: integrate classzone_idx and high_zoneidx 2020-06-03 20:09:44 -07:00
context_tracking.h
…
cpuhp.h
…
devfreq.h
…
devlink.h devlink: Add a tracepoint for trap reports 2020-09-30 18:01:26 -07:00
dma_fence.h
…
erofs.h erofs: fix up erofs_lookup tracepoint 2021-09-30 10:11:00 +02:00
ext4.h ext4: fix ext4_fc_stats trace point 2022-04-08 14:39:55 +02:00
f2fs.h f2fs: fix up f2fs_lookup tracepoints 2021-11-26 10:39:12 +01:00
fib.h
…
fib6.h
…
filelock.h locks: Remove extra "0x" in tracepoint format specifier 2020-09-01 18:09:34 -04:00
filemap.h
…
fs_dax.h
…
fscache.h
…
fsi.h
…
fsi_master_aspeed.h
…
fsi_master_ast_cf.h
…
fsi_master_gpio.h
…
gpio.h
…
gpu_mem.h gpu/trace: Minor comment updates for gpu_mem_total tracepoint 2020-05-07 13:32:57 -04:00
host1x.h
…
huge_memory.h khugepaged: introduce 'max_ptes_shared' tunable 2020-06-03 20:09:46 -07:00
hwmon.h
…
i2c.h
…
ib_mad.h
…
ib_umad.h
…
initcall.h
…
intel-sst.h
…
intel_iommu.h
…
intel_ish.h
…
io_uring.h
…
iocost.h iocost: add iocg_forgive_debt tracepoint 2020-09-25 08:35:02 -06:00
iommu.h
…
ipi.h
…
irq.h
…
irq_matrix.h
…
iscsi.h
…
jbd2.h
…
kmem.h
…
kvm.h KVM: x86: Allow deflecting unknown MSR accesses to user space 2020-09-28 07:58:04 -04:00
kyber.h
…
libata.h ata: libata: add qc->flags in ata_qc_complete_template tracepoint 2022-06-29 08:59:45 +02:00
lock.h
…
mce.h
…
mdio.h
…
migrate.h mm/vmstat: add events for THP migration without split 2020-08-12 10:57:57 -07:00
mlxsw.h
…
mmap.h
…
mmc.h
…
mmflags.h mm: Add PG_arch_2 page flag 2020-09-04 12:46:06 +01:00
module.h
…
napi.h
…
nbd.h
…
neigh.h
…
net.h
…
net_probe_common.h
…
nilfs2.h
…
nmi.h
…
objagg.h
…
oom.h
…
page_isolation.h
…
page_pool.h
…
page_ref.h
…
pagemap.h
…
percpu.h
…
power.h
…
power_cpu_migrate.h
…
preemptirq.h
…
printk.h
…
pwc.h
…
pwm.h
…
qdisc.h net_sched: add a tracepoint for qdisc creation 2020-05-27 15:05:49 -07:00
qla.h scsi: qla2xxx: Suppress two recently introduced compiler warnings 2020-05-19 21:43:01 -04:00
qrtr.h
…
rcu.h rcu/trace: Print negative GP numbers correctly 2020-08-24 18:36:04 -07:00
rdma.h RDMA/core: Move the rdma_show_ib_cm_event() macro 2020-08-24 16:01:47 -03:00
rdma_core.h
…
regulator.h regulator: core: Add regulator bypass trace points 2020-05-29 17:17:02 +01:00
rpcgss.h SUNRPC: Augment server-side rpcgss tracepoints 2020-07-13 17:28:24 -04:00
rpcrdma.h NFS Client Updates for Linux 5.10 2020-10-20 13:26:30 -07:00
rpm.h
…
rseq.h
…
rtc.h
…
rxrpc.h rxrpc: Fix decision on when to generate an IDLE ACK 2022-06-09 10:21:12 +02:00
sched.h sched/debug: Add new tracepoint to track cpu_capacity 2020-10-03 16:30:52 +02:00
scmi.h firmware: arm_scmi: Use signed integer to report transfer status 2020-06-30 14:07:08 +01:00
scsi.h
…
sctp.h
…
signal.h
…
siox.h
…
skb.h
…
smbus.h
…
sock.h net: sock: tracing: Fix sock_exceed_buf_limit not to dereference stale pointer 2022-07-21 21:20:00 +02:00
spi.h
…
spmi.h spmi: trace: fix stack-out-of-bound access in SPMI tracing functions 2022-08-21 15:16:15 +02:00
sunrpc.h SUNRPC: Ensure we flush any closed sockets before xs_xprt_free() 2022-05-18 10:23:48 +02:00
sunvnet.h
…
swiotlb.h
…
syscalls.h
…
target.h scsi: target: core: Add CONTROL field for trace events 2020-10-02 18:36:19 -04:00
task.h
…
tcp.h
…
tegra_apb_dma.h
…
thermal.h
…
thermal_power_allocator.h
…
thp.h
…
timer.h
…
tlb.h
…
udp.h
…
ufs.h scsi: ufs: Add trace event for UIC commands 2020-06-15 23:35:06 -04:00
v4l2.h
…
vb2.h
…
vmscan.h tracing: incorrect isolate_mote_t cast in mm_vmscan_lru_isolate 2022-06-09 10:20:58 +02:00
vsock_virtio_transport_common.h
…
wbt.h bdi: use bdi_dev_name() to get device name 2020-05-09 16:07:39 -06:00
workqueue.h
…
writeback.h trace: fix potenial dangerous pointer 2020-11-25 13:03:44 +01:00
xdp.h bpf: cpumap: Implement XDP_REDIRECT for eBPF programs attached to map entries 2020-07-16 17:00:32 +02:00
xen.h x86/paravirt: Remove set_pte_at() pv-op 2020-08-15 13:52:12 +02:00