Message ID | 0e16cb17a51ba2542986de951a61bd1362360eb9.1695757597.git.josef@toxicpanda.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: fix some maybe uninitialized warnings in ioctl.c | expand |
On Tue, Sep 26, 2023 at 03:47:27PM -0400, Josef Bacik wrote: > Jens reported the following warnings from -Wmaybe-uninitialized recent > linus. > > In file included from ./include/asm-generic/rwonce.h:26, > from ./arch/arm64/include/asm/rwonce.h:71, > from ./include/linux/compiler.h:246, > from ./include/linux/export.h:5, > from ./include/linux/linkage.h:7, > from ./include/linux/kernel.h:17, > from fs/btrfs/ioctl.c:6: > In function ‘instrument_copy_from_user_before’, > inlined from ‘_copy_from_user’ at ./include/linux/uaccess.h:148:3, > inlined from ‘copy_from_user’ at ./include/linux/uaccess.h:183:7, > inlined from ‘btrfs_ioctl_space_info’ at fs/btrfs/ioctl.c:2999:6, > inlined from ‘btrfs_ioctl’ at fs/btrfs/ioctl.c:4616:10: > ./include/linux/kasan-checks.h:38:27: warning: ‘space_args’ may be used > uninitialized [-Wmaybe-uninitialized] > 38 | #define kasan_check_write __kasan_check_write > ./include/linux/instrumented.h:129:9: note: in expansion of macro > ‘kasan_check_write’ > 129 | kasan_check_write(to, n); > | ^~~~~~~~~~~~~~~~~ > ./include/linux/kasan-checks.h: In function ‘btrfs_ioctl’: > ./include/linux/kasan-checks.h:20:6: note: by argument 1 of type ‘const > volatile void *’ to ‘__kasan_check_write’ declared here > 20 | bool __kasan_check_write(const volatile void *p, unsigned int > size); > | ^~~~~~~~~~~~~~~~~~~ > fs/btrfs/ioctl.c:2981:39: note: ‘space_args’ declared here > 2981 | struct btrfs_ioctl_space_args space_args; > | ^~~~~~~~~~ > In function ‘instrument_copy_from_user_before’, > inlined from ‘_copy_from_user’ at ./include/linux/uaccess.h:148:3, > inlined from ‘copy_from_user’ at ./include/linux/uaccess.h:183:7, > inlined from ‘_btrfs_ioctl_send’ at fs/btrfs/ioctl.c:4343:9, > inlined from ‘btrfs_ioctl’ at fs/btrfs/ioctl.c:4658:10: > ./include/linux/kasan-checks.h:38:27: warning: ‘args32’ may be used > uninitialized [-Wmaybe-uninitialized] > 38 | #define kasan_check_write __kasan_check_write > ./include/linux/instrumented.h:129:9: note: in expansion of macro > ‘kasan_check_write’ > 129 | kasan_check_write(to, n); > | ^~~~~~~~~~~~~~~~~ > ./include/linux/kasan-checks.h: In function ‘btrfs_ioctl’: > ./include/linux/kasan-checks.h:20:6: note: by argument 1 of type ‘const > volatile void *’ to ‘__kasan_check_write’ declared here > 20 | bool __kasan_check_write(const volatile void *p, unsigned int > size); > | ^~~~~~~~~~~~~~~~~~~ > fs/btrfs/ioctl.c:4341:49: note: ‘args32’ declared here > 4341 | struct btrfs_ioctl_send_args_32 args32; > | ^~~~~~ > > This was due to his config options and having KASAN turned on, > which adds some extra checks around copy_from_user(), which then > triggered the -Wmaybe-uninitialized checker for these cases. > > Fix the warnings by initializing the different structs we're copying > into. > > Reported-by: Jens Axboe <axboe@kernel.dk> > Signed-off-by: Josef Bacik <josef@toxicpanda.com> Added to misc-next, thanks.
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 75ab766fe156..8e7d03bc1b56 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2978,7 +2978,7 @@ static void get_block_group_info(struct list_head *groups_list, static long btrfs_ioctl_space_info(struct btrfs_fs_info *fs_info, void __user *arg) { - struct btrfs_ioctl_space_args space_args; + struct btrfs_ioctl_space_args space_args = { 0 }; struct btrfs_ioctl_space_info space; struct btrfs_ioctl_space_info *dest; struct btrfs_ioctl_space_info *dest_orig; @@ -4338,7 +4338,7 @@ static int _btrfs_ioctl_send(struct inode *inode, void __user *argp, bool compat if (compat) { #if defined(CONFIG_64BIT) && defined(CONFIG_COMPAT) - struct btrfs_ioctl_send_args_32 args32; + struct btrfs_ioctl_send_args_32 args32 = { 0 }; ret = copy_from_user(&args32, argp, sizeof(args32)); if (ret)
Jens reported the following warnings from -Wmaybe-uninitialized recent linus. In file included from ./include/asm-generic/rwonce.h:26, from ./arch/arm64/include/asm/rwonce.h:71, from ./include/linux/compiler.h:246, from ./include/linux/export.h:5, from ./include/linux/linkage.h:7, from ./include/linux/kernel.h:17, from fs/btrfs/ioctl.c:6: In function ‘instrument_copy_from_user_before’, inlined from ‘_copy_from_user’ at ./include/linux/uaccess.h:148:3, inlined from ‘copy_from_user’ at ./include/linux/uaccess.h:183:7, inlined from ‘btrfs_ioctl_space_info’ at fs/btrfs/ioctl.c:2999:6, inlined from ‘btrfs_ioctl’ at fs/btrfs/ioctl.c:4616:10: ./include/linux/kasan-checks.h:38:27: warning: ‘space_args’ may be used uninitialized [-Wmaybe-uninitialized] 38 | #define kasan_check_write __kasan_check_write ./include/linux/instrumented.h:129:9: note: in expansion of macro ‘kasan_check_write’ 129 | kasan_check_write(to, n); | ^~~~~~~~~~~~~~~~~ ./include/linux/kasan-checks.h: In function ‘btrfs_ioctl’: ./include/linux/kasan-checks.h:20:6: note: by argument 1 of type ‘const volatile void *’ to ‘__kasan_check_write’ declared here 20 | bool __kasan_check_write(const volatile void *p, unsigned int size); | ^~~~~~~~~~~~~~~~~~~ fs/btrfs/ioctl.c:2981:39: note: ‘space_args’ declared here 2981 | struct btrfs_ioctl_space_args space_args; | ^~~~~~~~~~ In function ‘instrument_copy_from_user_before’, inlined from ‘_copy_from_user’ at ./include/linux/uaccess.h:148:3, inlined from ‘copy_from_user’ at ./include/linux/uaccess.h:183:7, inlined from ‘_btrfs_ioctl_send’ at fs/btrfs/ioctl.c:4343:9, inlined from ‘btrfs_ioctl’ at fs/btrfs/ioctl.c:4658:10: ./include/linux/kasan-checks.h:38:27: warning: ‘args32’ may be used uninitialized [-Wmaybe-uninitialized] 38 | #define kasan_check_write __kasan_check_write ./include/linux/instrumented.h:129:9: note: in expansion of macro ‘kasan_check_write’ 129 | kasan_check_write(to, n); | ^~~~~~~~~~~~~~~~~ ./include/linux/kasan-checks.h: In function ‘btrfs_ioctl’: ./include/linux/kasan-checks.h:20:6: note: by argument 1 of type ‘const volatile void *’ to ‘__kasan_check_write’ declared here 20 | bool __kasan_check_write(const volatile void *p, unsigned int size); | ^~~~~~~~~~~~~~~~~~~ fs/btrfs/ioctl.c:4341:49: note: ‘args32’ declared here 4341 | struct btrfs_ioctl_send_args_32 args32; | ^~~~~~ This was due to his config options and having KASAN turned on, which adds some extra checks around copy_from_user(), which then triggered the -Wmaybe-uninitialized checker for these cases. Fix the warnings by initializing the different structs we're copying into. Reported-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Josef Bacik <josef@toxicpanda.com> --- fs/btrfs/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)