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 AF803249F9; Tue, 11 Mar 2025 15:09:44 +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=1741705784; cv=none; b=Ny1LzPI4ZdjOZlHUGMPzBtennQXj9I2soji3baEclW8AYUD6JTExdKYQUAK5Vlr5pJEV2OGK7gZGbAZZiK6RkalOBxl/OgnxVlOPTbNwX34AZ0K4VSxRk2WDJ64kTdw4UaZXg/fRyfezil0FEST+OH9OFy19UAoX3XhwA2o1lgc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741705784; c=relaxed/simple; bh=bF8nYf4rSSXkNyIkMWeUh1+E2xv8JThX7KWrAtahLnM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mwzgTfcB0jkduHkebvzLT1v/yUsdcff/VnbBBf3N41nRhRt1Ex9NimksEJTmdA5v4Pi+3oNupvbgP60TmOxToFoAYkk3WRuZdN0j/6LJXqQnyxG8UvKoQ8GxGv+akrH8MwApEDHZ/M2v0f/NEuoyxi233rUywxMnH8oFaj/KUgE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=vctnyQn2; 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="vctnyQn2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 096B8C4CEE9; Tue, 11 Mar 2025 15:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1741705784; bh=bF8nYf4rSSXkNyIkMWeUh1+E2xv8JThX7KWrAtahLnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vctnyQn22IgIXxofHjLl58o5CULWcdaDhuAOahL1PThPz85Zlxv+PkNbc4fPvlVgT DPWkEHLg8Qm5JS7mub3U4Yq9EiBXw+nWlKLtzrhK7oAVCIC9pP5wkFlB+uRK72rgRW XeoecQO+4OFwLocA5rBbkBgaP5rF3Q6ZUa5WVsdA= 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.4 154/328] nilfs2: fix possible int overflows in nilfs_fiemap() Date: Tue, 11 Mar 2025 15:58:44 +0100 Message-ID: <20250311145721.027964397@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250311145714.865727435@linuxfoundation.org> References: <20250311145714.865727435@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.4-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 @@ -1271,7 +1271,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( @@ -1284,14 +1284,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; }