public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
From: Lukas Czerner <lczerner@redhat.com>
To: Theodore Ts'o <tytso@mit.edu>
Cc: cgel.zte@gmail.com, Andreas Dilger <adilger.kernel@dilger.ca>,
	linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org,
	luo penghao <luo.penghao@zte.com.cn>,
	Zeal Robot <zealci@zte.com.cn>,
	Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Subject: Re: [PATCH linux] ext4: Delete useless ret assignment
Date: Thu, 6 Jan 2022 11:58:43 +0100	[thread overview]
Message-ID: <20220106105843.comh4jk3krxppgbp@work> (raw)
In-Reply-To: <YdZzt0LF/ajTGNXo@mit.edu>

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
> > 
> > 
> 


  reply	other threads:[~2022-01-06 10:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-01-07  0:59     ` harshad shirwadkar
2022-01-12 16:18       ` riteshh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220106105843.comh4jk3krxppgbp@work \
    --to=lczerner@redhat.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=cgel.zte@gmail.com \
    --cc=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luo.penghao@zte.com.cn \
    --cc=tytso@mit.edu \
    --cc=zealci@zte.com.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox