* [PATCH][next] fs: Fix uninitialized scalar variable now
@ 2024-10-09 20:05 Everest K.C.
2024-10-09 20:38 ` Shuah Khan
2024-10-09 20:45 ` Dan Carpenter
0 siblings, 2 replies; 7+ messages in thread
From: Everest K.C. @ 2024-10-09 20:05 UTC (permalink / raw)
To: viro, brauner, jack
Cc: Everest K.C., skhan, linux-fsdevel, kernel-janitors, linux-kernel
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>
---
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH][next] fs: Fix uninitialized scalar variable now
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
1 sibling, 1 reply; 7+ messages in thread
From: Shuah Khan @ 2024-10-09 20:38 UTC (permalink / raw)
To: Everest K.C., viro, brauner, jack
Cc: linux-fsdevel, kernel-janitors, linux-kernel, Shuah Khan
On 10/9/24 14:05, 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.
It could be, but it isn't. I am not sure if this change is needed.
>
> This patch initializes the variable to
> `inode_set_ctime_current(inode)` by default.
Instead of "This patch initializes", change it to "Initialize ..."
Do refer to submitting patches document for information on how
to write change logs.
>
> This issue was reported by Coverity Scan.
Include the the error/report from Coverity.
>
> Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> ---
> 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);
The code is clear and easy to read the way it is since it handles both cases
and does appropriate initialization.
> } else {
> /* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */
> WARN_ON_ONCE(ia_valid & ATTR_MTIME);
I will leave it up to the maintainers to decide whether to take
this change or not.
thanks,
-- Shuah
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][next] fs: Fix uninitialized scalar variable now
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 20:45 ` Dan Carpenter
2024-10-09 21:48 ` Everest K.C.
2024-10-09 22:39 ` Jeff Layton
1 sibling, 2 replies; 7+ messages in thread
From: Dan Carpenter @ 2024-10-09 20:45 UTC (permalink / raw)
To: Everest K.C., Jeff Layton
Cc: viro, brauner, jack, skhan, linux-fsdevel, kernel-janitors,
linux-kernel
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
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][next] fs: Fix uninitialized scalar variable now
2024-10-09 20:38 ` Shuah Khan
@ 2024-10-09 21:46 ` Everest K.C.
0 siblings, 0 replies; 7+ messages in thread
From: Everest K.C. @ 2024-10-09 21:46 UTC (permalink / raw)
To: Shuah Khan
Cc: viro, brauner, jack, linux-fsdevel, kernel-janitors, linux-kernel
On Wed, Oct 9, 2024 at 2:38 PM Shuah Khan <skhan@linuxfoundation.org> wrote:
>
> On 10/9/24 14:05, 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.
>
> It could be, but it isn't. I am not sure if this change is needed.
If you look at the full code then, if `ia_valid & ATTR_CTIME`
evaluates to False then now is never initialized.
> > This patch initializes the variable to
> > `inode_set_ctime_current(inode)` by default.
>
> Instead of "This patch initializes", change it to "Initialize ..."
> Do refer to submitting patches document for information on how
> to write change logs.
Will do that and send V2.
> >
> > This issue was reported by Coverity Scan.
>
> Include the the error/report from Coverity.
Will do that and send V2.
> >
> > Signed-off-by: Everest K.C. <everestkc@everestkc.com.np>
> > ---
> > 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);
>
> The code is clear and easy to read the way it is since it handles both cases
> and does appropriate initialization.
Yes, I agree, but if we initialize now to the current time during its
declaration then the else
condition won't be necessary.
>
> > } else {
> > /* If ATTR_CTIME isn't set, then ATTR_MTIME shouldn't be either. */
> > WARN_ON_ONCE(ia_valid & ATTR_MTIME);
>
> I will leave it up to the maintainers to decide whether to take
> this change or not.
>
> thanks,
> -- Shuah
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][next] fs: Fix uninitialized scalar variable now
2024-10-09 20:45 ` Dan Carpenter
@ 2024-10-09 21:48 ` Everest K.C.
2024-10-09 22:39 ` Jeff Layton
1 sibling, 0 replies; 7+ messages in thread
From: Everest K.C. @ 2024-10-09 21:48 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jeff Layton, viro, brauner, jack, skhan, linux-fsdevel,
kernel-janitors, linux-kernel
On Wed, Oct 9, 2024 at 2:45 PM Dan Carpenter <dan.carpenter@linaro.org> 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?
I am not sure about that, but even if that is necessary. I think it
should be handled in a different patch.
> 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
> >
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][next] fs: Fix uninitialized scalar variable now
2024-10-09 20:45 ` Dan Carpenter
2024-10-09 21:48 ` Everest K.C.
@ 2024-10-09 22:39 ` Jeff Layton
2024-10-09 22:55 ` Everest K.C.
1 sibling, 1 reply; 7+ messages in thread
From: Jeff Layton @ 2024-10-09 22:39 UTC (permalink / raw)
To: Dan Carpenter, Everest K.C.
Cc: viro, brauner, jack, skhan, linux-fsdevel, kernel-janitors,
linux-kernel
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH][next] fs: Fix uninitialized scalar variable now
2024-10-09 22:39 ` Jeff Layton
@ 2024-10-09 22:55 ` Everest K.C.
0 siblings, 0 replies; 7+ messages in thread
From: Everest K.C. @ 2024-10-09 22:55 UTC (permalink / raw)
To: Jeff Layton
Cc: Dan Carpenter, viro, brauner, jack, skhan, linux-fsdevel,
kernel-janitors, linux-kernel
On Wed, Oct 9, 2024 at 4:40 PM Jeff Layton <jlayton@kernel.org> wrote:
>
> 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.
Yes. I get it now.
> 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>
Thanks,
Everest K.C.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-10-09 22:55 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-10-09 22:55 ` Everest K.C.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox