From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00A2C28312F; Mon, 9 Feb 2026 14:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770648759; cv=none; b=nSVhgKuTCk30UHwcS7UNqDSFD01VV/Ajf2hmpyaLgxdQWWWGIU7nq0YdenPWNtb5/WY/NQ7dBesMPvawYgCzo1lPBF2zyxCXBx49oXYrlvJTrLVN09DetsLeNrGtgBDak6c9DaDTafFFOPWFTB1mH6VS3MLulDVfT+VyvHV0Iho= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770648759; c=relaxed/simple; bh=Q/ITZhk+ZZMv0fHkl/As8/FCfD+Rt7YDjxpt2KcdqvY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jp8fzNC5ExgUSaEw5xVx7eQ3wL07fAqurTaIzEYBmov3N4rDYkYqeRNp2U3E1Hp4sA+iYeIKHOlXh2G7AGOzIS/sxmB4X+q5ReVKiD6MzAXwlDC4Qct5NhfX6kdrqLoaW6mfToLYJqnly0J8uJXX3PV15/VT+m/Uc1ZCv+v88Ac= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=Q2ygCvwL; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="Q2ygCvwL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 689A6C116C6; Mon, 9 Feb 2026 14:52:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770648758; bh=Q/ITZhk+ZZMv0fHkl/As8/FCfD+Rt7YDjxpt2KcdqvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q2ygCvwLDya673XlRQAqAl6+uhQnXXICKRgQY8KIKFBMN/UHzhNf8/cmzID+GI015 ZlcQ78+m6m9PcB6Sy0VlpQfBUNWG8Cx6zzmlono+/LEjcYKbHj5/HYE+z+8U5nafHd v22tZjw+9IMBk2TQeHCQ5VaDnaeqv3WurXn7H2Ro= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, YunJe Shin , Sagi Grimberg , Joonkyo Jung , Keith Busch , Sasha Levin Subject: [PATCH 5.10 35/41] nvmet-tcp: add bounds checks in nvmet_tcp_build_pdu_iovec Date: Mon, 9 Feb 2026 15:24:56 +0100 Message-ID: <20260209142258.081418383@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260209142256.797267956@linuxfoundation.org> References: <20260209142256.797267956@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: YunJe Shin [ Upstream commit 52a0a98549344ca20ad81a4176d68d28e3c05a5c ] nvmet_tcp_build_pdu_iovec() could walk past cmd->req.sg when a PDU length or offset exceeds sg_cnt and then use bogus sg->length/offset values, leading to _copy_to_iter() GPF/KASAN. Guard sg_idx, remaining entries, and sg->length/offset before building the bvec. Fixes: 872d26a391da ("nvmet-tcp: add NVMe over TCP target driver") Signed-off-by: YunJe Shin Reviewed-by: Sagi Grimberg Reviewed-by: Joonkyo Jung Signed-off-by: Keith Busch Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/target/tcp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -294,11 +294,14 @@ static void nvmet_tcp_free_cmd_buffers(s cmd->req.sg = NULL; } +static void nvmet_tcp_fatal_error(struct nvmet_tcp_queue *queue); + static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd) { struct bio_vec *iov = cmd->iov; struct scatterlist *sg; u32 length, offset, sg_offset; + unsigned int sg_remaining; int nr_pages; length = cmd->pdu_len; @@ -306,17 +309,32 @@ static void nvmet_tcp_build_pdu_iovec(st offset = cmd->rbytes_done; cmd->sg_idx = offset / PAGE_SIZE; sg_offset = offset % PAGE_SIZE; + if (!cmd->req.sg_cnt || cmd->sg_idx >= cmd->req.sg_cnt) { + nvmet_tcp_fatal_error(cmd->queue); + return; + } sg = &cmd->req.sg[cmd->sg_idx]; + sg_remaining = cmd->req.sg_cnt - cmd->sg_idx; while (length) { u32 iov_len = min_t(u32, length, sg->length - sg_offset); + if (!sg_remaining) { + nvmet_tcp_fatal_error(cmd->queue); + return; + } + if (!sg->length || sg->length <= sg_offset) { + nvmet_tcp_fatal_error(cmd->queue); + return; + } + iov->bv_page = sg_page(sg); iov->bv_len = sg->length; iov->bv_offset = sg->offset + sg_offset; length -= iov_len; sg = sg_next(sg); + sg_remaining--; iov++; sg_offset = 0; }