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=1796382715; b=PY5SGt8PQoqBMz698ODmFXJ1eb2Mi4UKIQUnpjS9c512sijFHrTla2YPnpsH6ASzosoY Xi29dIUEoji/LHMkjfi+OrY15Nt+glq/mrqY/EyoUsbUiXM9U/gei82AbBm8eIaGJGiiM vNWq6RZsHU5C+HtfkRSAuL7bab30DO922LOfMcImob7Gw+hwdzB4fF6Bf4n0r1fSPG1/i uNFZ2jgsKhHUuKPJkHBpez5ck3bHX4LK9VaF9ygKPggPA7epAA1Fg5GYCXOS+HTRgvml7 mrq0DRSf6tbM51GVtlCBcHrBLqqxhexKYJzjrv9Sfx3D1Fx9pMYfl5KbjBTRsDf/NOw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382715; 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=xu+brRAlOQ/E0piJIH2TAFdjB6TK5wS7GPV4/4gkG9E=; b=WMy2XnMx6jMGaw5IyvHIvEfsbkRs6j0i+PHQFL+8WtYy1XGsCs5PEJ9lQbs5718sXO0J HibQ3Yof+ghd4WFN3b84JAp5eXSe0Z+kxHBg5FY9Bn5bfQCGst4p1C6V5dgvxou194ciY PnMGPs33p5/CIwcZswkv7Zdy8OtyJO653UZ8Wb7IqeHwvRaTJxowcgnT/VOSx/zuPvfbP VzGWwyeWPIoC8mRdmGNFSz5fwc8r0YuZLMJSsgJ+xovPmh/wCemVOAtHcp0ej7WdzCnbc 4QIUpTsuM1iL5NdOctKUMTgVBmOzR8rnGCQIcBfnUdJnYXj8Z6dXS7I9WX50QFfDc1A== 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=zP2UUunb; 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 41922606A322; Fri, 4 Dec 2026 11:11:55 +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=zP2UUunb Received: by smtp.kernel.org (Postfix) with ESMTPSA id B13701F000C2; Fri, 4 Dec 2026 11:11:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382715; bh=xu+brRAlOQ/E0piJIH2TAFdjB6TK5wS7GPV4/4gkG9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zP2UUunbW1Vxi2PABhmz2+kNopaW3cWxpbteAxr9Ub124PDGt2EuJlkPtCX6PXL0G HTzMFbknX31AnI4who2JZxqSr5HYw8kL6FrroHnC1r9yHaMRvStYLaYNWwi0Ou4rzo F8bgEQvmbLmRZaBg6BqmDQiW6JRPpKABfYD4YuOg= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shao Mingyin , Keith Busch Subject: [PATCH 6.18 572/703] nvmet: zero the entire Get Log Page transfer buffer Date: Fri, 4 Dec 2026 19:07:51 +0900 Message-ID: <20261204100642.981388371@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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 6.18-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); @@ -611,7 +638,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;