* [PATCH] [v2] btrfs: zoned: bail out in btrfs_alloc_chunk for bad input
@ 2021-03-23 14:31 Arnd Bergmann
2021-03-29 18:44 ` David Sterba
0 siblings, 1 reply; 2+ messages in thread
From: Arnd Bergmann @ 2021-03-23 14:31 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba, Anand Jain, Naohiro Aota
Cc: Arnd Bergmann, David Sterba, Nikolay Borisov, Johannes Thumshirn,
linux-btrfs, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
gcc complains that the ctl->max_chunk_size member might be used
uninitialized when none of the three conditions for initializing it in
init_alloc_chunk_ctl_policy_zoned() are true:
In function ‘init_alloc_chunk_ctl_policy_zoned’,
inlined from ‘init_alloc_chunk_ctl’ at fs/btrfs/volumes.c:5023:3,
inlined from ‘btrfs_alloc_chunk’ at fs/btrfs/volumes.c:5340:2:
include/linux/compiler-gcc.h:48:45: error: ‘ctl.max_chunk_size’ may be used uninitialized [-Werror=maybe-uninitialized]
4998 | ctl->max_chunk_size = min(limit, ctl->max_chunk_size);
| ^~~
fs/btrfs/volumes.c: In function ‘btrfs_alloc_chunk’:
fs/btrfs/volumes.c:5316:32: note: ‘ctl’ declared here
5316 | struct alloc_chunk_ctl ctl;
| ^~~
If we ever get into this condition, something is seriously
wrong, so the same logic as in init_alloc_chunk_ctl_policy_regular()
and a few other places should be applied. This avoids both further
data corruption, and the compile-time warning.
Fixes: 1cd6121f2a38 ("btrfs: zoned: implement zoned chunk allocator")
Link: https://lore.kernel.org/lkml/20210323132343.GF7604@twin.jikos.cz/
Suggested-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
Note that the -Wmaybe-unintialized warning is globally disabled
by default. For some reason I got this warning anyway when building
this specific file with gcc-11.
---
fs/btrfs/volumes.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index bc3b33efddc5..d2994305ed77 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4989,6 +4989,8 @@ static void init_alloc_chunk_ctl_policy_zoned(
ctl->max_chunk_size = 2 * ctl->max_stripe_size;
ctl->devs_max = min_t(int, ctl->devs_max,
BTRFS_MAX_DEVS_SYS_CHUNK);
+ } else {
+ BUG();
}
/* We don't want a chunk larger than 10% of writable space */
--
2.29.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] [v2] btrfs: zoned: bail out in btrfs_alloc_chunk for bad input
2021-03-23 14:31 [PATCH] [v2] btrfs: zoned: bail out in btrfs_alloc_chunk for bad input Arnd Bergmann
@ 2021-03-29 18:44 ` David Sterba
0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2021-03-29 18:44 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Chris Mason, Josef Bacik, David Sterba, Anand Jain, Naohiro Aota,
Arnd Bergmann, David Sterba, Nikolay Borisov, Johannes Thumshirn,
linux-btrfs, linux-kernel
On Tue, Mar 23, 2021 at 03:31:19PM +0100, Arnd Bergmann wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> gcc complains that the ctl->max_chunk_size member might be used
> uninitialized when none of the three conditions for initializing it in
> init_alloc_chunk_ctl_policy_zoned() are true:
>
> In function ‘init_alloc_chunk_ctl_policy_zoned’,
> inlined from ‘init_alloc_chunk_ctl’ at fs/btrfs/volumes.c:5023:3,
> inlined from ‘btrfs_alloc_chunk’ at fs/btrfs/volumes.c:5340:2:
> include/linux/compiler-gcc.h:48:45: error: ‘ctl.max_chunk_size’ may be used uninitialized [-Werror=maybe-uninitialized]
> 4998 | ctl->max_chunk_size = min(limit, ctl->max_chunk_size);
> | ^~~
> fs/btrfs/volumes.c: In function ‘btrfs_alloc_chunk’:
> fs/btrfs/volumes.c:5316:32: note: ‘ctl’ declared here
> 5316 | struct alloc_chunk_ctl ctl;
> | ^~~
>
> If we ever get into this condition, something is seriously
> wrong, so the same logic as in init_alloc_chunk_ctl_policy_regular()
> and a few other places should be applied. This avoids both further
> data corruption, and the compile-time warning.
>
> Fixes: 1cd6121f2a38 ("btrfs: zoned: implement zoned chunk allocator")
> Link: https://lore.kernel.org/lkml/20210323132343.GF7604@twin.jikos.cz/
> Suggested-by: David Sterba <dsterba@suse.cz>
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Added to misc-next, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-29 18:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-23 14:31 [PATCH] [v2] btrfs: zoned: bail out in btrfs_alloc_chunk for bad input Arnd Bergmann
2021-03-29 18:44 ` David Sterba
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.