linux/include/trace/events
JP Kobryn 0590874226 9p: prevent read overrun in protocol dump tracepoint
commit a931c68160 upstream.

An out of bounds read can occur within the tracepoint 9p_protocol_dump. In
the fast assign, there is a memcpy that uses a constant size of 32 (macro
named P9_PROTO_DUMP_SZ). When the copy is invoked, the source buffer is not
guaranteed match this size.  It was found that in some cases the source
buffer size is less than 32, resulting in a read that overruns.

The size of the source buffer seems to be known at the time of the
tracepoint being invoked. The allocations happen within p9_fcall_init(),
where the capacity field is set to the allocated size of the payload
buffer. This patch tries to fix the overrun by changing the fixed array to
a dynamically sized array and using the minimum of the capacity value or
P9_PROTO_DUMP_SZ as its length. The trace log statement is adjusted to
account for this. Note that the trace log no longer splits the payload on
the first 16 bytes. The full payload is now logged to a single line.

To repro the orignal problem, operations to a plan 9 managed resource can
be used. The simplest approach might just be mounting a shared filesystem
(between host and guest vm) using the plan 9 protocol while the tracepoint
is enabled.

mount -t 9p -o trans=virtio <mount_tag> <mount_path>

The bpftrace program below can be used to show the out of bounds read.
Note that a recent version of bpftrace is needed for the raw tracepoint
support. The script was tested using v0.19.0.

/* from include/net/9p/9p.h */
struct p9_fcall {
    u32 size;
    u8 id;
    u16 tag;
    size_t offset;
    size_t capacity;
    struct kmem_cache *cache;
    u8 *sdata;
    bool zc;
};

tracepoint:9p:9p_protocol_dump
{
    /* out of bounds read can happen when this tracepoint is enabled */
}

rawtracepoint:9p_protocol_dump
{
    $pdu = (struct p9_fcall *)arg1;
    $dump_sz = (uint64)32;

    if ($dump_sz > $pdu->capacity) {
        printf("reading %zu bytes from src buffer of %zu bytes\n",
            $dump_sz, $pdu->capacity);
    }
}

Signed-off-by: JP Kobryn <inwardvessel@gmail.com>
Message-ID: <20231204202321.22730-1-inwardvessel@gmail.com>
Fixes: 60ece0833b ("net/9p: allocate appropriate reduced message buffers")
Cc: stable@vger.kernel.org
Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>
Signed-off-by: Dominique Martinet <asmadeus@codewreck.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2024-01-01 12:42:43 +00:00
..
9p.h 9p: prevent read overrun in protocol dump tracepoint 2024-01-01 12:42:43 +00:00
afs.h
alarmtimer.h
asoc.h
avc.h
bcache.h
block.h fs: add CONFIG_BUFFER_HEAD 2023-08-02 09:13:09 -06:00
bpf_test_run.h
bridge.h
btrfs.h btrfs: remove v0 extent handling 2023-08-21 14:54:48 +02:00
cachefiles.h
cgroup.h
clk.h
cma.h
compaction.h mm: compaction: add trace event for fast freepages isolation 2023-06-09 16:25:43 -07:00
context_tracking.h
cpuhp.h
csd.h trace,smp: Add tracepoints for scheduling remotelly called functions 2023-06-16 22:08:09 +02:00
damon.h
devfreq.h
devlink.h
dlm.h fs: dlm: add plock dev tracepoints 2023-08-10 10:33:03 -05:00
dma_fence.h
erofs.h erofs: adapt folios for z_erofs_read_folio() 2023-08-23 23:47:33 +08:00
error_report.h
ext4.h ext4: Give symbolic names to mballoc criterias 2023-06-26 19:34:56 -04:00
f2fs.h f2fs: add async reset zone command support 2023-06-12 13:04:09 -07:00
fib.h net: Replace strlcpy with strscpy 2023-07-04 19:40:16 +01:00
fib6.h net: Replace strlcpy with strscpy 2023-07-04 19:40:16 +01:00
filelock.h
filemap.h
fs_dax.h
fscache.h
fsi_master_aspeed.h
fsi_master_ast_cf.h
fsi_master_gpio.h
fsi_master_i2cr.h fsi: Add IBM I2C Responder virtual FSI master 2023-08-11 13:32:14 +09:30
fsi.h fsi: core: Add trace events for scan and unregister 2023-08-09 15:43:28 +09:30
gpio.h
gpu_mem.h
habanalabs.h
handshake.h net/handshake: Trace events for TLS Alert helpers 2023-07-28 14:07:59 -07:00
host1x.h
huge_memory.h
hwmon.h
i2c_slave.h
i2c.h
ib_mad.h
ib_umad.h
initcall.h
intel_ifs.h
intel_ish.h
intel-sst.h
io_uring.h
iocost.h
iommu.h
ipi.h
irq_matrix.h
irq.h
iscsi.h
jbd2.h jbd2: remove journal_clean_one_cp_list() 2023-07-10 23:09:21 -04:00
kmem.h
ksm.h
kvm.h
kyber.h kyber: Replace strlcpy with strscpy 2023-07-17 08:18:17 -06:00
libata.h
lock.h
maple_tree.h
mce.h
mctp.h
mdio.h
migrate.h
mlxsw.h
mmap_lock.h
mmap.h
mmc.h
mmflags.h mm: compaction: remove compaction result helpers 2023-06-09 16:25:36 -07:00
module.h
mptcp.h
napi.h
nbd.h
neigh.h neighbor: tracing: Move pin6 inside CONFIG_IPV6=y section 2023-10-18 11:16:43 +01:00
net_probe_common.h
net.h net: fix net_dev_start_xmit trace event vs skb_transport_offset() 2023-07-03 09:13:23 +01:00
netfs.h
netlink.h
nilfs2.h
nmi.h
notifier.h
objagg.h
oom.h
osnoise.h
page_isolation.h
page_pool.h page_pool: split types and declarations from page_pool.h 2023-08-07 13:05:19 -07:00
page_ref.h
pagemap.h
percpu.h
power_cpu_migrate.h
power.h
preemptirq.h
printk.h
pwc.h
pwm.h
qdisc.h
qla.h
qrtr.h
rcu.h
rdma_core.h
regulator.h
rpcgss.h
rpcrdma.h svcrdma: trace cc_release calls 2023-06-17 13:18:06 -04:00
rpm.h
rseq.h
rtc.h
rv.h
rwmmio.h
rxrpc.h rxrpc: Fix RTT determination to use any ACK as a source 2023-12-03 07:33:02 +01:00
sched.h
scmi.h
scsi.h scsi: core: Trace SCSI sense data 2023-05-31 11:05:34 -04:00
sctp.h
signal.h
siox.h
skb.h
smbus.h
sock.h
sof_intel.h
sof.h
spi.h spi: Fix spelling typos and acronyms capitalization 2023-07-11 14:14:32 +01:00
spmi.h
sunrpc.h SUNRPC: Move trace_svc_xprt_enqueue 2023-08-29 17:45:22 -04:00
sunvnet.h
swiotlb.h
syscalls.h
target.h
task.h tracing: Replace strlcpy with strscpy in trace/events/task.h 2023-09-01 21:00:00 -04:00
tcp.h tcp: add missing family to tcp_set_ca_state() tracepoint 2023-08-09 13:45:19 -07:00
tegra_apb_dma.h
thermal_pressure.h
thp.h powerpc/book3s64/mm: enable transparent pud hugepage 2023-08-18 10:12:55 -07:00
timer.h tracing/timer: Add missing hrtimer modes to decode_hrtimer_mode(). 2023-06-19 09:09:14 +02:00
tlb.h
udp.h
ufs.h
v4l2.h
vb2.h
vmalloc.h
vmscan.h
vsock_virtio_transport_common.h
watchdog.h
wbt.h blk-wbt: Replace strlcpy with strscpy 2023-07-17 08:18:17 -06:00
workqueue.h
writeback.h writeback: fix dereferencing NULL mapping->host on writeback_page_template 2023-06-19 13:19:31 -07:00
xdp.h net: invert the netdevice.h vs xdp.h dependency 2023-08-03 08:38:07 -07:00
xen.h x86/xen: move paravirt lazy code 2023-09-19 07:04:49 +02:00