ksmbd: potential uninitialized error code in set_file_basic_info()
Subsystems (3)
PATCH 1/1 ksmbd: potential uninitialized error code in set_file_basic_info()
Smatch complains that there are some paths where "rc" is not set.
--- fs/ksmbd/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +1 -1
@@ -5444,7 +5444,7 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,struct file *filp;struct inode *inode;struct user_namespace *user_ns; -int rc; +int rc =0 ;if (!(fp->daccess &FILE_WRITE_ATTRIBUTES_LE ))return -EACCES ;
Signature · 1 line
2.20.1
Sergey Senozhatsky
reviewerQuoted 14 lines · Dan Carpenter
Smatch complains that there are some paths where "rc" is not set.
Fixes eb5784f0c6ef ("ksmbd: ensure error is surfaced in set_file_basic_info()")Signed-off-by Dan Carpenter <[email protected]>--- fs/ksmbd/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ksmbd/smb2pdu.c +0
-0
fs/ksmbd/smb2pdu.c static int set_file_basic_info(struct ksmbd_file *fp, char *buf, · line 5450
Quoted 8 lines
fs/ksmbd/smb2pdu.c +1
-1@@ -5444,7 +5444,7 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf,struct file *filp;struct inode *inode;struct user_namespace *user_ns; -int rc; +int rc =0 ;if (!(fp->daccess &FILE_WRITE_ATTRIBUTES_LE ))return -EACCES ;
It sort of feels like that `rc' is not needed there at all. It's being used in
rc = ksmbd_vfs_set_dos_attrib_xattr(user_ns,
filp->f_path.dentry, &da);
if (rc)
ksmbd_debug(SMB,
"failed to restore file attribute in EA\n");and in
rc = setattr_prepare(user_ns, dentry, &attrs);
if (rc)
return -EINVAL;Either it should be used more, and probably be a return value, or we can just remove it.
Namjae Jeon
maintainer2021-09-07 17:01 GMT+09:00, Sergey Senozhatsky <[email protected]>:
Quoted 37 lines · Dan Carpenter
Quoted 23 lines
Smatch complains that there are some paths where "rc" is not set.
Fixes eb5784f0c6ef ("ksmbd: ensure error is surfaced in
set_file_basic_info()")Signed-off-by Dan Carpenter <[email protected]>--- fs/ksmbd/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ksmbd/smb2pdu.c +1
-1@@ -5444,7 +5444,7 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf, struct file *filp;struct inode *inode;struct user_namespace *user_ns; -int rc; +int rc =0 ;if (!(fp->daccess &FILE_WRITE_ATTRIBUTES_LE ))Quoted 1 line
return
-EACCES;It sort of feels like that `rc' is not needed there at all. It's being used in
rc = ksmbd_vfs_set_dos_attrib_xattr(user_ns,
filp->f_path.dentry,
&da);
if (rc)
ksmbd_debug(SMB,
"failed to restore file attribute in
EA\n");
Quoted 8 lines
and in
rc = setattr_prepare(user_ns, dentry, &attrs); if (rc) return -EINVAL;Either it should be used more, and probably be a return value, or we can just remove it.
This patch is correct. But I have already fixed it.
You can understand it if you check #ksmbd-for-next branch, not master.
https://git.samba.org/?p=ksmbd.git;a=shortlog;h=refs/heads/ksmbd-for-next
Thanks!
Quoted 1 line
Sergey Senozhatsky
reviewerQuoted 44 lines · Namjae Jeon
2021-09-07 17:01 GMT+09:00, Sergey Senozhatsky <[email protected]>:
Quoted 43 lines · Dan Carpenter
Quoted 23 lines
Smatch complains that there are some paths where "rc" is not set.
Fixes eb5784f0c6ef ("ksmbd: ensure error is surfaced in
set_file_basic_info()")Signed-off-by Dan Carpenter <[email protected]>--- fs/ksmbd/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ksmbd/smb2pdu.c +1
-1@@ -5444,7 +5444,7 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf, struct file *filp;struct inode *inode;struct user_namespace *user_ns; -int rc; +int rc =0 ;if (!(fp->daccess &FILE_WRITE_ATTRIBUTES_LE ))Quoted 1 line
return
-EACCES;It sort of feels like that `rc' is not needed there at all. It's being used in
rc = ksmbd_vfs_set_dos_attrib_xattr(user_ns,
filp->f_path.dentry,
&da);
if (rc)
ksmbd_debug(SMB,
"failed to restore file attribute in
EA\n");and in
rc = setattr_prepare(user_ns, dentry, &attrs); if (rc) return -EINVAL;
Quoted 6 lines
Quoted 2 lines
Either it should be used more, and probably be a return value, or we can just remove it.
This patch is correct. But I have already fixed it.
You can understand it if you check #ksmbd-for-next branch, not master.https://git.samba.org/?p=ksmbd.git;a=shortlog;h=refs/heads/ksmbd-for-next
I assume it's "ksmbd: ensure error is surfaced in set_file_basic_info()"
If none of the branches that set `rc' is taken then function returns random stack value:
---
int rc;
if (test_share_config_flag(share, KSMBD_SHARE_FLAG_STORE_DOS_ATTRS) ... {
rc = ...
}
if (attrs.ia_valid) .... {
rc = ...
}
return rc;---
Quoted 7 lines · Sergey Senozhatsky
rc = setattr_prepare(user_ns, dentry, &attrs); if (rc) return -EINVAL;Either it should be used more, and probably be a return value, or we can just remove it.
You are looking at old code from before the bug was introduced.
regards,
dan carpenter
Sergey Senozhatsky
reviewerQuoted 10 lines · Dan Carpenter
Quoted 7 lines · Sergey Senozhatsky
rc = setattr_prepare(user_ns, dentry, &attrs); if (rc) return -EINVAL;Either it should be used more, and probably be a return value, or we can just remove it.
You are looking at old code from before the bug was introduced.
Right. I fetched today's linux-next and see the point now.
Quoted 44 lines · Namjae Jeon
2021-09-07 17:01 GMT+09:00, Sergey Senozhatsky <[email protected]>:
Quoted 43 lines · Dan Carpenter
Quoted 23 lines
Smatch complains that there are some paths where "rc" is not set.
Fixes eb5784f0c6ef ("ksmbd: ensure error is surfaced in
set_file_basic_info()")Signed-off-by Dan Carpenter <[email protected]>--- fs/ksmbd/smb2pdu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/ksmbd/smb2pdu.c +1
-1@@ -5444,7 +5444,7 @@ static int set_file_basic_info(struct ksmbd_file *fp, char *buf, struct file *filp;struct inode *inode;struct user_namespace *user_ns; -int rc; +int rc =0 ;if (!(fp->daccess &FILE_WRITE_ATTRIBUTES_LE ))Quoted 1 line
return
-EACCES;It sort of feels like that `rc' is not needed there at all. It's being used in
rc = ksmbd_vfs_set_dos_attrib_xattr(user_ns,
filp->f_path.dentry,
&da);
if (rc)
ksmbd_debug(SMB,
"failed to restore file attribute in
EA\n");and in
rc = setattr_prepare(user_ns, dentry, &attrs); if (rc) return -EINVAL;
Quoted 6 lines
Quoted 2 lines
Either it should be used more, and probably be a return value, or we can just remove it.
This patch is correct. But I have already fixed it.
You can understand it if you check #ksmbd-for-next branch, not master.https://git.samba.org/?p=ksmbd.git;a=shortlog;h=refs/heads/ksmbd-for-next
Thanks for fixing it. I was out on vacation last week.
Christian