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 AD2961DE2C5; Wed, 19 Feb 2025 09:25:55 +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=1739957155; cv=none; b=UIo1pyhRh1LScRwWbdYdCSdzuyuFYqPNeMmdcuXGAvjmP6ne1oOYszc/wDKzlDmaWq/p9fARSONEjtB6GjWay7s//AHxOLwzZc6wkTrEDRUMAfWV47w71W8+S3zhwaUWg/iwV7FAn1RHfvvBSjHiblNGxfoiIIoRmgTDaUHO/KI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739957155; c=relaxed/simple; bh=4YtZqGwIiwwqMt0Jld+tgVIjfQVog/6m3sWJaMYn+WA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KPbxUreLVVJzXEExD+UCuyGLus5Mv768FvafmhItK78URd/h1Vcc4EqdRxN2XP+IxOL/ncBVKJM1HIrB3mpm/GoE0oU9riHm7Pu5dVuvhuJ2Nv/S1nS6qPJWXMidbXTqodylE6BM9ORMLQNbjCdHD45FvqrRE1qPXLdNPYuxIto= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bs/iHsRv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bs/iHsRv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C065AC4CED1; Wed, 19 Feb 2025 09:25:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1739957155; bh=4YtZqGwIiwwqMt0Jld+tgVIjfQVog/6m3sWJaMYn+WA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bs/iHsRvi7uSNuVQdWVaYl/Q2ulmpmAhGXmG7Ju0gO+psOwtVE6qEZRRijzUqg+7W tY8aOT83101YJukZJJwahYGQz17XnVgtqNqu9/h88MPV5WFqE/D6ZHuNa15lmA9IFp GjRQGeAJtxKhpKWqzaEb+36BenZbzAJl3xHH9mRM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Nikita Zhandarovich , Ryusuke Konishi , Andrew Morton Subject: [PATCH 6.1 428/578] nilfs2: fix possible int overflows in nilfs_fiemap() Date: Wed, 19 Feb 2025 09:27:12 +0100 Message-ID: <20250219082709.853425767@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250219082652.891560343@linuxfoundation.org> References: <20250219082652.891560343@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Nikita Zhandarovich commit 6438ef381c183444f7f9d1de18f22661cba1e946 upstream. Since nilfs_bmap_lookup_contig() in nilfs_fiemap() calculates its result by being prepared to go through potentially maxblocks == INT_MAX blocks, the value in n may experience an overflow caused by left shift of blkbits. While it is extremely unlikely to occur, play it safe and cast right hand expression to wider type to mitigate the issue. Found by Linux Verification Center (linuxtesting.org) with static analysis tool SVACE. Link: https://lkml.kernel.org/r/20250124222133.5323-1-konishi.ryusuke@gmail.com Fixes: 622daaff0a89 ("nilfs2: fiemap support") Signed-off-by: Nikita Zhandarovich Signed-off-by: Ryusuke Konishi Cc: Signed-off-by: Andrew Morton Signed-off-by: Greg Kroah-Hartman --- fs/nilfs2/inode.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/fs/nilfs2/inode.c +++ b/fs/nilfs2/inode.c @@ -1267,7 +1267,7 @@ int nilfs_fiemap(struct inode *inode, st if (size) { if (phys && blkphy << blkbits == phys + size) { /* The current extent goes on */ - size += n << blkbits; + size += (u64)n << blkbits; } else { /* Terminate the current extent */ ret = fiemap_fill_next_extent( @@ -1280,14 +1280,14 @@ int nilfs_fiemap(struct inode *inode, st flags = FIEMAP_EXTENT_MERGED; logical = blkoff << blkbits; phys = blkphy << blkbits; - size = n << blkbits; + size = (u64)n << blkbits; } } else { /* Start a new extent */ flags = FIEMAP_EXTENT_MERGED; logical = blkoff << blkbits; phys = blkphy << blkbits; - size = n << blkbits; + size = (u64)n << blkbits; } blkoff += n; }