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 597BF352C3C for ; Sat, 7 Feb 2026 15:05:45 +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=1770476745; cv=none; b=OWrrvKEm08mTmWZRw8CH/RYNRd2CyEWIoruCWOs4tfeqOiZd6lYmRA1YEoAlTQLLRFjevhHpGdKDOFI7TpkfYtD1va8MW+IBUgYPttGSfUhxgxH5o/RR/A8S1hFxvD2wkGqb7v74qllSN0CbFQtcKEzZSUrXQ19phu8Bb9toKqM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770476745; c=relaxed/simple; bh=XzKvRdZxU2LgEjUGf4l3E6A8mJhsZQP4b90xl2TIyaA=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=X0+pFg+LEFK5f2OYY1GYol8YtMMlYBQ/A2FyRCuvdIbYFGtPYlysi4u278vkqKUvRuXs/LusjRD8aj01IOTV/+X9lSNnWucKN1RRoyG857rTLvI/qosK62vN98BBoLzqRH5M4NrnCzreMPvIm6pbEXl4TIagmmo8k6h5IOE3Y5w= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=BqNektM+; 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="BqNektM+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A630FC116D0; Sat, 7 Feb 2026 15:05:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1770476745; bh=XzKvRdZxU2LgEjUGf4l3E6A8mJhsZQP4b90xl2TIyaA=; h=Subject:To:Cc:From:Date:From; b=BqNektM+xJ/yNs30XIRBNY7JUoEE8HQrWqgnTAni1HKF5BJ+SgrD50d32xdfiUFU0 3oz6q5c+IYgGRcnXbe0N1Prh7rV6Z9C9FW7Pmd6wHdwCKH9aGDXwlvCwXLiERfuF7g GZm7av7vlUHmhoIzlu/5DtXbex7LK7jzkDbxqqcA= Subject: FAILED: patch "[PATCH] nvmet-tcp: add bounds checks in nvmet_tcp_build_pdu_iovec" failed to apply to 5.10-stable tree To: yjshin0438@gmail.com,ioerts@kookmin.ac.kr,joonkyoj@yonsei.ac.kr,kbusch@kernel.org,sagi@grimberg.me Cc: From: Date: Sat, 07 Feb 2026 16:03:41 +0100 Message-ID: <2026020741-chitchat-symphonic-a96f@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.10-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.10.y git checkout FETCH_HEAD git cherry-pick -x 52a0a98549344ca20ad81a4176d68d28e3c05a5c # git commit -s git send-email --to '' --in-reply-to '2026020741-chitchat-symphonic-a96f@gregkh' --subject-prefix 'PATCH 5.10.y' HEAD^.. Possible dependencies: thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 52a0a98549344ca20ad81a4176d68d28e3c05a5c Mon Sep 17 00:00:00 2001 From: YunJe Shin Date: Wed, 28 Jan 2026 09:41:07 +0900 Subject: [PATCH] nvmet-tcp: add bounds checks in nvmet_tcp_build_pdu_iovec 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 diff --git a/drivers/nvme/target/tcp.c b/drivers/nvme/target/tcp.c index 549a4786d1c3..bda816d66846 100644 --- a/drivers/nvme/target/tcp.c +++ b/drivers/nvme/target/tcp.c @@ -349,11 +349,14 @@ static void nvmet_tcp_free_cmd_buffers(struct nvmet_tcp_cmd *cmd) 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; @@ -361,9 +364,22 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd) 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) { + if (!sg_remaining) { + nvmet_tcp_fatal_error(cmd->queue); + return; + } + if (!sg->length || sg->length <= sg_offset) { + nvmet_tcp_fatal_error(cmd->queue); + return; + } u32 iov_len = min_t(u32, length, sg->length - sg_offset); bvec_set_page(iov, sg_page(sg), iov_len, @@ -371,6 +387,7 @@ static void nvmet_tcp_build_pdu_iovec(struct nvmet_tcp_cmd *cmd) length -= iov_len; sg = sg_next(sg); + sg_remaining--; iov++; sg_offset = 0; }