From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 E1270344DB4 for ; Wed, 20 May 2026 19:33:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779305613; cv=none; b=pekUL9ku3D4KAG1ioOdolbj/U7+jCgbQRomtkTQvdPdvUGHd7BMQNHDZG0YKqgR0ED+TGK1J3W/vTEoY93TgVdpABD03trOPoRuknU2MK/E4GUX+vp1MRei5eVciZQQrJtQljxmL9y8FVuiM5tRp06rbrataRabeyjs1tiboea8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779305613; c=relaxed/simple; bh=vyoanCeD9iyxG1+jQEMxLIBFl9BSX5KKL/J8nxcThPs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fd5OmyjLYozLMIA5AEY5sArdwReVemdxZFqZbYQ1u5Fgpn2TsOsm5zpHpuF67rRpoFAlpiRPt0yrTjzLP5W7KhRIsONW85RjE477k8MlTqQksQGkBJLDDu3r7EMja6N8npgbcDZl7fagnNhfN2KA9L90WVkzNM8kAce0q/5r5IQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RRcnM8CC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="RRcnM8CC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 017F51F000E9; Wed, 20 May 2026 19:33:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1779305612; bh=XuumR3ELpsuetsgZhIwTN5JimHj8jH4OyA95lBtrTLw=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=RRcnM8CC3aaLlqPZoXywt2/FILkZGvMmUUK2nPkREH/njOs+O20qui7EywHM7K6Ck 0Be8yLVrtQhiQ/cwOCHt+45brIA6nKj361FXOAFitEdr98XUjZilB0hMQq8z30ja+v 10bz6U3FcT315G/0pooJqzZpNhGeY3o1pYwUz8Jgxy+GY3PD3+UHIptuMfebBlxuSf /Ofj3Tou54z9TkwsMb7aTjgDLprlYLKUJGTCr2jR5duq9zzFYe/lALwA2DoCp3nVJa kwfdslPWnjtsut9ztFQdjwrUH19/6Kow8RjGdT07Q3wRWs0t+fSgY+Wq+rxJ2l942N lyVtH6yJ5NZyA== Date: Wed, 20 May 2026 13:33:30 -0600 From: Keith Busch To: Chao Shi Cc: Jens Axboe , linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, Christoph Hellwig , Sagi Grimberg , Daniel Wagner , Hannes Reinecke , Maurizio Lombardi , Sungwoo Kim , Dave Tian , Weidong Zhu Subject: Re: [PATCH v3] nvme: core: reject invalid LBA data size from Identify Namespace Message-ID: References: <20260515185853.2761456-1-coshi036@gmail.com> 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: <20260515185853.2761456-1-coshi036@gmail.com> On Fri, May 15, 2026 at 02:58:53PM -0400, Chao Shi wrote: > nvme_update_ns_info_block() trusts id->lbaf[lbaf].ds from the > controller and assigns it directly to ns->head->lba_shift without > bounds checking. nvme_lba_to_sect() then does: > > return lba << (head->lba_shift - SECTOR_SHIFT); > > When called with lba = le64_to_cpu(id->nsze) to compute the device > capacity, an attacker-controlled controller can choose ds < 9 or a > combination of (ds, nsze) that makes the left shift overflow > sector_t. The former is a C undefined behaviour that UBSAN reports > as a BUG; the latter silently yields a bogus capacity that the > block layer then trusts for bounds checking. > > Validate ds against SECTOR_SHIFT and use check_shl_overflow() to > compute capacity so that any (ds, nsze) combination that would > overflow sector_t is rejected. The namespace is skipped with > -ENODEV instead of crashing the kernel. This is reachable by a > malicious NVMe device, a buggy firmware, or an attacker-controlled > NVMe-oF target. Thanks, applied to nvme-7.2.