* [PATCH linux] ext4: Delete useless ret assignment @ 2021-12-30 6:29 cgel.zte 2022-01-06 4:44 ` Theodore Ts'o 0 siblings, 1 reply; 5+ messages in thread From: cgel.zte @ 2021-12-30 6:29 UTC (permalink / raw) To: Theodore Ts'o Cc: Andreas Dilger, linux-ext4, linux-kernel, luo penghao, Zeal Robot From: luo penghao <luo.penghao@zte.com.cn> 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 <zealci@zte.com.cn> Signed-off-by: luo penghao <luo.penghao@zte.com.cn> --- 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH linux] ext4: Delete useless ret assignment 2021-12-30 6:29 [PATCH linux] ext4: Delete useless ret assignment cgel.zte @ 2022-01-06 4:44 ` Theodore Ts'o 2022-01-06 10:58 ` Lukas Czerner 0 siblings, 1 reply; 5+ messages in thread From: Theodore Ts'o @ 2022-01-06 4:44 UTC (permalink / raw) To: cgel.zte Cc: Andreas Dilger, linux-ext4, linux-kernel, luo penghao, Zeal Robot, Harshad Shirwadkar On Thu, Dec 30, 2021 at 06:29:05AM +0000, cgel.zte@gmail.com wrote: > From: luo penghao <luo.penghao@zte.com.cn> > > 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 <zealci@zte.com.cn> > Signed-off-by: luo penghao <luo.penghao@zte.com.cn> > --- > 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 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH linux] ext4: Delete useless ret assignment 2022-01-06 4:44 ` Theodore Ts'o @ 2022-01-06 10:58 ` Lukas Czerner 2022-01-07 0:59 ` harshad shirwadkar 0 siblings, 1 reply; 5+ messages in thread From: Lukas Czerner @ 2022-01-06 10:58 UTC (permalink / raw) To: Theodore Ts'o Cc: cgel.zte, Andreas Dilger, linux-ext4, linux-kernel, luo penghao, Zeal Robot, Harshad Shirwadkar On Wed, Jan 05, 2022 at 11:44:39PM -0500, Theodore Ts'o wrote: > On Thu, Dec 30, 2021 at 06:29:05AM +0000, cgel.zte@gmail.com wrote: > > From: luo penghao <luo.penghao@zte.com.cn> > > > > 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 <zealci@zte.com.cn> > > Signed-off-by: luo penghao <luo.penghao@zte.com.cn> > > --- > > 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 > > > > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH linux] ext4: Delete useless ret assignment 2022-01-06 10:58 ` Lukas Czerner @ 2022-01-07 0:59 ` harshad shirwadkar 2022-01-12 16:18 ` riteshh 0 siblings, 1 reply; 5+ messages in thread From: harshad shirwadkar @ 2022-01-07 0:59 UTC (permalink / raw) To: Lukas Czerner Cc: Theodore Ts'o, cgel.zte, Andreas Dilger, Ext4 Developers List, linux-kernel, luo penghao, Zeal Robot 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 <lczerner@redhat.com> 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, cgel.zte@gmail.com wrote: > > > From: luo penghao <luo.penghao@zte.com.cn> > > > > > > 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 <zealci@zte.com.cn> > > > Signed-off-by: luo penghao <luo.penghao@zte.com.cn> > > > --- > > > 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 > > > > > > > > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH linux] ext4: Delete useless ret assignment 2022-01-07 0:59 ` harshad shirwadkar @ 2022-01-12 16:18 ` riteshh 0 siblings, 0 replies; 5+ messages in thread From: riteshh @ 2022-01-12 16:18 UTC (permalink / raw) To: harshad shirwadkar, luo penghao Cc: Lukas Czerner, Theodore Ts'o, cgel.zte, Andreas Dilger, Ext4 Developers List, linux-kernel, Zeal Robot On 22/01/06 04:59PM, harshad shirwadkar wrote: > 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 <lczerner@redhat.com> 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, cgel.zte@gmail.com wrote: > > > > From: luo penghao <luo.penghao@zte.com.cn> > > > > > > > > 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 > > > Since I was also suspecting a similar issue in ext4_fc_record_modified_inode() (w.r.t. krealloc()) while doing some code reviews a while ago. And I also happened to stumble upon this discussion which added some more context to it. @Luo, I am preparing some other fixes and might submit this fix also as part of those. I am completely ok, if you would like to push a patch from your end based on this discussion. In that case, I will request to drop my patch or won't even publish it, if you submit it before my fixes gets out. -ritesh > > > 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 <zealci@zte.com.cn> > > > > Signed-off-by: luo penghao <luo.penghao@zte.com.cn> > > > > --- > > > > 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 > > > > > > > > > > > > > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-01-12 16:19 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-12-30 6:29 [PATCH linux] ext4: Delete useless ret assignment cgel.zte 2022-01-06 4:44 ` Theodore Ts'o 2022-01-06 10:58 ` Lukas Czerner 2022-01-07 0:59 ` harshad shirwadkar 2022-01-12 16:18 ` riteshh
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.