From: Jason Gunthorpe <jgg@ziepe.ca>
To: YunJe Shin <yjshin0438@gmail.com>
Cc: ioerts@kookmin.ac.kr, joonkyoj@yonsei.ac.kr, leon@kernel.org,
linux-rdma@vger.kernel.org
Subject: Re: [PATCH] RDMA/umad: Reject negative data_len in ib_umad_write
Date: Mon, 2 Feb 2026 14:34:49 -0400 [thread overview]
Message-ID: <20260202183449.GL2328995@ziepe.ca> (raw)
In-Reply-To: <20260131140954.89165-1-ioerts@kookmin.ac.kr>
On Sat, Jan 31, 2026 at 11:09:14PM +0900, YunJe Shin wrote:
> 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>
> ---
> drivers/infiniband/core/user_mad.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
> index fd67fc9fe85a..db1643aab029 100644
> --- a/drivers/infiniband/core/user_mad.c
> +++ b/drivers/infiniband/core/user_mad.c
> @@ -588,7 +588,15 @@ static ssize_t ib_umad_write(struct file *filp, const char __user *buf,
> }
>
> base_version = ((struct ib_mad_hdr *)&packet->mad.data)->base_version;
> + if (count < hdr_size(file) + hdr_len) {
> + ret = -EINVAL;
> + goto err_ah;
> + }
> data_len = count - hdr_size(file) - hdr_len;
> + if (data_len < 0) {
> + ret = -EINVAL;
> + goto err_ah;
> + }
data_len should also be a size_t to prevent truncation of count.
But I think I would prefer to replace both of these 'ifs' with a
simple check_sub_overflow() after making data_len unsigned.
Jason
next prev parent reply other threads:[~2026-02-02 18:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-30 11:00 [Bug] KASAN: null-ptr-deref in range in ib-comp-unb-wq ib_cq_poll_work yunje shin
2026-01-31 14:09 ` [PATCH] RDMA/umad: Reject negative data_len in ib_umad_write YunJe Shin
2026-02-01 9:30 ` Michael Gur
2026-02-02 18:34 ` Jason Gunthorpe [this message]
2026-02-03 6:46 ` YunJe Shin
2026-02-03 9:46 ` Leon Romanovsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260202183449.GL2328995@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=ioerts@kookmin.ac.kr \
--cc=joonkyoj@yonsei.ac.kr \
--cc=leon@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=yjshin0438@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox