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 449BB22FF4E; Mon, 10 Mar 2025 18:00:06 +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=1741629606; cv=none; b=JWV2lQz/2uFQkH1rHmkdzckUTIKAi/bvY/keEYt4XN47stXxSwlumbYx8mGeIpfGyY2Q9vsAgPI40AV78F8V6kg2ZWnDMzvlP2Qh7rfE2Vh5pi5Wj3yvQYGA6Y41L3ruKtJ2Nke9e3yik71F63Y8gxbb8P1JCyYcc1EOEuP9fCQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741629606; c=relaxed/simple; bh=zByKgvUbwtqPF/H0x6OvUWxr4jp1NN4ifq7V9hO0L9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ONI4ehVH3jic98W3j8hiRThU7mKFxULUElnWzH+CT4rGMC31F1L1E2w4kA/RLffmcf2upa+C/bQx9ocFmxpyJrVV1VWqlojNmnn8P4Am5PADIIf6U73TW5SeI/vWpFithw6fRXGfco2Fk042VSTN1xjlqqZ8/aJufj8jq1YeTI4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UTio8lC8; 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="UTio8lC8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BEA00C4CEED; Mon, 10 Mar 2025 18:00:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741629606; bh=zByKgvUbwtqPF/H0x6OvUWxr4jp1NN4ifq7V9hO0L9M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UTio8lC8VYideBFvH4Km1300GHtr8aLmXX9EP3kQwoghHdhU//+w5vGkIxnaqnwYn CvYzsxfyo9oW7hMOp+YzXTvh+VDIvlH3u/oSsOEYBVOMjtKVUNEAs0MvOYb/+t4h5R FCfPt3SSraRUSf0jaKGax5ie5Do5xsVcqEP1XCLM= 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 5.15 321/620] nilfs2: fix possible int overflows in nilfs_fiemap() Date: Mon, 10 Mar 2025 18:02:47 +0100 Message-ID: <20250310170558.281007382@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250310170545.553361750@linuxfoundation.org> References: <20250310170545.553361750@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 5.15-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 @@ -1265,7 +1265,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( @@ -1278,14 +1278,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; }