Skip to contentSkip to conversation

fs/cifs/cifsacl: fix sid_to_id

PATCH In review Qiujun Huang 3 participants 4 messages Mar 3, 2020 – Mar 5, 2020

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

PATCH 1/1 fs/cifs/cifsacl: fix sid_to_id

fix it to return the errcode.

---
 fs/cifs/cifsacl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cifs/cifsacl.c +2 -1
index 716574a..a8d2aa8 100644
@@ -400,6 +400,7 @@
 	if (!sidstr)
 		return -ENOMEM;
 
+	rc = 0;
 	saved_cred = override_creds(root_cred);
 	sidkey = request_key(&cifs_idmap_key_type, sidstr, "");
 	if (IS_ERR(sidkey)) {
@@ -454,7 +455,7 @@
 		fattr->cf_uid = fuid;
 	else
 		fattr->cf_gid = fgid;
-	return 0;
+	return rc;
 }
 
 int
Signature · 1 line
1.8.3.1
#1 lore raw

Doesn't rc = 0 have to be set earlier (preferably in the declaration on line 345)?

since line 392 does

            goto got_valid_id;

which appears to leave rc unitialized with your change

Quoted 32 lines · Qiujun Huang

fix it to return the errcode.

---
 fs/cifs/cifsacl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/cifs/cifsacl.c +2 -2
index 716574a..a8d2aa8 100644
@@ -400,6 +400,7 @@
        if (!sidstr)
                return -ENOMEM;
 
+       rc = 0;
        saved_cred = override_creds(root_cred);
        sidkey = request_key(&cifs_idmap_key_type, sidstr, "");
        if (IS_ERR(sidkey)) {
@@ -454,7 +455,7 @@
                fattr->cf_uid = fuid;
        else
                fattr->cf_gid = fgid;
-       return 0;
+       return rc;
 }
 
 int
--

1.8.3.1

Signature · 3 lines
Thanks,

Steve
#2 lore raw
Quoted 8 lines · Steve French

Doesn't rc = 0 have to be set earlier (preferably in the declaration on line 345)?

since line 392 does

            goto got_valid_id;

which appears to leave rc unitialized with your change

ok, I noticed that fall back to using the mnt_uid/mnt_gid.

Should we remove the variable 'rc'. It is set but not used. And I was confused last time. (:

fs/cifs/cifsacl.c +0 -3
index 716574a..1cf3916 100644
@@ -342,7 +342,6 @@
 sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
                struct cifs_fattr *fattr, uint sidtype)
 {
-       int rc;
        struct key *sidkey;
        char *sidstr;
        const struct cred *saved_cred;
@@ -403,7 +402,6 @@
        saved_cred = override_creds(root_cred);
        sidkey = request_key(&cifs_idmap_key_type, sidstr, "");
        if (IS_ERR(sidkey)) {
-               rc = -EINVAL;
                cifs_dbg(FYI, "%s: Can't map SID %s to a %cid\n",
                         __func__, sidstr, sidtype == SIDOWNER ? 'u' : 'g');
                goto out_revert_creds;
@@ -416,7 +414,6 @@
         */
        BUILD_BUG_ON(sizeof(uid_t) != sizeof(gid_t));
        if (sidkey->datalen != sizeof(uid_t)) {
-               rc = -EIO;
                cifs_dbg(FYI, "%s: Downcall contained malformed key

(datalen=%hu)\n",

                         __func__, sidkey->datalen);
                key_invalidate(sidkey);
#3 lore raw
In reply to Qiujun Huang
Thank you for the patch! Perhaps something to improve:

Hi Qiujun,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on cifs/for-next]
[also build test WARNING on v5.6-rc4 next-20200304]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Qiujun-Huang/fs-cifs-cifsacl-fix-sid_to_id/20200304-041618
base:   git://git.samba.org/sfrench/cifs-2.6.git for-next
config: x86_64-allyesconfig (attached as .config)
compiler: clang version 11.0.0 (git://gitmirror/llvm_project f95095e9f612084fc95c5e797c2ab5eb8dd674b8)

reproduce:
# FIXME the reproduce steps for clang is not ready yet

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

>> fs/cifs/cifsacl.c:390:8: warning: variable 'rc' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                           if (uid_valid(uid)) {
                               ^~~~~~~~~~~~~~
   fs/cifs/cifsacl.c:458:9: note: uninitialized use occurs here
           return rc;
                  ^~
   fs/cifs/cifsacl.c:390:4: note: remove the 'if' if its condition is always false
                           if (uid_valid(uid)) {
                           ^~~~~~~~~~~~~~~~~~~~~
   fs/cifs/cifsacl.c:380:8: warning: variable 'rc' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
                           if (gid_valid(gid)) {
                               ^~~~~~~~~~~~~~
   fs/cifs/cifsacl.c:458:9: note: uninitialized use occurs here
           return rc;
                  ^~
   fs/cifs/cifsacl.c:380:4: note: remove the 'if' if its condition is always false
                           if (gid_valid(gid)) {
                           ^~~~~~~~~~~~~~~~~~~~~
   fs/cifs/cifsacl.c:345:8: note: initialize the variable 'rc' to silence this warning
           int rc;
                 ^
                  = 0

2 warnings generated.

vim +390 fs/cifs/cifsacl.c

21fed0d5b763b94 Shirish Pargaonkar 2011-08-09  340  
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  341  static int
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  342  sid_to_id(struct cifs_sb_info *cifs_sb, struct cifs_sid *psid,
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  343  		struct cifs_fattr *fattr, uint sidtype)
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  344  {
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  345  	int rc;
faa65f07d21e7d3 Jeff Layton        2012-12-03  346  	struct key *sidkey;
faa65f07d21e7d3 Jeff Layton        2012-12-03  347  	char *sidstr;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  348  	const struct cred *saved_cred;
8abf2775dd425ec Eric W. Biederman  2013-02-06  349  	kuid_t fuid = cifs_sb->mnt_uid;
8abf2775dd425ec Eric W. Biederman  2013-02-06  350  	kgid_t fgid = cifs_sb->mnt_gid;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  351  
faa65f07d21e7d3 Jeff Layton        2012-12-03  352  	/*
faa65f07d21e7d3 Jeff Layton        2012-12-03  353  	 * If we have too many subauthorities, then something is really wrong.
faa65f07d21e7d3 Jeff Layton        2012-12-03  354  	 * Just return an error.
faa65f07d21e7d3 Jeff Layton        2012-12-03  355  	 */
faa65f07d21e7d3 Jeff Layton        2012-12-03  356  	if (unlikely(psid->num_subauth > SID_MAX_SUB_AUTHORITIES)) {
f96637be081141d Joe Perches        2013-05-04  357  		cifs_dbg(FYI, "%s: %u subauthorities is too many!\n",
f96637be081141d Joe Perches        2013-05-04  358  			 __func__, psid->num_subauth);
faa65f07d21e7d3 Jeff Layton        2012-12-03  359  		return -EIO;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  360  	}
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  361  
3514de3fd5fab51 Steve French       2016-10-13  362  	if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_UID_FROM_ACL) {
3514de3fd5fab51 Steve French       2016-10-13  363  		uint32_t unix_id;
3514de3fd5fab51 Steve French       2016-10-13  364  		bool is_group;
3514de3fd5fab51 Steve French       2016-10-13  365  
3514de3fd5fab51 Steve French       2016-10-13  366  		if (sidtype != SIDOWNER)
3514de3fd5fab51 Steve French       2016-10-13  367  			is_group = true;
3514de3fd5fab51 Steve French       2016-10-13  368  		else
3514de3fd5fab51 Steve French       2016-10-13  369  			is_group = false;
3514de3fd5fab51 Steve French       2016-10-13  370  
3514de3fd5fab51 Steve French       2016-10-13  371  		if (is_well_known_sid(psid, &unix_id, is_group) == false)
3514de3fd5fab51 Steve French       2016-10-13  372  			goto try_upcall_to_get_id;
3514de3fd5fab51 Steve French       2016-10-13  373  
3514de3fd5fab51 Steve French       2016-10-13  374  		if (is_group) {
3514de3fd5fab51 Steve French       2016-10-13  375  			kgid_t gid;
3514de3fd5fab51 Steve French       2016-10-13  376  			gid_t id;
3514de3fd5fab51 Steve French       2016-10-13  377  
3514de3fd5fab51 Steve French       2016-10-13  378  			id = (gid_t)unix_id;
3514de3fd5fab51 Steve French       2016-10-13  379  			gid = make_kgid(&init_user_ns, id);
3514de3fd5fab51 Steve French       2016-10-13  380  			if (gid_valid(gid)) {
3514de3fd5fab51 Steve French       2016-10-13  381  				fgid = gid;
3514de3fd5fab51 Steve French       2016-10-13  382  				goto got_valid_id;
3514de3fd5fab51 Steve French       2016-10-13  383  			}
3514de3fd5fab51 Steve French       2016-10-13  384  		} else {
3514de3fd5fab51 Steve French       2016-10-13  385  			kuid_t uid;
3514de3fd5fab51 Steve French       2016-10-13  386  			uid_t id;
3514de3fd5fab51 Steve French       2016-10-13  387  
3514de3fd5fab51 Steve French       2016-10-13  388  			id = (uid_t)unix_id;
3514de3fd5fab51 Steve French       2016-10-13  389  			uid = make_kuid(&init_user_ns, id);
3514de3fd5fab51 Steve French       2016-10-13 @390  			if (uid_valid(uid)) {
3514de3fd5fab51 Steve French       2016-10-13  391  				fuid = uid;
3514de3fd5fab51 Steve French       2016-10-13  392  				goto got_valid_id;
3514de3fd5fab51 Steve French       2016-10-13  393  			}
3514de3fd5fab51 Steve French       2016-10-13  394  		}
3514de3fd5fab51 Steve French       2016-10-13  395  		/* If unable to find uid/gid easily from SID try via upcall */
3514de3fd5fab51 Steve French       2016-10-13  396  	}
3514de3fd5fab51 Steve French       2016-10-13  397  
3514de3fd5fab51 Steve French       2016-10-13  398  try_upcall_to_get_id:
faa65f07d21e7d3 Jeff Layton        2012-12-03  399  	sidstr = sid_to_key_str(psid, sidtype);
faa65f07d21e7d3 Jeff Layton        2012-12-03  400  	if (!sidstr)
faa65f07d21e7d3 Jeff Layton        2012-12-03  401  		return -ENOMEM;
faa65f07d21e7d3 Jeff Layton        2012-12-03  402  
9c70b12d1885d23 Qiujun Huang       2020-03-03  403  	rc = 0;
faa65f07d21e7d3 Jeff Layton        2012-12-03  404  	saved_cred = override_creds(root_cred);
028db3e290f15ac Linus Torvalds     2019-07-10  405  	sidkey = request_key(&cifs_idmap_key_type, sidstr, "");
faa65f07d21e7d3 Jeff Layton        2012-12-03  406  	if (IS_ERR(sidkey)) {
faa65f07d21e7d3 Jeff Layton        2012-12-03  407  		rc = -EINVAL;
f96637be081141d Joe Perches        2013-05-04  408  		cifs_dbg(FYI, "%s: Can't map SID %s to a %cid\n",
f96637be081141d Joe Perches        2013-05-04  409  			 __func__, sidstr, sidtype == SIDOWNER ? 'u' : 'g');
faa65f07d21e7d3 Jeff Layton        2012-12-03  410  		goto out_revert_creds;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  411  	}
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  412  
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  413  	/*
faa65f07d21e7d3 Jeff Layton        2012-12-03  414  	 * FIXME: Here we assume that uid_t and gid_t are same size. It's
faa65f07d21e7d3 Jeff Layton        2012-12-03  415  	 * probably a safe assumption but might be better to check based on
faa65f07d21e7d3 Jeff Layton        2012-12-03  416  	 * sidtype.
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  417  	 */
355958f2893d973 Eric W. Biederman  2013-02-06  418  	BUILD_BUG_ON(sizeof(uid_t) != sizeof(gid_t));
41a9f1f6b38664f Jeff Layton        2012-12-03  419  	if (sidkey->datalen != sizeof(uid_t)) {
faa65f07d21e7d3 Jeff Layton        2012-12-03  420  		rc = -EIO;
f96637be081141d Joe Perches        2013-05-04  421  		cifs_dbg(FYI, "%s: Downcall contained malformed key (datalen=%hu)\n",
f96637be081141d Joe Perches        2013-05-04  422  			 __func__, sidkey->datalen);
2ae03025d520de5 Jeff Layton        2012-12-03  423  		key_invalidate(sidkey);
faa65f07d21e7d3 Jeff Layton        2012-12-03  424  		goto out_key_put;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  425  	}
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  426  
8abf2775dd425ec Eric W. Biederman  2013-02-06  427  	if (sidtype == SIDOWNER) {
8abf2775dd425ec Eric W. Biederman  2013-02-06  428  		kuid_t uid;
8abf2775dd425ec Eric W. Biederman  2013-02-06  429  		uid_t id;
146aa8b1453bd8f David Howells      2015-10-21  430  		memcpy(&id, &sidkey->payload.data[0], sizeof(uid_t));
8abf2775dd425ec Eric W. Biederman  2013-02-06  431  		uid = make_kuid(&init_user_ns, id);
8abf2775dd425ec Eric W. Biederman  2013-02-06  432  		if (uid_valid(uid))
8abf2775dd425ec Eric W. Biederman  2013-02-06  433  			fuid = uid;
8abf2775dd425ec Eric W. Biederman  2013-02-06  434  	} else {
8abf2775dd425ec Eric W. Biederman  2013-02-06  435  		kgid_t gid;
8abf2775dd425ec Eric W. Biederman  2013-02-06  436  		gid_t id;
146aa8b1453bd8f David Howells      2015-10-21  437  		memcpy(&id, &sidkey->payload.data[0], sizeof(gid_t));
8abf2775dd425ec Eric W. Biederman  2013-02-06  438  		gid = make_kgid(&init_user_ns, id);
8abf2775dd425ec Eric W. Biederman  2013-02-06  439  		if (gid_valid(gid))
8abf2775dd425ec Eric W. Biederman  2013-02-06  440  			fgid = gid;
8abf2775dd425ec Eric W. Biederman  2013-02-06  441  	}
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  442  
faa65f07d21e7d3 Jeff Layton        2012-12-03  443  out_key_put:
faa65f07d21e7d3 Jeff Layton        2012-12-03  444  	key_put(sidkey);
faa65f07d21e7d3 Jeff Layton        2012-12-03  445  out_revert_creds:
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  446  	revert_creds(saved_cred);
faa65f07d21e7d3 Jeff Layton        2012-12-03  447  	kfree(sidstr);
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  448  
faa65f07d21e7d3 Jeff Layton        2012-12-03  449  	/*
faa65f07d21e7d3 Jeff Layton        2012-12-03  450  	 * Note that we return 0 here unconditionally. If the mapping
faa65f07d21e7d3 Jeff Layton        2012-12-03  451  	 * fails then we just fall back to using the mnt_uid/mnt_gid.
faa65f07d21e7d3 Jeff Layton        2012-12-03  452  	 */
3514de3fd5fab51 Steve French       2016-10-13  453  got_valid_id:
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  454  	if (sidtype == SIDOWNER)
faa65f07d21e7d3 Jeff Layton        2012-12-03  455  		fattr->cf_uid = fuid;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  456  	else
faa65f07d21e7d3 Jeff Layton        2012-12-03  457  		fattr->cf_gid = fgid;
9c70b12d1885d23 Qiujun Huang       2020-03-03  458  	return rc;
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  459  }
9409ae58e0759d0 Shirish Pargaonkar 2011-04-22  460  

:::::: The code at line 390 was first introduced by commit
:::::: 3514de3fd5fab518520e393152d3f4e3d0441d8d CIFS: Retrieve uid and gid from special sid if enabled

:::::: TO: Steve French <[email protected]>
:::::: CC: Steve French <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org