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 EB8DD3446C7; Mon, 9 Feb 2026 14:56:00 +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=1770648961; cv=none; b=gL9SFbCvY/zSydWozKE9pXH+Y35NjvCpJatfuLj7YVsWnNmhqSWiIrkkq3vrdC90BEl9aMXbEwK5aabUcQ0ntoeANPCXg5Qs7tYeN6jpSKm+L6nrfnCjuXwBfmdFqsN8FySa/+CzmZSedpKphRgd0oBbrSdNFyGGNnbQ/54lXZM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770648961; c=relaxed/simple; bh=32l25ycSUhPAQMeFDU+qQrErkrp+cHvGQBUIqZbCqak=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uu8z2AhPTDZ1HBCoA8XJfYUmIc2Xb5WUJPYMOsBGtAtTpcVFzSc0DTL8iFWLZpCczdw3MGEByaTtMh7Uw4O5NETGLelJS5SnFaUxyyjLqeO3iBqKPRLOMKlPG1t3rh/6qtt+x6KJcswkXPvYd0yx6tptfp4U0uPMHUogVZhwTGk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=pYXUg6TY; 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="pYXUg6TY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E94CDC116C6; Mon, 9 Feb 2026 14:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770648960; bh=32l25ycSUhPAQMeFDU+qQrErkrp+cHvGQBUIqZbCqak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pYXUg6TYXXDTYFVL0JXkDP7KRGznVLw6YayDZkFJtgEH2nbPT97DcMmTgZ6Rs6V6r OYGnvHusKXbLCvFPrftomPUwVSCX4ckCMDJsYO/8bv58aJtydTUoWwPfHfIjzUKlZZ Q7K5vrSCV1loIpHTGK1pSKZY0NwA/zaGHGOyVCd4= 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.15 59/75] nvmet-tcp: add bounds checks in nvmet_tcp_build_pdu_iovec Date: Mon, 9 Feb 2026 15:24:56 +0100 Message-ID: <20260209142303.969454504@linuxfoundation.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260209142301.830618238@linuxfoundation.org> References: <20260209142301.830618238@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.15-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 @@ -306,11 +306,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; @@ -318,17 +321,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; }