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=1796381120; b=XfyqoJ9W641MLUsxgLnwaRL+IrChOP5loAd+MXW5HhXgCXfQPb227of+W9Gp2X6KTjnv 7P2dm1KjUUW54X06B54vXHBKEeJgf2d1NuCuAq4IGSFbDdlNCFk5iQL/A155NbR5c6c4D LiwBrlOtJfJiDIu6EGF7mZ5Il9OUKQNDOzp51Wekm+7Tw+hzZx5+wv3x+WcnndbfxET9o WkKNLxl4zp3bC1Bj2e1CB6n5oduqphtdqFWCFLpFPLv6NLqbuwv52f0o4BvF3jBh+6xRQ 2MIaoPB3jWzAExT/A4JGXLMJVFRDtwk73FwOjk+faSjD1BIXTl9V9b4KqXEXsQOTNXA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381120; 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=OCc8AXl0l5d4hvvdJmB7fWBf0yj6waKGjqyhRdVdFkM=; b=3gEy8SmRwUkesnBcZNOantArNS9VHhv3iWGQVc2+Y1G5jFqJ9tWbzbveAU2xBW1U0DSy khI3H8Il3+CQ7FFt+8Iju0omOMgJBk6bcNZbck/qFo/1QA++df5VWsvbIwWkYXNarmwZr wLnEZvufOSrQNdd5z6CiqMPCjwqmtI+rSieT4sOJjW1sMKLzkXaUUZMDeLemBvRQOHl4B pYpNxJkex9M5vkxX94B5HhqEShJ4b+uV9a5KZmwAUPYvOA1hUa2EeQSzOOzLgWRu+stYi CGbiYUbmDB+NlICBHbPK1ZUL/2Mo9zrtYHZabhjHiktDrTsoyfQ5JfokmoDvUBIPXaw== 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=1wEUkkJP; 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 6054F606A684; Fri, 4 Dec 2026 10:45:20 +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=1wEUkkJP Received: by smtp.kernel.org (Postfix) with ESMTPSA id D01961F00935; Fri, 4 Dec 2026 10:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381120; bh=OCc8AXl0l5d4hvvdJmB7fWBf0yj6waKGjqyhRdVdFkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=1wEUkkJP1LCUqBHxTv/UFl1ZW5+znnsokMce1TO915c+u8YVJ+v4LMH9VI9dxFHRe DxyHXBKY4AiYp9QdbbPoJ1rGZ+TbpBhKQp/uRwGuNC+5/8xTeYcTvGtRlFltqDBCbM gUrLpmYeUCQSP18WnNvMdZ6uxI80i1l2XX+3knZE= 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 7.3 566/742] RDMA/srpt: reject zero-length buffer descriptors Date: Fri, 4 Dec 2026 19:07:10 +0900 Message-ID: <20261204100650.180214460@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-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 @@ -979,6 +979,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)