Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

RDMA/umad: Reject negative data_len in ib_umad_write

ib_umad_write computes data_len from user-controlled count and the
MAD header sizes. With a mismatched user MAD header size and RMPP
header length, data_len can become negative and reach ib_create_send_mad().
This can make the padding calculation exceed the segment size and trigger
an out-of-bounds memset in alloc_send_rmpp_list().

Add an explicit check to reject negative data_len before creating the
send buffer.

KASAN splat:
[ 211.363464] BUG: KASAN: slab-out-of-bounds in ib_create_send_mad+0xa01/0x11b0
[ 211.364077] Write of size 220 at addr ffff88800c3fa1f8 by task spray_thread/102
[ 211.365867] ib_create_send_mad+0xa01/0x11b0
[ 211.365887] ib_umad_write+0x853/0x1c80

Fixes: 2be8e3ee8efd ("IB/umad: Add P_Key index support")
Signed-off-by: YunJe Shin <ioerts@kookmin.ac.kr>
Link: https://patch.msgid.link/20260203100628.1215408-1-ioerts@kookmin.ac.kr
Signed-off-by: Leon Romanovsky <leon@kernel.org>

authored by

YunJe Shin and committed by
Leon Romanovsky
5551b02f 42e3aac6

+6 -2
+6 -2
drivers/infiniband/core/user_mad.c
··· 514 514 struct rdma_ah_attr ah_attr; 515 515 struct ib_ah *ah; 516 516 __be64 *tid; 517 - int ret, data_len, hdr_len, copy_offset, rmpp_active; 517 + int ret, hdr_len, copy_offset, rmpp_active; 518 + size_t data_len; 518 519 u8 base_version; 519 520 520 521 if (count < hdr_size(file) + IB_MGMT_RMPP_HDR) ··· 589 588 } 590 589 591 590 base_version = ((struct ib_mad_hdr *)&packet->mad.data)->base_version; 592 - data_len = count - hdr_size(file) - hdr_len; 591 + if (check_sub_overflow(count, hdr_size(file) + hdr_len, &data_len)) { 592 + ret = -EINVAL; 593 + goto err_ah; 594 + } 593 595 packet->msg = ib_create_send_mad(agent, 594 596 be32_to_cpu(packet->mad.hdr.qpn), 595 597 packet->mad.hdr.pkey_index, rmpp_active,