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 D820B23D290 for ; Wed, 26 Nov 2025 20:52:10 +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=1764190330; cv=none; b=qMAGWf5/Xbi7Kjzt1OHw5z0hvb7C9tXRqSD//RJ73up3yBcLr2XAeUuNHke6M+77zfcPS/my4fXENxlW5iE31+Zqb7La53zJzR+Xg1I4z40RUwXFIt2/Q/gKb6KCqxuRR67SFJfWDRRcb4oQbP4RN43j2smZYEjKyQ8SfsTsi00= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764190330; c=relaxed/simple; bh=ummODbuTVwODNNLpHfFOIPFZYiF413uJ/4Wkgzo7XZE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KBINFzQxWhcPNG8LioVkD+vmJPO2OedFf1MWOMGnjnyjXNgbp++C+IohVyOEC2SGrONu6Pp1hJzh6CUkmDxVxCNeklaZYlTtL7+AEgi58aicwi1dNKxfNKSk0j55SCt6rh4CPBVSk7+GuHHBTesAMOvan8WhYea9GcAs+1iDBU8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=M5cZ/O8j; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="M5cZ/O8j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31FFDC4CEF7; Wed, 26 Nov 2025 20:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764190330; bh=ummODbuTVwODNNLpHfFOIPFZYiF413uJ/4Wkgzo7XZE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=M5cZ/O8jMVlp6qey1w+QzRXddTfwJjNAM4kFLC38sm6dOEVCLkfipUPYA8eTJBOkI V4vbGqj4VEACvIWBKEW5CqXECCt70mR7A6wA5R1NOvGEckR3SA6u4AR7yO1XNiz1Q0 kAPHk9br5oxJ85qhP7kjDgaDQJQvUteoFnsmoL04Lpncb3dH9RpCazEcEkVKEVunsI TElRXPxaSTy0rpqFibnmcrKmpuFc9Q53UMW9dDQXR0ZguOUZqf/Ui4R0xt6nvcb6kI DMCyfPpOfkY72gmxeDif6LfriM73zWP1HvLofIYXVaNkf64KDYnXeCEmOQ/R8k/B0I 8W4z4mr+2LD5A== Date: Wed, 26 Nov 2025 13:52:08 -0700 From: Keith Busch To: Eugene Korenevsky Cc: Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] nvme: nvme_identify_ns_descs: prevent oob Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Wed, Nov 26, 2025 at 11:27:21PM +0300, Eugene Korenevsky wrote: > Broken or malicious controller can send invalid ns id. > Out-of-band memory access may occur if remaining buffer size > is less than .nidl (ns id length) field of `struct nvme_ns_id_desc` > > Fix this issue by making nvme_process_id_decs() function aware of > remaining buffer size. > > Also simplify nvme_process_id_decs(): replace copy-pasted `case` > branches with table lookup. > > Signed-off-by: Eugene Korenevsky > --- > drivers/nvme/host/core.c | 80 ++++++++++++++++++++-------------------- > 1 file changed, 39 insertions(+), 41 deletions(-) Is this simpler check not sufficient? --- diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index fa534f1d6b27a..6cc43cbb04dd9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1566,7 +1566,7 @@ static int nvme_identify_ns_descs(struct nvme_ctrl *ctrl, for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) { struct nvme_ns_id_desc *cur = data + pos; - if (cur->nidl == 0) + if (cur->nidl == 0 || cur->nidl + pos > NVME_IDENTIFY_DATA_SIZE) break; len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); --