2021-12-30 06:29:14

by CGEL

[permalink] [raw]
Subject: [PATCH linux] ext4: Delete useless ret assignment

From: luo penghao <[email protected]>

The assignments in these two places will be overwritten by new
assignments later, so they should be deleted.

The clang_analyzer complains as follows:

fs/ext4/fast_commit.c

Value stored to 'ret' is never read

Reported-by: Zeal Robot <[email protected]>
Signed-off-by: luo penghao <[email protected]>
---
fs/ext4/fast_commit.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
index 8ea5a81..8d5d044 100644
--- a/fs/ext4/fast_commit.c
+++ b/fs/ext4/fast_commit.c
@@ -1660,7 +1660,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
return 0;
}

- ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
+ ext4_fc_record_modified_inode(sb, inode->i_ino);

start = le32_to_cpu(ex->ee_block);
start_pblk = ext4_ext_pblock(ex);
@@ -1785,7 +1785,7 @@ ext4_fc_replay_del_range(struct super_block *sb, struct ext4_fc_tl *tl,
return 0;
}

- ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
+ ext4_fc_record_modified_inode(sb, inode->i_ino);

jbd_debug(1, "DEL_RANGE, inode %ld, lblk %d, len %d\n",
inode->i_ino, le32_to_cpu(lrange.fc_lblk),
--
2.15.2




2022-01-06 04:44:45

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH linux] ext4: Delete useless ret assignment

On Thu, Dec 30, 2021 at 06:29:05AM +0000, [email protected] wrote:
> From: luo penghao <[email protected]>
>
> The assignments in these two places will be overwritten by new
> assignments later, so they should be deleted.
>
> The clang_analyzer complains as follows:
>
> fs/ext4/fast_commit.c
>
> Value stored to 'ret' is never read

I suspect the right answer here is that we *should* be checking the
return value, and reflecting the error up to caller, if appropriate.

Harshad, what do you think?

- Ted

>
> Reported-by: Zeal Robot <[email protected]>
> Signed-off-by: luo penghao <[email protected]>
> ---
> fs/ext4/fast_commit.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> index 8ea5a81..8d5d044 100644
> --- a/fs/ext4/fast_commit.c
> +++ b/fs/ext4/fast_commit.c
> @@ -1660,7 +1660,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
> return 0;
> }
>
> - ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
> + ext4_fc_record_modified_inode(sb, inode->i_ino);
>
> start = le32_to_cpu(ex->ee_block);
> start_pblk = ext4_ext_pblock(ex);
> @@ -1785,7 +1785,7 @@ ext4_fc_replay_del_range(struct super_block *sb, struct ext4_fc_tl *tl,
> return 0;
> }
>
> - ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
> + ext4_fc_record_modified_inode(sb, inode->i_ino);
>
> jbd_debug(1, "DEL_RANGE, inode %ld, lblk %d, len %d\n",
> inode->i_ino, le32_to_cpu(lrange.fc_lblk),
> --
> 2.15.2
>
>

2022-01-06 10:58:54

by Lukas Czerner

[permalink] [raw]
Subject: Re: [PATCH linux] ext4: Delete useless ret assignment

On Wed, Jan 05, 2022 at 11:44:39PM -0500, Theodore Ts'o wrote:
> On Thu, Dec 30, 2021 at 06:29:05AM +0000, [email protected] wrote:
> > From: luo penghao <[email protected]>
> >
> > The assignments in these two places will be overwritten by new
> > assignments later, so they should be deleted.
> >
> > The clang_analyzer complains as follows:
> >
> > fs/ext4/fast_commit.c
> >
> > Value stored to 'ret' is never read
>
> I suspect the right answer here is that we *should* be checking the
> return value, and reflecting the error up to caller, if appropriate.
>
> Harshad, what do you think?

Indeed we absolutely *must* be checking the return value and bail out
otherwise we risk overwriting kernel memory among other possible
problems.

See ext4_fc_record_modified_inode() where we increment
fc_modified_inodes_size before the actual reallocation which in case of
allocation failure will leave us with elevated fc_modified_inodes_size
and the next call to ext4_fc_record_modified_inode() can modify
fc_modified_inodes[] out of bounds.

In addition to checking the return value we should probably also move
incrementing the fc_modified_inodes_size until after the successful
reallocation in order to avoid such pitfalls.

Thanks!
-Lukas

>
> - Ted
>
> >
> > Reported-by: Zeal Robot <[email protected]>
> > Signed-off-by: luo penghao <[email protected]>
> > ---
> > fs/ext4/fast_commit.c | 4 ++--
> > 1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> > index 8ea5a81..8d5d044 100644
> > --- a/fs/ext4/fast_commit.c
> > +++ b/fs/ext4/fast_commit.c
> > @@ -1660,7 +1660,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
> > return 0;
> > }
> >
> > - ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
> > + ext4_fc_record_modified_inode(sb, inode->i_ino);
> >
> > start = le32_to_cpu(ex->ee_block);
> > start_pblk = ext4_ext_pblock(ex);
> > @@ -1785,7 +1785,7 @@ ext4_fc_replay_del_range(struct super_block *sb, struct ext4_fc_tl *tl,
> > return 0;
> > }
> >
> > - ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
> > + ext4_fc_record_modified_inode(sb, inode->i_ino);
> >
> > jbd_debug(1, "DEL_RANGE, inode %ld, lblk %d, len %d\n",
> > inode->i_ino, le32_to_cpu(lrange.fc_lblk),
> > --
> > 2.15.2
> >
> >
>


2022-01-07 01:00:01

by harshad shirwadkar

[permalink] [raw]
Subject: Re: [PATCH linux] ext4: Delete useless ret assignment

First of all thanks for catching this. Yeah, I think the right thing
to do here is to return the return value up to the caller. Also, I
agree with Lukas, we should only set fc_modified_inodes_size if the
allocation succeeds. Luo, would you be okay updating the patch to
include these changes?

Thanks,
Harshad

On Thu, Jan 6, 2022 at 2:58 AM Lukas Czerner <[email protected]> wrote:
>
> On Wed, Jan 05, 2022 at 11:44:39PM -0500, Theodore Ts'o wrote:
> > On Thu, Dec 30, 2021 at 06:29:05AM +0000, [email protected] wrote:
> > > From: luo penghao <[email protected]>
> > >
> > > The assignments in these two places will be overwritten by new
> > > assignments later, so they should be deleted.
> > >
> > > The clang_analyzer complains as follows:
> > >
> > > fs/ext4/fast_commit.c
> > >
> > > Value stored to 'ret' is never read
> >
> > I suspect the right answer here is that we *should* be checking the
> > return value, and reflecting the error up to caller, if appropriate.
> >
> > Harshad, what do you think?
>
> Indeed we absolutely *must* be checking the return value and bail out
> otherwise we risk overwriting kernel memory among other possible
> problems.
>
> See ext4_fc_record_modified_inode() where we increment
> fc_modified_inodes_size before the actual reallocation which in case of
> allocation failure will leave us with elevated fc_modified_inodes_size
> and the next call to ext4_fc_record_modified_inode() can modify
> fc_modified_inodes[] out of bounds.
>
> In addition to checking the return value we should probably also move
> incrementing the fc_modified_inodes_size until after the successful
> reallocation in order to avoid such pitfalls.
>
> Thanks!
> -Lukas
>
> >
> > - Ted
> >
> > >
> > > Reported-by: Zeal Robot <[email protected]>
> > > Signed-off-by: luo penghao <[email protected]>
> > > ---
> > > fs/ext4/fast_commit.c | 4 ++--
> > > 1 file changed, 2 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/fs/ext4/fast_commit.c b/fs/ext4/fast_commit.c
> > > index 8ea5a81..8d5d044 100644
> > > --- a/fs/ext4/fast_commit.c
> > > +++ b/fs/ext4/fast_commit.c
> > > @@ -1660,7 +1660,7 @@ static int ext4_fc_replay_add_range(struct super_block *sb,
> > > return 0;
> > > }
> > >
> > > - ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
> > > + ext4_fc_record_modified_inode(sb, inode->i_ino);
> > >
> > > start = le32_to_cpu(ex->ee_block);
> > > start_pblk = ext4_ext_pblock(ex);
> > > @@ -1785,7 +1785,7 @@ ext4_fc_replay_del_range(struct super_block *sb, struct ext4_fc_tl *tl,
> > > return 0;
> > > }
> > >
> > > - ret = ext4_fc_record_modified_inode(sb, inode->i_ino);
> > > + ext4_fc_record_modified_inode(sb, inode->i_ino);
> > >
> > > jbd_debug(1, "DEL_RANGE, inode %ld, lblk %d, len %d\n",
> > > inode->i_ino, le32_to_cpu(lrange.fc_lblk),
> > > --
> > > 2.15.2
> > >
> > >
> >
>