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=1796381118; b=KNgEVGSAfXwHHAsbD/YPoLzeOO8toSlOeVdnI/uVuzT3tekqGuYBM4YU+wTikqKgzalw lvgAL9gMhfa9v1gM19MSLrufM1oSq147CycISNblC3uJvsG8YrnRvnb+9LzzNIDaLzsnZ FIFf8jArAkg54mcV1mJffwc0yCtIcGELVvvQsL3XhbzmbwrQTLz0D2Y8OKpds1sTDfE9B GnsaKjMUoP10oRmBFRN/07f3BLX/+6ZleprAmc+Ikoo86X1r7LWXp1wXb4Hl+WRAQoQ+N gKUDJKbbErc0aYpAhkFta06czH+qL/urjqF6/LXkvFhHoEGeUNGPIS4hVTWgCL6pW6w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381118; 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=C4d+ZWQyyjcOuaiK2aAo4zq+uAphCzIHylLj7wvltag=; b=V6G3oMe/VH7g6gGY/8ub/sKnvqjZIyOuUfqxnkKYeyoD3sfjzmeBea2wzey+yKA7SxTK drgENtGWOeUs3CALoLaGDTfoeYyjrvdjNH9LaqJX+Las8mlmrocHguLpA26IMkRWV03EX vp6mL7LhjTbCgxnhG4G3ANr1Ygc9VaH9sWfR8RBnpYP15EZ/VN2nPoZ0/HaxNYc6d9iTl krKM5Q0Z1aKn4U2cRvLHUMHWaAPt0nTbtXZK+0kIKYpJLJXbZdTIMHMHQVk/C3Cdf5E0u U1H8RJGOOF/TS5nkHFfVvriSfzzPSYcrcIpqAUG8H1meuXbIadNFVQN/xI/NZlZsH3A== 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=pRnzPaCB; 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 2825B606A32F; Fri, 4 Dec 2026 10:45:18 +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=pRnzPaCB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9407C1F00897; Fri, 4 Dec 2026 10:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381118; bh=C4d+ZWQyyjcOuaiK2aAo4zq+uAphCzIHylLj7wvltag=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pRnzPaCBGv3oLqqyi7Z5qWLvylrKXoBOJSuKjAflHVC8lC18T8b9WA9hd1VnRkueK Nad2w5QAIPcZYjKO6el4iUxW1Rcp4FbSJGnyMSVI4MoObTAXuULv6sNtn4ibqcYFcI pwSPIfh3SkBMPcdtHEkh68vDWEf/1qgJfTCzuPaI= 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 565/742] RDMA/srpt: bound the indirect descriptor table to the IU Date: Fri, 4 Dec 2026 19:07:09 +0900 Message-ID: <20261204100650.155922403@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 82d46dedf750addfad5480f79165cacb81c89650 upstream. srpt_get_desc_tbl() takes the number of INDIRECT descriptors from idb->table_desc.len, which the initiator controls, and checks it only against data_out_desc_cnt + data_in_desc_cnt, two more initiator fields. Both are u8, so the pair admits up to 510 descriptors, and nothing compares the table against the receive IU it has to live in. srpt_alloc_rw_ctxs() then walks idb->desc_list for that many entries. With the default srp_max_req_size of 8276 the table fits as long as the additional CDB is short, but ADDITIONAL CDB LENGTH is an initiator field too, and at its maximum of 252 bytes 510 descriptors end at 48 + 252 + 20 + 510 * 16 = 8480, which is past the end of the object. BUG: KASAN: slab-out-of-bounds in srpt_alloc_rw_ctxs+0x631/0x870 Read of size 4 at addr ffff888002d6a05c by task kunit_try_catch/43 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 Call Trace: dump_stack_lvl+0x3f/0x50 print_report+0xcd/0x620 ? alloc_pages_node_noprof+0xa2/0x140 ? srpt_alloc_rw_ctxs+0x631/0x870 kasan_report+0xde/0x110 ? srpt_alloc_rw_ctxs+0x631/0x870 srpt_alloc_rw_ctxs+0x631/0x870 srpt_test_parse+0x114/0x580 ? __pfx_srpt_test_ctx_common.constprop.0+0x10/0x10 ? __pfx_srpt_test_parse+0x10/0x10 ? srpt_test_ctx_init.constprop.0+0x4cb/0x6c0 srpt_test_run.constprop.0+0xc1/0xa60 ? pick_task_fair+0x126/0x1950 ? __pfx_srpt_test_run.constprop.0+0x10/0x10 ? update_curr.constprop.0+0x4a/0x390 ? __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 Allocated by task 43: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x30 __kasan_slab_alloc+0x6e/0x70 kmem_cache_alloc_noprof+0xfc/0x2b0 srpt_test_ctx_common.constprop.0+0x46f/0x9b0 srpt_test_ctx_init.constprop.0+0x30/0x6c0 srpt_test_run.constprop.0+0xb6/0xa60 kunit_try_run_case+0x1ca/0x4b0 kunit_generic_run_threadfn_adapter+0x7b/0xe0 kthread+0x36e/0x500 ret_from_fork+0x34d/0x620 ret_from_fork_asm+0x19/0x30 The buggy address belongs to the object at ffff888002d68000 which belongs to the cache srpt-kunit-iu of size 8276 The buggy address is located 8 bytes to the right of allocated 8276-byte region [ffff888002d68000, ffff888002d6a054) The KUnit harness that forces this is not part of this patch. A table_desc.len below one descriptor is the other way in. It gives nbufs zero, which the count check admits and a span check cannot catch either, since an empty table fits in any IU. srpt_alloc_rw_ctxs() then returns success with n_rw_ctx zero, no scatterlist is chained, and srpt_write_pending() reaches ib_post_send() with an empty work request list. rvt_post_send() evaluates !wr->next before the loop that tests wr against NULL, so an rdmavt device faults there whenever its send queue is idle. Reject a table that does not fit by comparing the span it occupies against byte_len, and reject an empty one. The span is the table offset plus struct_size(idb, desc_list, nbufs), and nbufs is at most 510 once the existing count check has passed, so it cannot saturate. The header always lies inside the allocated buffer, since the largest offset srpt_get_desc_buf() can return is 48 + 252 and the header is 20 bytes, so it ends at 320 while srp_max_req_size is at least MIN_MAX_REQ_SIZE, which is 996. It does not always lie inside the bytes the initiator actually sent, which is why the span starts at the table offset and covers the header as well. Fixes: a42d985bd5b2 ("ib_srpt: Initial SRP Target merge for v3.3-rc1") Cc: stable@vger.kernel.org Signed-off-by: Yehyeong Lee Link: https://patch.msgid.link/20261025013748.3755639-2-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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -1117,6 +1117,7 @@ static int srpt_get_desc_tbl(struct srpt struct srp_indirect_buf *idb = srpt_get_desc_buf(srp_cmd); int nbufs = be32_to_cpu(idb->table_desc.len) / sizeof(struct srp_direct_buf); + size_t desc_off = (uintptr_t)idb - (uintptr_t)srp_cmd; if (nbufs > (srp_cmd->data_out_desc_cnt + srp_cmd->data_in_desc_cnt)) { @@ -1128,6 +1129,18 @@ static int srpt_get_desc_tbl(struct srpt return -EINVAL; } + if (nbufs == 0) { + pr_err("received SRP_CMD with an empty indirect descriptor table\n"); + return -EINVAL; + } + + if (desc_off + struct_size(idb, desc_list, nbufs) > + recv_ioctx->byte_len) { + pr_err("received SRP_CMD indirect table (%d descriptors) that does not fit the %d-byte IU\n", + nbufs, recv_ioctx->byte_len); + return -EINVAL; + } + *data_len = be32_to_cpu(idb->len); return srpt_alloc_rw_ctxs(ioctx, idb->desc_list, nbufs, sg, sg_cnt);