]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
nilfs2: fix possible int overflows in nilfs_fiemap()
authorNikita Zhandarovich <n.zhandarovich@fintech.ru>
Fri, 24 Jan 2025 22:20:53 +0000 (07:20 +0900)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Mar 2025 11:47:12 +0000 (12:47 +0100)
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 <n.zhandarovich@fintech.ru>
Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/nilfs2/inode.c

index fe3f005d5d5504ec30c5ffd717dda8a8b5c22877..7203c8f1211138f04f59fe88678dd1308167233d 100644 (file)
@@ -1263,7 +1263,7 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                        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(
@@ -1276,14 +1276,14 @@ int nilfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
                                        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;
                }