fs/ntfs3: fix -Wmaybe-uninitialized warning in ntfs_ioctl_fitrim
PATCH 1/1 fs/ntfs3: fix -Wmaybe-uninitialized warning in ntfs_ioctl_fitrim
From: huhai <[email protected]>
With CONFIG_KASAN and CONFIG_WERROR enabled, GCC 13.2 reports:
CC fs/ntfs3/file.o
In file included from ./include/asm-generic/rwonce.h:26,
from ./arch/arm64/include/asm/rwonce.h:81,
from ./include/linux/compiler.h:369,
from ./include/linux/array_size.h:5,
from ./include/linux/kernel.h:16,
from ./include/linux/backing-dev.h:12,
from fs/ntfs3/file.c:10:In function ‘instrument_copy_from_user_before’,
inlined from ‘_inline_copy_from_user’ at ./include/linux/uaccess.h:184:2,
inlined from ‘copy_from_user’ at ./include/linux/uaccess.h:222:9,
inlined from ‘ntfs_ioctl_fitrim’ at fs/ntfs3/file.c:77:6,
inlined from ‘ntfs_ioctl’ at fs/ntfs3/file.c:242:10:./include/linux/kasan-checks.h:38:27: error: ‘range’ may be used uninitialized [-Werror=maybe-uninitialized]
38 | #define kasan_check_write __kasan_check_write./include/linux/instrumented.h:146:9: note: in expansion of macro ‘kasan_check_write’
146 | kasan_check_write(to, n);
| ^~~~~~~~~~~~~~~~~
./include/linux/kasan-checks.h: In function ‘ntfs_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/ntfs3/file.c:65:29: note: ‘range’ declared here
65 | struct fstrim_range range;
| ^~~~~
copy_from_user() initializes the entire structure on success, but GCC fails to recognize this after the KASAN checks are inlined. Zero-initialize range to avoid the false positive.
--- fs/ntfs3/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs3/file.c +1 -1
@@ -62,7 +62,7 @@ static bool ntfs_should_use_dio(struct kiocb *iocb, struct iov_iter *iter)static int ntfs_ioctl_fitrim (struct ntfs_sb_info *sbi,unsigned long arg) {struct fstrim_range __user *user_range; -struct fstrim_range range; +struct fstrim_range range = {};struct block_device *dev;int err;
Signature · 1 line
2.40.1
Konstantin Komarov
maintainerQuoted 55 lines · huhai
From: huhai <[email protected]>
With
CONFIG_KASANandCONFIG_WERRORenabled, GCC 13.2 reports:CC
fs/ntfs3/file.o
In file included from./include/asm-generic/rwonce.h:26,from ./arch/arm64/include/asm/rwonce.h:81, from ./include/linux/compiler.h:369, from ./include/linux/array_size.h:5, from ./include/linux/kernel.h:16, from ./include/linux/backing-dev.h:12, from fs/ntfs3/file.c:10:In function ‘instrument_copy_from_user_before’,
inlined from ‘_inline_copy_from_user’ at./include/linux/uaccess.h:184:2,
inlined from ‘copy_from_user’ at./include/linux/uaccess.h:222:9,
inlined from ‘ntfs_ioctl_fitrim’ atfs/ntfs3/file.c:77:6,
inlined from ‘ntfs_ioctl’ atfs/ntfs3/file.c:242:10:./include/linux/kasan-checks.h:38:27: error: ‘range’ may be used uninitialized [-Werror=maybe-uninitialized]
38 | #definekasan_check_write__kasan_check_write./include/linux/instrumented.h:146:9: note: in expansion of macro ‘kasan_check_write’146 | kasan_check_write(to, n); | ^~~~~~~~~~~~~~~~~ ./include/linux/kasan-checks.h: In function ‘ntfs_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/ntfs3/file.c:65:29: note: ‘range’ declared here 65 | struct fstrim_range range; | ^~~~~
copy_from_user()initializes the entire structure on success, but GCC fails to recognize this after the KASAN checks are inlined. Zero-initialize range to avoid the false positive.Assisted-by Codex:gpt-5.6-solReported-by k2ci <[email protected]>Signed-off-by huhai <[email protected]>--- fs/ntfs3/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ntfs3/file.c +1
-2@@ -62,7 +62,7 @@ static bool ntfs_should_use_dio(struct kiocb *iocb, struct iov_iter *iter)static int ntfs_ioctl_fitrim (struct ntfs_sb_info *sbi,unsigned long arg) {struct fstrim_range __user *user_range; -struct fstrim_range range; +struct fstrim_range range = {};struct block_device *dev;int err; --
Quoted 1 line
2.40.1
Hello,
The patch is applied, thank you.
Regards,
Konstantin