From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) (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 D0CF319C556 for ; Mon, 1 Dec 2025 06:21:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.95.11.211 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764570079; cv=none; b=R9eEIgEnPp6eYETOSUyYFabv/7/uR7kva5u3NWgRNf06U1p0nFF69Ew3LP7t0ZawiiTqdWVoaA4517kqRhZVkzfLabFqfWabhW34RyQSKPw3oLbO3k5dXPGGTkAZUaq+ttgfmVIptsc6gcTxVL/Hl2BXFk0CUZAXdiMsiNaWn4s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764570079; c=relaxed/simple; bh=RYc0FBc5+jenS5qLoW4xgJZw7CxAyIwTHX/nHb8+Tms=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MgRFoT881x7UTNv3/Y+VQEOoJbADK0OLV7a8FDhNVwFnQmAphBfZ7gmQEoOpXjON1sET4ua6a3ccx3K5W9HWgpxXyQ/cB6xe59IY77Nzx6k+bJVPOGnozbapIShbzibL8WYarLenbTD/10Y6zbFrY8UhAo+rRzNIPsMg9xHPkZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de; spf=pass smtp.mailfrom=lst.de; arc=none smtp.client-ip=213.95.11.211 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=lst.de Received: by verein.lst.de (Postfix, from userid 2407) id B43566732A; Mon, 1 Dec 2025 07:21:06 +0100 (CET) Date: Mon, 1 Dec 2025 07:21:06 +0100 From: Christoph Hellwig To: Eugene Korenevsky Cc: Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] nvme: nvme_identify_ns_descs: prevent oob Message-ID: <20251201062106.GA19164@lst.de> 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: User-Agent: Mutt/1.5.17 (2007-11-01) On Sat, Nov 29, 2025 at 11:03:05PM +0300, Eugene Korenevsky wrote: > - int status, pos, len; > + int status, len, remain; Pre-existing issue, but all but len here should be unsigned. > + remain = NVME_IDENTIFY_DATA_SIZE; > + cur = data; > + while (remain >= sizeof(*cur)) { > if (cur->nidl == 0) > break; > + if (sizeof(*cur) + cur->nidl > remain) > + break; > > len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen); > if (len < 0) > break; > > len += sizeof(*cur); > + remain -= len; > + cur += len; > } I don't think this works, cur is a nvme_ns_id_desc pointer, so it will be increased by len multiplied by the size of it. I think this would work muc heasier if you'd do away with remain, use and just use cur locally, and instead maintain an offet; Something like: offset = 0; do { cur = data + offset; ... offset += len; } while (offset < NVME_IDENTIFY_DATA_SIZE - sizeof(*cur));