The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Jeff Layton <jlayton@kernel.org>
To: Dan Carpenter <dan.carpenter@linaro.org>,
	"Everest K.C." <everestkc@everestkc.com.np>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
	 skhan@linuxfoundation.org, linux-fsdevel@vger.kernel.org,
	 kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] fs: Fix uninitialized scalar variable now
Date: Wed, 09 Oct 2024 18:39:59 -0400	[thread overview]
Message-ID: <439cb2078a8eefa782bc8da4a77bb8ac43725ba4.camel@kernel.org> (raw)
In-Reply-To: <263ceb04-f909-45d8-b9b2-5de86617ea25@stanley.mountain>

On Wed, 2024-10-09 at 23:45 +0300, Dan Carpenter wrote:
> On Wed, Oct 09, 2024 at 02:05:25PM -0600, Everest K.C. wrote:
> > Variable `now` is declared without initialization. The variable
> > could be accessed inside the if-else statements following the
> > variable declaration, before it has been initialized.
> > 
> > This patch initializes the variable to
> > `inode_set_ctime_current(inode)` by default.
> > 
> > This issue was reported by Coverity Scan.
> > 
> > Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> 
> Fixes: d8d11298e8a1 ("fs: handle delegated timestamps in setattr_copy_mgtime")
> 
> Maybe the WARN_ON_ONCE() should be updated to check ATTR_ATIME as well?
> 
> regards,
> dan carpenter
> 
> > ---
> >  fs/attr.c | 4 +---
> >  1 file changed, 1 insertion(+), 3 deletions(-)
> > 
> > diff --git a/fs/attr.c b/fs/attr.c
> > index c614b954bda5..77523af2e62d 100644
> > --- a/fs/attr.c
> > +++ b/fs/attr.c
> > @@ -284,7 +284,7 @@ EXPORT_SYMBOL(inode_newsize_ok);
> >  static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr)
> >  {
> >  	unsigned int ia_valid = attr->ia_valid;
> > -	struct timespec64 now;
> > +	struct timespec64 now = inode_set_ctime_current(inode);
> >  
> >  	if (ia_valid & ATTR_CTIME) {
> >  		/*
> > @@ -293,8 +293,6 @@ static void setattr_copy_mgtime(struct inode *inode, const struct iattr *attr)
> >  		 */
> >  		if (ia_valid & ATTR_DELEG)
> >  			now = inode_set_ctime_deleg(inode, attr->ia_ctime);
> > -		else
> > -			now = inode_set_ctime_current(inode);
> >  	} else {
> >  		/* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */
> >  		WARN_ON_ONCE(ia_valid & ATTR_MTIME);
> > -- 
> > 2.43.0
> > 

This doesn't look correct. inode_set_ctime_current will update the time
to the current time and then inode_set_ctime_deleg() won't work
properly if the time being set is earlier than that.

I proposed a different fix earlier today which should be correct:

https://lore.kernel.org/linux-fsdevel/20241009-mgtime-v1-1-383b9e0481b5@kernel.org/

Thanks,
-- 
Jeff Layton <jlayton@kernel.org>

  parent reply	other threads:[~2024-10-09 22:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-09 20:05 [PATCH][next] fs: Fix uninitialized scalar variable now Everest K.C.
2024-10-09 20:38 ` Shuah Khan
2024-10-09 21:46   ` Everest K.C.
2024-10-09 20:45 ` Dan Carpenter
2024-10-09 21:48   ` Everest K.C.
2024-10-09 22:39   ` Jeff Layton [this message]
2024-10-09 22:55     ` Everest K.C.

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=439cb2078a8eefa782bc8da4a77bb8ac43725ba4.camel@kernel.org \
    --to=jlayton@kernel.org \
    --cc=brauner@kernel.org \
    --cc=dan.carpenter@linaro.org \
    --cc=everestkc@everestkc.com.np \
    --cc=jack@suse.cz \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=viro@zeniv.linux.org.uk \
    /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