From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.171 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230221; b=JRqz5A2Fpp2IPqbPQtBDdM25zBf6sTDlTeLy2yWNeThrXLU3TAadY5lA2/IW8uOra+u4 BdOXqgVQubveoTKSkZeq3a2ZFhNJc7eWaGoMjUd3qpimf3pFh2v1uWIzgv2rPX6a1DeP3 ODET3VtMnKLNXMw2rAet6cawH02W1YfZtBEYAP6l+uSdKH8NU45StKqweTa1Vz/8yLm5F uzhSg3XmX+FPipBJTQMzv+SA9PqOGePX8/2TEcOcLeXWz0nKJyf5iyRMLF9VqMTDZ/BoB WN0UNj3sfq1d012psSZ1ofic4ejh0SXQRFdkiB91VKQ5jXvAz+w8Ksg185pqp68RqVQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230221; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=lSErrClaNvr3ATtJT44mQ4sDoqKkmk7ih43st3xyl1k=; b=doxPMa5+KyFQOF28aWn0rWAl+DOrLx50EoRUO0gSq7sCmdKdnpPg1ViJuJOEnv904V1h dvqdQ0cqv5WTvtVD/k/pSAl6ypiDmk+V74w0kQpuP6A8L1BeAmAUVGiSUK0FSrBU8Rpek iu1EOY0IVABvrpa5e9lDAeAUqQgJXSN1gmOg5sCdM8x5/sH9jsJE2pC6CIhy86E3DjK3q /za7kl8FtacUZkbba/VWGnUjmuF8whuChjnbaEexdxMPxogcaSvL9vr0CdWvW31I46HU0 z4mdBoV3SAGZopfghLeB+bzo7Gzb650nrnW2niTH3YPFvhYJ4I2dKkGXdsFNWhAQtCQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=stellman-greene.com; spf=none smtp.mailfrom=stellman-greene.com; dkim=pass header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=jXDBE7RD; arc=none smtp.remote-ip=209.85.222.171 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) (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 1CA80606A334 for ; Wed, 2 Dec 2026 16:50:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 1CA80606A334 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=jXDBE7RD Received: by mail-qk1-f171.google.com with SMTP id af79cd13be357-94999a08973so1210139985a.0 for ; Wed, 02 Dec 2026 08:50:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stellman-greene-com.20260707.gappssmtp.com; s=20260707; t=1796230220; x=1796835020; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=lSErrClaNvr3ATtJT44mQ4sDoqKkmk7ih43st3xyl1k=; b=jXDBE7RDbeHwb+nZu6WUFpxQAvMiP1QPpiZmWrTYpUJrOJvwbvB0Os3udZ8btj4qYC APbV3//rKDD0oJ326PFKy9j5Hczt6CPMYPIWtLH0U8kOYxz/fv1o2vmSa4kzCO37z12B +8cNvXNKOOYQMrhfT8ePK0rSI/gk9aKkhab15CRs3y+34LkJMDFbRwSBM3J9NSOSrYIx ZkfKaxP65ZrpFegAbCnN2qY2IEbM2HjUXguXJZWkqoD/gX4hlqCmbankii/+SxqBju8y Lb91BXUGqX+iA5tXYqmIJa/X4hmUAwNd0+iwz1FLyncPmZ2uAy/BEmHl5yuOo8kp2T2B 98aQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796230220; x=1796835020; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lSErrClaNvr3ATtJT44mQ4sDoqKkmk7ih43st3xyl1k=; b=0+RHDOspcUxs+hHfLx/oDbNyA+a4xBnPk3TLKYPvnWMBp5SHotpUMlPVbcz2aPuXAH mVattZDRRbgRa+2gM67vq3kifTOXknTfGozQsmDy32xEXUd3ms3pynWqTRyHuOUFPmQ6 sm11duakgd39Cvn37bY/r7U4D4dbFlEoK2l5cBWF2klPOY4KBaYGweWT+FbxV5Y4OJmL nxlOBc20nanyejr4juCsYvnCwXgFwB1x+W4kxVwhD/JzA+jq8FrE5pEQtZDnIcindBAh L5vuUk9zDjlc9LslbJfebtCneib9w02dhtQoSqi0MUagakihoU/r7Gw2d8F6YCW3Z26V J7hA== X-Forwarded-Encrypted: i=1; AL+hErHCgbhWNBZF7Gt1jnwWvOG6mY404rCKr1jJI4ZyMB/j2oSBzRgvIc/WL5cXNlrWqiwDM3GCCb7JFm1A@vger.kernel.org X-Gm-Message-State: APuU4Z9Lk9uLaMiE9A3XgKNiXpksLxtiny5K6u+otK+kbPmHbvlcHXEh xGMhPIfrWDg/GDJN1EHWo8WFEq1FkRH6KRuvSyUtd7cm2wpT3cCH5T0FnOzQhbENTCk= X-Gm-Gg: AZFdTZdaYwWDe8clvvXP4WXF3aBLvON+BLhOieU5NvabKnA1WDOg7Qq04/TzUtZAeCC WgybMl764+PFrCwp+otXKuePUUjfipYrDMPrhTrSOLr5+uCwwN4Djzn28DYNESCC5FufbeE3gSb FHn9UbgamSe9G0sdGRaWs3cTeF0j1wlq+HzctPm5e7nSD0kJjjkAOkYgEMJM1zftdlgKPzWLTIS A7QCPVJIKrK1Mv1c22ykxlEWL+rUpWUxlMe9NLjbWPFkN3Pl80vWT3rE5TYgg8M9QiV7mfjWILi qbqmkA6UTCBlxmi0KWvpMxNN6Jas+JhLZQAGARdxtsh3hidTG2oQqD4u0mZBH2UzjwmfL79ghWb E4hFfGkiR5NK+xD8GqUWTfTe9aw4rcBxqLDAYKbDqExtCI/MH0GQ5fMY0JpmuoU4lv8M7Qc/o4e NmxyTxbCz9U0dwR6lfoILkTHA0vXT+VVONQF94wbZIQf5dani1biC1aIeRkcHEpxntysJSxIVdg 2QFPL+MWAhN+pXSL4QlhZLA0ZUi2JofNmTGkW1EBtKz/cEkn8aTa0EKFaWAmt1vmOXUZh4XQ+pr o0qdnVKieqq3jxSGQM0rEGn4JAuYwsub4uSAvzZDqfGXfkHj+Vd9f7Dnz50tiaf6qaXRyxCaNZd / X-Received: by 2002:a05:620a:3715:b0:949:a139:2f2a with SMTP id af79cd13be357-949ba7ccbe4mr7421305085a.9.1796230219796; Wed, 02 Dec 2026 08:50:19 -0800 (PST) Received: from Mac.mynetworksettings.com ([2600:4041:5c28:200:9fd:9761:5b78:f32c]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb418241sm3087916485a.38.2026.12.02.08.50.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 08:50:19 -0800 (PST) From: Andrew Stellman To: Bernard Metzler Cc: Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH rdma-next] RDMA/siw: Fix overflow in inline SGE length check Date: Wed, 2 Dec 2026 11:50:18 -0500 Message-ID: <20261202165018.50109-1-bugs@stellman-greene.com> X-Mailer: git-send-email 2.53.0 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 Content-Transfer-Encoding: 8bit From: Andrew Stellman siw_copy_inline_sgl() keeps a running total of the inline data length in the int 'bytes'. For each SGE it adds the u32 length to the total first and only then checks the total against SIW_MAX_INLINE. If the lengths add up to 2^32 or more, the total wraps around, and if the wrapped total is small enough, the check passes and memcpy() is called with the full SGE length to copy into the inline area of the send queue entry. A kernel caller that posts an IB_SEND_INLINE work request with SGE lengths of 16 and 0xfffffff8 gets a total of 8. 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] ================================================================== Check each SGE length against the space left in the inline area before adding it, so the total can't wrap. Such a work request now fails with -EINVAL instead of being posted. Fixes: 303ae1cdfdf7 ("rdma/siw: application interface") Signed-off-by: Andrew Stellman --- Leon, thanks for your feedback on my iwcm patch. Here's a writeup of everything I did, including full disclosure of everything I used AI for. The bug is in siw_copy_inline_sgl(). It adds each SGE length to the running total first and only checks the total against SIW_MAX_INLINE after that, so if the lengths add up to 2^32 or more, the total wraps around. If the wrapped total ends up small enough, the check passes and memcpy() gets called to copy the whole SGE length into the inline area of the send queue entry. In my test that was almost 4 GB going into a one-page vmalloc buffer, which is the write KASAN flagged. As far as I can tell, only kernel callers can hit this, since siw_post_send() rejects work requests on user-mapped send queues. I only tested it with my own module, and I haven't checked whether any in-tree caller does this. I tested it on: - mainline 19cc08c1a6a6 (7.4.0-rc5) - arm64 QEMU/HVF with KASAN and CONFIG_RDMA_SIW=y - an out-of-tree test module that I loaded as root - an inline IB_WR_SEND from that module, with SGE lengths 16 and 0xfffffff8 Just to be 100% transparent about AI use, I found this with my open-source Quality Playbook skill (https://github.com/andrewstellman/quality-playbook) running Claude Opus 5.5, but then I reviewed everything and made sure it's a real bug so I'm not just bombarding maintainers with AI slop. OpenAI GPT-6 drafted the fix, which moves the check ahead of the addition so each SGE length is compared with the space that's left before it's added to the total. I read the KASAN report, but I also used Claude Opus 5.5 to help me find the relevant bits and explain what's going on, and to help me write this description. To me this looks like a valid bug fix because of the red-green test. On the unpatched kernel the test module triggered the KASAN report above and siw_post_send() returned 0 (red). With the patch applied, the same test got -EINVAL with bad_wr set and KASAN didn't report anything (green). When I reverted only the fix, the KASAN report came back. A normal inline send of 16 + 8 bytes returned 0 with and without the fix. A reproducer is available on request. drivers/infiniband/sw/siw/siw_verbs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/sw/siw/siw_verbs.c b/drivers/infiniband/sw/siw/siw_verbs.c index 80ef4cb95fc3..496838231ac3 100644 --- a/drivers/infiniband/sw/siw/siw_verbs.c +++ b/drivers/infiniband/sw/siw/siw_verbs.c @@ -667,11 +667,11 @@ static int siw_copy_inline_sgl(const struct ib_send_wr *core_wr, core_sge++; continue; } - bytes += core_sge->length; - if (bytes > SIW_MAX_INLINE) { + if (core_sge->length > SIW_MAX_INLINE - bytes) { bytes = -EINVAL; break; } + bytes += core_sge->length; memcpy(kbuf, ib_virt_dma_to_ptr(core_sge->addr), core_sge->length); -- 2.53.0