From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=95.215.58.56 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796559944; b=Jed5+87zgo8Fc0G+/HRMQCkyUsMwDyv6t2fuwRvRetf9+QzV/D53PFdfkOvMmPXy6BKm IHWEEj5hZDSyr/EmigqH0YY6Z+ZSBKETZwhUCFoPmJtwgYln4ISYPPQMeCLVq1WV40dMQ aALIy5EarTMm51VPG32RtJPJM+hw6Ls8s07ltuFGnLapyXyg8+x7FFdJZfJps2L3KmGso 0xYynirwGq4r6qKWLIcy0Fn9xB3Ei9r5eKFtgAufFg8so78mHbtDOCN5+7tfm34EwT34A EveOWDOvPLZkepEGMCPTIWhBEBvwjHbvxxg5ygf5LqcIK+vjOJLmGb+ACy29hQgqhQA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796559944; h=DMARC-Filter:X-Envelope-To:DKIM-Signature:X-Envelope-To:Received: X-Mizu-Trace-ID:X-Migadu-Flow:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=MaisRExKvEbZrUrFUK0PQFwy6kGZY9P13J7i6LXJT3U=; b=wBKau6GIp4+iEnbA0aCUoh4hBctgBXZO8XkSrKnNQytIznKjCtfTy2tZfIuE0e6A1vzU AR7NafZzKPnMpYuRdn315K1XuDpYQ/jnQQ1xIm6dvhjJiIhMFge5LM7NtBm2zrsIG5Arh vu2sQexAi1I9EIZ0q2Un0xTyhjaNa9tczSBlnLZ3fBvlD6PgElPLCUgA/pCF74GONHP1L FHFxrvEyCnPs5F1F9m5nx4JU3+MHkHCs4LsIIomQrwIUowVNPhn1LiafRlybFB0fDHCrG pKPfVX3zAXeWgfBk1xaaXZL2Pny0fxMMPWMvGBPGU7Ojdhp9TvjMO+TlOTM6G6yYmYw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=tuDATWVs; arc=none smtp.remote-ip=95.215.58.56 Received: from mta1.migadu.com (out-56.mta1.migadu.com [95.215.58.56]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D355606A31F for ; Sun, 6 Dec 2026 12:25:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7D355606A31F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.dev header.i=@linux.dev header.a=rsa-sha256 header.s=key1 header.b=tuDATWVs X-Envelope-To: linux-rdma@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ai0kmiSskTUteG7ISphhc5QGY9Y7u60xsosbeO+lyAo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1796559941; v=1; x=1797164741; b=tuDATWVs1Da7GYszIt58eZMT10hSOuNmxWYcInunEfk3KveB9+MgQZ9gX5Ee2j2lh8i3XJVi S1tuMEctYRnoClGqM6U+BZFCvGjmR/14EhrxKwuf3lsbMspAzfu8ikGWiP+SJ4v3WftD5uePkmA choU9Pj+p9lcTiYiyrksrvgQ= X-Envelope-To: linux-rdma@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 1addb9ae797e6a76; Sun, 06 Dec 2026 12:25:30 +0000 X-Mizu-Trace-ID: 1addb9ae797e6a76 X-Migadu-Flow: FLOW_OUT Message-ID: Date: Sun, 6 Dec 2026 13:25:27 +0100 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH rdma-next v3] RDMA/siw: Fix overflow in inline SGE length check To: Andrew Stellman Cc: Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org References: <20261205233234.56335-1-bugs@stellman-greene.com> From: Bernard Metzler In-Reply-To: <20261205233234.56335-1-bugs@stellman-greene.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 06.12.2026 00:32, Andrew Stellman wrote: > From: Andrew Stellman > > siw_copy_inline_sgl() adds each u32 SGE length to the int running total > 'bytes' before checking the total against SIW_MAX_INLINE, so lengths that > add up to 2^32 or more can wrap the total to a small value, and memcpy() > then copies the full SGE length into the inline area of the send queue > entry. With inline SGE lengths of 16 and 0xfffffff8 from a kernel > caller, siw_post_send() returns 0 and KASAN reports: > > [ 45.087395] ================================================================== > [ 45.087402] BUG: KASAN: vmalloc-out-of-bounds in siw_copy_inline_sgl.isra.0+0xdc/0x1e0 > [ 45.087432] Write of size 4294967288 at addr ffff800080069038 by task insmod/418 > > [ 45.087439] CPU: 4 UID: 0 PID: 418 Comm: insmod Tainted: G O 7.4.0-rc5 #1 PREEMPT(full) > [ 45.087442] Tainted: [O]=OOT_MODULE > [ 45.087443] Hardware name: linux,dummy-virt (DT) > [ 45.087445] Call trace: > [ 45.087449] show_stack+0x18/0x24 (C) > [ 45.087458] dump_stack_lvl+0x60/0x80 > [ 45.087461] print_report+0x17c/0x4d8 > [ 45.087464] kasan_report+0xbc/0x124 > [ 45.087473] kasan_check_range+0x100/0x1a8 > [ 45.087475] __asan_memcpy+0x54/0xa0 > [ 45.087477] siw_copy_inline_sgl.isra.0+0xdc/0x1e0 > [ 45.087480] siw_post_send+0x8cc/0x1900 > [ 45.087483] siw050_init+0x2a0/0x1000 [siw050_kclient] > [ 45.087487] do_one_initcall+0xd0/0x320 > [ 45.087490] do_init_module+0x22c/0x6d0 > [ 45.087495] load_module+0x3ac4/0x4dec > [ 45.087496] init_module_from_file+0x164/0x180 > [ 45.087498] __arm64_sys_finit_module+0x334/0x740 > [ 45.087500] invoke_syscall+0x74/0x2c0 > [ 45.087505] el0_svc_common.constprop.0+0xac/0x230 > [ 45.087507] do_el0_svc+0x40/0x58 > [ 45.087509] el0_svc+0x38/0xa0 > [ 45.087522] el0t_64_sync_handler+0xa0/0xe4 > [ 45.087524] el0t_64_sync+0x198/0x19c > > [ 45.087527] The buggy address belongs to a 1-page vmalloc region starting at 0xffff800080069000 allocated at vcalloc_noprof+0x20/0x40 > [ 45.087539] The buggy address belongs to the physical page: > [ 45.087541] page: refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x1270e8 > [ 45.087545] flags: 0xbfffe0000000000(node=0|zone=2|lastcpupid=0x1ffff) > [ 45.087549] raw: 0bfffe0000000000 0000000000000000 dead000000000122 0000000000000000 > [ 45.087550] raw: 0000000000000000 0000000000000000 00000001ffffffff 0000000000000000 > [ 45.087551] page dumped because: kasan: bad access detected > > [ 45.087552] Memory state around the buggy address: > [ 45.087553] ffff800080069280: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > [ 45.087554] ffff800080069300: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > [ 45.087555] >ffff800080069380: 00 00 00 00 00 00 00 00 f8 f8 f8 f8 f8 f8 f8 f8 > [ 45.087555] ^ > [ 45.087556] ffff800080069400: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > [ 45.087559] ffff800080069480: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 > [ 45.087560] ================================================================== > > Make the running total a u64 so it can't wrap; such a work request now > fails with -EINVAL instead of being posted. > > The issue was found by Claude Opus 5.5 running Quality Playbook, an > LLM-driven code review tool: > https://github.com/andrewstellman/quality-playbook > The fix was drafted with OpenAI GPT-6 (Codex), this changelog with > OpenAI GPT-6 (Codex) and Claude Opus 5.5, and both were reviewed by me. > > Fixes: 303ae1cdfdf7 ("rdma/siw: application interface") > Suggested-by: Bernard Metzler > Signed-off-by: Andrew Stellman > --- > v3: Cast the return value to int, as Bernard Metzler suggested. No > functional change; the test results below are from v2. > v2: Make 'bytes' a u64 instead of checking before the addition, as > Bernard Metzler suggested. > https://lore.kernel.org/r/20261205150402.97273-1-bugs@stellman-greene.com > v1: https://lore.kernel.org/r/20261202165018.50109-1-bugs@stellman-greene.com > > Tested on mainline 19cc08c1a6a6 (7.4.0-rc5) in arm64 QEMU with KASAN > and CONFIG_RDMA_SIW=y, using an out-of-tree module that posts an inline > IB_WR_SEND: SGE lengths 16 and 0xfffffff8 got -EINVAL with bad_wr set > and no KASAN report, and a 16 + 8 byte inline send returned 0. > > A reproducer is available on request. > > drivers/infiniband/sw/siw/siw_verbs.c | 13 ++++++------- > 1 file changed, 6 insertions(+), 7 deletions(-) > > diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c > index 80ef4cb95f..95896b6f5e 100644 > --- a/drivers/infiniband/sw/siw/siw_verbs.c > +++ b/drivers/infiniband/sw/siw/siw_verbs.c > @@ -657,7 +657,8 @@ static int siw_copy_inline_sgl(const struct ib_send_wr *core_wr, > { > struct ib_sge *core_sge = core_wr->sg_list; > void *kbuf = &sqe->sge[1]; > - int num_sge = core_wr->num_sge, bytes = 0; > + int num_sge = core_wr->num_sge; > + u64 bytes = 0; > > sqe->sge[0].laddr = (uintptr_t)kbuf; > sqe->sge[0].lkey = 0; > @@ -668,20 +669,18 @@ static int siw_copy_inline_sgl(const struct ib_send_wr *core_wr, > continue; > } > bytes += core_sge->length; > - if (bytes > SIW_MAX_INLINE) { > - bytes = -EINVAL; > - break; > - } > + if (bytes > SIW_MAX_INLINE) > + return -EINVAL; > memcpy(kbuf, ib_virt_dma_to_ptr(core_sge->addr), > core_sge->length); > > kbuf += core_sge->length; > core_sge++; > } > - sqe->sge[0].length = max(bytes, 0); > + sqe->sge[0].length = bytes; > sqe->num_sge = bytes > 0 ? 1 : 0; > > - return bytes; > + return (int)bytes; > } > > /* Complete SQ WR's without processing */ Thanks Andrew. Acked-by: Bernard Metzler