* [PATCH] ext4: mballoc: avoid garbage value from err
@ 2023-07-24 5:45 Su Hui
2023-07-24 17:19 ` Nick Desaulniers
0 siblings, 1 reply; 5+ messages in thread
From: Su Hui @ 2023-07-24 5:45 UTC (permalink / raw)
To: tytso, adilger.kernel, nathan, ndesaulniers, trix
Cc: linux-ext4, linux-kernel, llvm, kernel-janitors, Su Hui
clang warning: fs/ext4/mballoc.c, line 4178, column 6
Branch condition evaluates to a garbage value.
err is uninitialized and will be judged when it enters the
loop first time and the condition "!ext4_sb_block_valid()"
is true. Although this can't make problems now, it's better
to correct it.
Signed-off-by: Su Hui <suhui@nfschina.com>
---
fs/ext4/mballoc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 21b903fe546e..769000c970b0 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -4084,7 +4084,7 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
struct ext4_sb_info *sbi = EXT4_SB(sb);
ext4_group_t group;
ext4_grpblk_t blkoff;
- int i, err;
+ int i, err = 0;
int already;
unsigned int clen, clen_changed, thisgrp_len;
--
2.30.2
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ext4: mballoc: avoid garbage value from err
2023-07-24 5:45 [PATCH] ext4: mballoc: avoid garbage value from err Su Hui
@ 2023-07-24 17:19 ` Nick Desaulniers
2023-07-24 20:57 ` Theodore Ts'o
2023-07-25 4:33 ` Dan Carpenter
0 siblings, 2 replies; 5+ messages in thread
From: Nick Desaulniers @ 2023-07-24 17:19 UTC (permalink / raw)
To: Su Hui
Cc: tytso, adilger.kernel, nathan, trix, linux-ext4, linux-kernel,
llvm, kernel-janitors
On Sun, Jul 23, 2023 at 10:46 PM Su Hui <suhui@nfschina.com> wrote:
>
> clang warning: fs/ext4/mballoc.c, line 4178, column 6
> Branch condition evaluates to a garbage value.
Specifically this is clang's static analysis; not the compiler itself.
>
> err is uninitialized and will be judged when it enters the
> loop first time and the condition "!ext4_sb_block_valid()"
> is true. Although this can't make problems now, it's better
> to correct it.
>
> Signed-off-by: Su Hui <suhui@nfschina.com>
Hi Su,
Thanks for the patch! I see what the warning is getting at;
If `len <= 0` then `err` is never initialized, then is used at line
4178 (that is UB).
Would you mind sending a v2 with the commit message updated to reflect
the above points? I'd be happy to sign-off on that.
> ---
> fs/ext4/mballoc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
> index 21b903fe546e..769000c970b0 100644
> --- a/fs/ext4/mballoc.c
> +++ b/fs/ext4/mballoc.c
> @@ -4084,7 +4084,7 @@ void ext4_mb_mark_bb(struct super_block *sb, ext4_fsblk_t block,
> struct ext4_sb_info *sbi = EXT4_SB(sb);
> ext4_group_t group;
> ext4_grpblk_t blkoff;
> - int i, err;
> + int i, err = 0;
> int already;
> unsigned int clen, clen_changed, thisgrp_len;
>
> --
> 2.30.2
>
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ext4: mballoc: avoid garbage value from err
2023-07-24 17:19 ` Nick Desaulniers
@ 2023-07-24 20:57 ` Theodore Ts'o
2023-07-25 4:21 ` Su Hui
2023-07-25 4:33 ` Dan Carpenter
1 sibling, 1 reply; 5+ messages in thread
From: Theodore Ts'o @ 2023-07-24 20:57 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Su Hui, adilger.kernel, nathan, trix, linux-ext4, linux-kernel,
llvm, kernel-janitors
On Mon, Jul 24, 2023 at 10:19:02AM -0700, Nick Desaulniers wrote:
> >
> > err is uninitialized and will be judged when it enters the
> > loop first time and the condition "!ext4_sb_block_valid()"
> > is true. Although this can't make problems now, it's better
> > to correct it.
> >
> > Signed-off-by: Su Hui <suhui@nfschina.com>
>
> Hi Su,
> Thanks for the patch! I see what the warning is getting at;
>
> If `len <= 0` then `err` is never initialized, then is used at line
> 4178 (that is UB).
>
> Would you mind sending a v2 with the commit message updated to reflect
> the above points? I'd be happy to sign-off on that.
Fortunately, as near as I can tell, ext4_mb_mark_bb() should never be
called with len <= 0. It might be possible to trick ext4 via a
corrupted file system --- I'd have to take a closer look at that, but
fortunately, in the case where len <= 0, bitmap_bh will be NULL, so
regardless of whether err is 0, or some garbage non-zero value,
brelse(NULL) is a no-op.
So while it's good to avoid the clang warning, but the fact that it
might be possible for err to be a "garbage value" shouldn't be causing
any problem.
Cheers,
- Ted
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ext4: mballoc: avoid garbage value from err
2023-07-24 20:57 ` Theodore Ts'o
@ 2023-07-25 4:21 ` Su Hui
0 siblings, 0 replies; 5+ messages in thread
From: Su Hui @ 2023-07-25 4:21 UTC (permalink / raw)
To: Theodore Ts'o, Nick Desaulniers
Cc: adilger.kernel, nathan, trix, linux-ext4, linux-kernel, llvm,
kernel-janitors
On 2023/7/25 04:57, Theodore Ts'o wrote:
> On Mon, Jul 24, 2023 at 10:19:02AM -0700, Nick Desaulniers wrote:
>>> err is uninitialized and will be judged when it enters the
>>> loop first time and the condition "!ext4_sb_block_valid()"
>>> is true. Although this can't make problems now, it's better
>>> to correct it.
>>>
>>> Signed-off-by: Su Hui <suhui@nfschina.com>
>> Hi Su,
>> Thanks for the patch! I see what the warning is getting at;
>>
>> If `len <= 0` then `err` is never initialized, then is used at line
>> 4178 (that is UB).
>>
>> Would you mind sending a v2 with the commit message updated to reflect
>> the above points? I'd be happy to sign-off on that.
> Fortunately, as near as I can tell, ext4_mb_mark_bb() should never be
> called with len <= 0. It might be possible to trick ext4 via a
> corrupted file system --- I'd have to take a closer look at that, but
> fortunately, in the case where len <= 0, bitmap_bh will be NULL, so
> regardless of whether err is 0, or some garbage non-zero value,
> brelse(NULL) is a no-op.
> So while it's good to avoid the clang warning, but the fact that it
> might be possible for err to be a "garbage value" shouldn't be causing
> any problem.
Maybe it can make the code more robust and clearer. I will send v2 patch
soon.
Thanks for your reply!
Su Hui
>
> Cheers,
>
> - Ted
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ext4: mballoc: avoid garbage value from err
2023-07-24 17:19 ` Nick Desaulniers
2023-07-24 20:57 ` Theodore Ts'o
@ 2023-07-25 4:33 ` Dan Carpenter
1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2023-07-25 4:33 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Su Hui, tytso, adilger.kernel, nathan, trix, linux-ext4,
linux-kernel, llvm, kernel-janitors
On Mon, Jul 24, 2023 at 10:19:02AM -0700, Nick Desaulniers wrote:
> On Sun, Jul 23, 2023 at 10:46 PM Su Hui <suhui@nfschina.com> wrote:
> >
> > clang warning: fs/ext4/mballoc.c, line 4178, column 6
> > Branch condition evaluates to a garbage value.
>
> Specifically this is clang's static analysis; not the compiler itself.
>
> >
> > err is uninitialized and will be judged when it enters the
> > loop first time and the condition "!ext4_sb_block_valid()"
> > is true. Although this can't make problems now, it's better
> > to correct it.
> >
> > Signed-off-by: Su Hui <suhui@nfschina.com>
>
> Hi Su,
> Thanks for the patch! I see what the warning is getting at;
>
> If `len <= 0` then `err` is never initialized, then is used at line
> 4178 (that is UB).
>
> Would you mind sending a v2 with the commit message updated to reflect
> the above points? I'd be happy to sign-off on that.
The commit message talks about !ext4_sb_block_valid() on the first
iteration through the loop and not that len <= 0.
But either way, brelse(NULL) is a no-op.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-25 5:52 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-24 5:45 [PATCH] ext4: mballoc: avoid garbage value from err Su Hui
2023-07-24 17:19 ` Nick Desaulniers
2023-07-24 20:57 ` Theodore Ts'o
2023-07-25 4:21 ` Su Hui
2023-07-25 4:33 ` Dan Carpenter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox