Skip to contentSkip to conversation

ksmbd: potential uninitialized error code in set_file_basic_info()

PATCH In review Dan Carpenter 4 participants 7 messages Sep 7, 2021 – Sep 13, 2021

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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.

Fixes eb5784f0c6ef ("ksmbd: ensure error is surfaced in set_file_basic_info()")
---
 fs/ksmbd/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +1 -1
index a350e1cef7f4..c86164dc70bb 100644
@@ -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
#1 lore raw
Quoted 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()")
---
 fs/ksmbd/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +0 -0
index a350e1cef7f4..c86164dc70bb 100644

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.

maintainer
#2 lore raw

2021-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()")

---
 fs/ksmbd/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +1 -1
index a350e1cef7f4..c86164dc70bb 100644
@@ -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
#3 lore raw
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()")

---
 fs/ksmbd/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +1 -1
index a350e1cef7f4..c86164dc70bb 100644
@@ -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;

---

#5 lore raw
In reply to Sergey Senozhatsky
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

#6 lore raw
Quoted 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.

#4 lore raw
In reply to Namjae Jeon
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()")

---
 fs/ksmbd/smb2pdu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ksmbd/smb2pdu.c +1 -1
index a350e1cef7f4..c86164dc70bb 100644
@@ -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