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=1796381311; b=BrsYu7i/K2m9SxuJ6xrsCwgmCmhMcRykRCKYfu4yYtP/HH5Y6aMRnn3DS6uXmySv2C7M LYNRHQUrIFKfpcE0BcZz/BGCJ3RWtOYAlkl3E8RDCxrVu7/zpZVOrg9gw7jmqn1PqB53d dfkJHwNChTGDX92LgLwF0ziSAh9K3jFJNEsbNpNp5NgOAkUGdqoW8i9kHvRFR0AlDVX9B Z/lRxdhnziTBxCRA8esQIqZvAC/ujjxZXb7fUturV0bpCHaiZwUDTkrFb5WRR0iFrjxN/ Q/+MN52Js3A/u6vRyHcMqrgBooEkdzr0T0RB4KVCvCGaqysdMHjOsrl7idGwt/zxxAw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381311; 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=bedPS6EfFS7tALEYI6BjGhIiNcbDzeaFp07FfDwPOVE=; b=zeVEo4/BmcUlLG3wjzhXb7KaaPJuk322lQ4GuNw9Sb5yc1u06p8S1E1AHA07Il3mwmGL 8+CLR2w87S60F3LBzJZ5+Lgw4TEQ3fVHEQ0M6GWlvYIcqsTE2KhIfZ02Qar3a8arvD9AL ZrqH3jLsGrC5/vYzrZ1HtXgoo4D4U8kU8Fpa2YnmyHbX+cnFtRwSoB9oqX6MMQS9bFTDj NcUxRQqahv3qe50jpmLNou5aPFClBbhoNuvPzAMsq3IDgiEfWWKLwaN6UdDEZ19TRyQ0X GkR46uzl7p9SvETfu6r4PpJVEsuokBROW2+j3xhllQ38C5/IUnbEuOcRVGRCqJt8GPA== 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=bylMSHhK; 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 4AD80606A332; Fri, 4 Dec 2026 10:48:30 +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=bylMSHhK Received: by smtp.kernel.org (Postfix) with ESMTPSA id 699581F000C2; Fri, 4 Dec 2026 10:48:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381310; bh=bedPS6EfFS7tALEYI6BjGhIiNcbDzeaFp07FfDwPOVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bylMSHhK+fP03JumCBy56NLIqYjtR0pK2L7RVv+bdj5sNOvtNW8FtozhbmUZgFAmI qDyuwq3ATbgESwj29/WB3RHBu0tNtU/L4DvN1zXfbS1hGze0HlZzc55Tg2abXbv23o ukjZL6MrOj6YFZum9GGCspByFXUih8SSq2iZ+NOk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Keith Busch Subject: [PATCH 7.3 648/742] nvmet: zero the entire Get Log Page transfer buffer Date: Fri, 4 Dec 2026 19:08:32 +0900 Message-ID: <20261204100652.304462811@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: stable@vger.kernel.org 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: Shao Mingyin commit ad606ae5635b68e324005aaa06421be752619dab upstream. Several fixed-size Get Log Page handlers copy only the log structure and leave the rest of the host buffer untouched. The transport buffers are not zeroed, so a host requesting more bytes than the structure receives stale kernel memory. Zero the entire transfer length before filling the buffer in the Supported Log Pages, Commands Supported and Effects, Supported Features, Endurance Group, Rotational Media Information and Reservation handlers. For the Error log, also clamp the ring walk to the requested length and propagate copy failures instead of completing with success. The Rotational Media Information handler now accepts a buffer larger than its fixed structure. Fixes: 11ad507784ed ("nvmet: add error log page cmd handler") Fixes: 83acb24e6de7 ("nvmet: implement supported log pages") Fixes: 0866bf0c3778 ("nvmet: add commands supported and effects log page") Fixes: e973c91727d4 ("nvmet: implement supported features log") Fixes: 266b652c65b4 ("nvmet: implement endurance groups") Fixes: 5fd075cdaf36 ("nvmet: implement rotational media information log") Fixes: 5a47c2080a73 ("nvmet: support reservation feature") Cc: stable@vger.kernel.org Signed-off-by: Shao Mingyin Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/target/admin-cmd.c | 51 +++++++++++++++++++++++++++++++--------- drivers/nvme/target/pr.c | 6 ++++ 2 files changed, 46 insertions(+), 11 deletions(-) --- a/drivers/nvme/target/admin-cmd.c +++ b/drivers/nvme/target/admin-cmd.c @@ -176,16 +176,35 @@ static void nvmet_execute_get_log_page_e { struct nvmet_ctrl *ctrl = req->sq->ctrl; unsigned long flags; - off_t offset = 0; + u32 offset = 0; + u32 len; u64 slot; u64 i; + u16 status = 0; + + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (status) { + nvmet_req_complete(req, status); + return; + } + + len = min_t(u32, req->transfer_len, + NVMET_ERROR_LOG_SLOTS * sizeof(struct nvme_error_slot)); spin_lock_irqsave(&ctrl->error_lock, flags); + + /* + * The NVMe base specification requires the most recent error to be + * the first log entry, so walk the ring backwards from the slot of + * the last error and stop at the end of the requested buffer. + */ slot = ctrl->err_counter % NVMET_ERROR_LOG_SLOTS; - for (i = 0; i < NVMET_ERROR_LOG_SLOTS; i++) { - if (nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot], - sizeof(struct nvme_error_slot))) + for (i = 0; i < NVMET_ERROR_LOG_SLOTS && + offset + sizeof(struct nvme_error_slot) <= len; i++) { + status = nvmet_copy_to_sgl(req, offset, &ctrl->slots[slot], + sizeof(struct nvme_error_slot)); + if (status) break; if (slot == 0) @@ -195,7 +214,7 @@ static void nvmet_execute_get_log_page_e offset += sizeof(struct nvme_error_slot); } spin_unlock_irqrestore(&ctrl->error_lock, flags); - nvmet_req_complete(req, 0); + nvmet_req_complete(req, status); } static void nvmet_execute_get_supported_log_pages(struct nvmet_req *req) @@ -221,7 +240,9 @@ static void nvmet_execute_get_supported_ logs->lids[NVME_LOG_RMI] = cpu_to_le32(NVME_LIDS_LSUPP); logs->lids[NVME_LOG_RESERVATION] = cpu_to_le32(NVME_LIDS_LSUPP); - status = nvmet_copy_to_sgl(req, 0, logs, sizeof(*logs)); + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (!status) + status = nvmet_copy_to_sgl(req, 0, logs, sizeof(*logs)); kfree(logs); out: nvmet_req_complete(req, status); @@ -303,7 +324,7 @@ static void nvmet_execute_get_log_page_r goto out; } - if (req->transfer_len != sizeof(*log)) { + if (req->transfer_len < sizeof(*log)) { status = NVME_SC_SGL_INVALID_DATA | NVME_STATUS_DNR; goto out; } @@ -321,7 +342,9 @@ static void nvmet_execute_get_log_page_r else log->numa = cpu_to_le16(1); - status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (!status) + status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); kfree(log); out: nvmet_req_complete(req, status); @@ -436,7 +459,9 @@ static void nvmet_execute_get_log_cmd_ef goto free; } - status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (!status) + status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); free: kfree(log); out: @@ -527,7 +552,9 @@ static void nvmet_execute_get_log_page_e put_unaligned_le64(host_writes, &log->hwc[0]); put_unaligned_le64(data_units_written, &log->duw[0]); copy: - status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (!status) + status = nvmet_copy_to_sgl(req, 0, log, sizeof(*log)); kfree(log); out: nvmet_req_complete(req, status); @@ -610,7 +637,9 @@ static void nvmet_execute_get_log_page_f features->fis[NVME_FEAT_RESV_MASK] = cpu_to_le32(NVME_FIS_FSUPP | NVME_FIS_NSCPE); - status = nvmet_copy_to_sgl(req, 0, features, sizeof(*features)); + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (!status) + status = nvmet_copy_to_sgl(req, 0, features, sizeof(*features)); kfree(features); out: nvmet_req_complete(req, status); --- a/drivers/nvme/target/pr.c +++ b/drivers/nvme/target/pr.c @@ -99,6 +99,12 @@ void nvmet_execute_get_log_page_resv(str u64 cur_count; u64 next_count; + status = nvmet_zero_sgl(req, 0, req->transfer_len); + if (status) { + nvmet_req_complete(req, status); + return; + } + mutex_lock(&log_mgr->lock); if (!kfifo_get(&log_mgr->log_queue, &log)) goto out;