From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382648; b=GFa/cF6J0mfkL23ZLixtzV+K6P9oP7CcH/WsJN3dyN6xEldgLjUsW4LzXgFL43ZTGX/Z QDCGxBfY4Iz9rTH6EdzcQYrK5IkfIkY/0f2VswkD4HITSYBOIQegoBZzsMI940invUAyl tGAY9EQj17xj6FnvziaTF3TQYo/gNl0k88E4qP+/zbga8Wd3r4U/gzzm3u5F9tN0FbTpo e5lFZT+PVj2UQWAzBVCGxip3QJBECC3Gx5SWQoaPmLmUYclEGS8ML3LADI9/btAmTHraq PgjtXiYGVzMjP1IXXBu7/osnhEKFQ30gicKRo06rDoT4G3FmAiHGS8rwSsVQRgKou5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382648; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=I7YfqXGa+Xo9sGZQYsNNWYsIlWwh28J6vq79GAP5Gnk=; b=LV8Fl2OK8Zp0bFUxyhJUk2tRAEAwxtErgbpl6UDYbKElVTAyk8JDZWsgYeEg10WhdT5d KHrb1anm1fU9wfj6hB6pEnYzSvc0WerRgk9DQoqMkXMs4VjkKMk0lk3VwXe501OXARRyj LOvn/UkZK37fgSorJJxWjCcU/MLaZOk6qe6bqXtqKxqJWuShe9hqPcRWlI/wMQ+WNAaQx VxGzQjqAR/O9esDbrObOgfnmYiprX0bIbRDdY0S5eIbLTCQ0Ny72KMt0+nuo+JFtQYP2I O2tb2xJcF7GcpjK7s0k+c1M3awlVhTF2bXCTxfLpKA6uVE5pGRomDLZwcqjg8N66dDA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=U00PNn+N; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3C7CC606A322; Fri, 4 Dec 2026 11:10:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=U00PNn+N Received: by smtp.kernel.org (Postfix) with ESMTPSA id A82DF1F000C2; Fri, 4 Dec 2026 11:10:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382648; bh=I7YfqXGa+Xo9sGZQYsNNWYsIlWwh28J6vq79GAP5Gnk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=U00PNn+Nrqtf3m2wXk4syDgHGsZDiCmlQqKM2YYcYrmuxUMYZ8f0Xgwf2QO9uSLE9 I5tLkwmthRcausiXAF4E4zWrxrKVdHZYZtmxc9JlUS8YNc4etet2u/Ei7t3HlOiV8M arq4q7LjNdHE74BWxRZJSnoFrTyqMWOaUiEouk60= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yehyeong Lee , Bart Van Assche , Leon Romanovsky Subject: [PATCH 6.18 503/703] RDMA/srpt: reject zero-length buffer descriptors Date: Fri, 4 Dec 2026 19:06:42 +0900 Message-ID: <20261204100641.182397038@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@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 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yehyeong Lee commit 252fc17ff4fbc2c6ead5e2f9404c9d0c490f0965 upstream. srpt_alloc_rw_ctxs() takes each buffer descriptor length straight from the wire and hands it to target_alloc_sgl(), which has no length check of its own. For the single descriptor of a DIRECT request, and for the last descriptor of an INDIRECT table, chainable is false, so a zero length makes sgl_alloc_order() compute nalloc zero. kmalloc_objs() answers that with ZERO_SIZE_PTR, which is not NULL, so the allocation looks like it succeeded and sg_init_table(sgl, 0) runs. That reaches sg_init_marker(), which does sg_mark_end(&sgl[nents - 1]) with nents unsigned, so the index is 4294967295 rather than minus one and the read modify write of page_link lands far outside any allocation. Oops: general protection fault, probably for non-canonical address 0xdffffc03fffffffe: 0000 [#1] KASAN PTI KASAN: probably user-memory-access in range [0x0000001ffffffff0-0x0000001ffffffff7] CPU: 0 UID: 0 PID: 43 Comm: kunit_try_catch Tainted: G N 7.3.0-12378-g6fba331225f5-dirty #1 PREEMPT(lazy) Tainted: [N]=TEST RIP: 0010:sgl_alloc_order+0xb6/0x370 Code: ef 01 4c 89 e2 49 89 c4 31 f6 49 c1 e7 05 48 89 c7 e8 ae e0 cb ff 4d 01 e7 48 b8 00 00 00 00 00 fc ff df 4c 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 6b 02 00 00 49 bc 00 00 00 00 00 fc ff df 49 8b RSP: 0000:ffff888002d4fa38 EFLAGS: 00010202 RAX: dffffc0000000000 RBX: 0000000000001000 RCX: 0000000000000000 RDX: 00000003fffffffe RSI: 0000000000000000 RDI: 0000000000000010 RBP: 0000000000000000 R08: ffff888002b158a0 R09: 0000000000000000 R10: 0000000000000010 R11: 0000000000000037 R12: 0000000000000010 R13: ffff888002d6803c R14: 0000000000000000 R15: 0000001ffffffff0 FS: 0000000000000000(0000) GS:0000000000000000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: ffff88802f1c8000 CR3: 000000002e458000 CR4: 00000000000006f0 Call Trace: target_alloc_sgl+0x2b/0x70 srpt_alloc_rw_ctxs+0x2ef/0x870 srpt_test_parse+0x114/0x580 ? __pfx_srpt_test_parse+0x10/0x10 ? srpt_test_ctx_init_direct+0x17d/0x280 srpt_direct_len0_test+0xa4/0x280 ? __pfx_srpt_direct_len0_test+0x10/0x10 ? __set_cpus_allowed_ptr+0x181/0x240 ? __pfx_read_tsc+0x10/0x10 ? ktime_get_ts64+0x192/0x250 kunit_try_run_case+0x1ca/0x4b0 ? __pfx_kunit_try_run_case+0x10/0x10 ? kthread_affine_node+0x24b/0x370 ? __pfx_kthread_affine_node+0x10/0x10 ? __pfx_kunit_try_run_case+0x10/0x10 ? __pfx_kunit_generic_run_threadfn_adapter+0x10/0x10 kunit_generic_run_threadfn_adapter+0x7b/0xe0 kthread+0x36e/0x500 ? __pfx_kthread+0x10/0x10 ret_from_fork+0x34d/0x620 ? __pfx_ret_from_fork+0x10/0x10 ? __switch_to+0x22/0xdd0 ? __pfx_kthread+0x10/0x10 ret_from_fork_asm+0x19/0x30 The KUnit harness that forces this is not part of this patch. A zero length descriptor elsewhere in a table is chainable, so one entry is allocated and that write does not happen, but the entry count comes back zero and the mapping in rdma_rw_ctx_init() then refuses it. The target core never hands the same allocator a zero length. Its own call in transport_generic_new_cmd() sits behind a cmd->data_length test. Reject a descriptor whose length is zero. The existing unwind label covers the first iteration, where its loop body does not run because nothing has been allocated yet. Fixes: b99f8e4d7bcd ("IB/srpt: convert to the generic RDMA READ/WRITE API") Cc: stable@vger.kernel.org Signed-off-by: Yehyeong Lee Link: https://patch.msgid.link/20261025013748.3755639-3-yhlee@isslab.korea.ac.kr Reviewed-by: Bart Van Assche Signed-off-by: Leon Romanovsky Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/srpt/ib_srpt.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -980,6 +980,12 @@ static int srpt_alloc_rw_ctxs(struct srp u32 size = be32_to_cpu(db->len); u32 rkey = be32_to_cpu(db->key); + if (size == 0) { + pr_err("received SRP_CMD buffer descriptor with zero length\n"); + ret = -EINVAL; + goto unwind; + } + ret = target_alloc_sgl(&ctx->sg, &ctx->nents, size, false, i < nbufs - 1); if (ret)