lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAKFNMonqeRS_S=k9T9cR7dq3cd9XeBjGJSfuDAp9u15FT+VVGg@mail.gmail.com>
Date: Thu, 16 Jan 2025 04:06:43 +0900
From: Ryusuke Konishi <konishi.ryusuke@...il.com>
To: Nikita Zhandarovich <n.zhandarovich@...tech.ru>
Cc: linux-nilfs@...r.kernel.org, linux-kernel@...r.kernel.org, 
	lvc-project@...uxtesting.org
Subject: Re: [PATCH] nilfs2: fix possible int overflows in nilfs_fiemap()

On Thu, Jan 16, 2025 at 2:08 AM Nikita Zhandarovich wrote:
>
> 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.
>
> Fixes: 622daaff0a89 ("nilfs2: fiemap support")
> Cc: stable@...r.kernel.org
> Signed-off-by: Nikita Zhandarovich <n.zhandarovich@...tech.ru>
> ---
>  fs/nilfs2/inode.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/fs/nilfs2/inode.c b/fs/nilfs2/inode.c
> index 23f3a75edd50..81abb58dcbd8 100644
> --- a/fs/nilfs2/inode.c
> +++ b/fs/nilfs2/inode.c
> @@ -1188,7 +1188,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(
> @@ -1201,14 +1201,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;
>                 }

Thank you Nikita.

I'll take this patch and send it upstream.

Since nilfs2 extents (contiguous blocks) cannot cross segment
boundaries, these overflows do not occur in normal format.  However,
in an environment where the segments are tuned to be larger, these
overflows can theoretically occur, so as you pointed out, I believe
this fix is necessary.

Thanks,
Ryusuke Konishi

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ