Skip to contentSkip to conversation

SUNRPC: simplify auth_unix.

bug report In review Dan Carpenter 3 participants 3 messages Dec 21, 2018 – Feb 21, 2019

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

Hello NeilBrown,

This is a semi-automatic email about new static checker warnings.

The patch 394f319df78e: "SUNRPC: simplify auth_unix." from Dec 3, 2018, leads to the following Smatch complaint:

    net/sunrpc/auth_unix.c:90 unx_match()
    warn: variable dereferenced before check 'acred->cred' (see line 87)

net/sunrpc/auth_unix.c

    86	
    87		if (!uid_eq(cred->cr_cred->fsuid, acred->cred->fsuid) || !gid_eq(cred->cr_cred->fsgid, acred->cred->fsgid))
                                                  ^^^^^^^^^^^

New dereference

    88			return 0;
    89	
    90		if (acred->cred && acred->cred->group_info != NULL)
                    ^^^^^^^^^^^

But the old code checked for NULL

    91			groups = acred->cred->group_info->ngroups;
    92		if (groups > UNX_NGROUPS)

regards,
dan carpenter

#1 lore raw

PATCH 1/1 SUNRPC: remove pointless test in unx_match()

As reported by Dan Carpenter, this test for acred->cred being set is inconsistent with the dereference of the pointer a few lines earlier.

An 'auth_cred' *always* has ->cred set - every place that creates one initializes this field, often as the first thing done.

So remove this test.

---
 net/sunrpc/auth_unix.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/sunrpc/auth_unix.c +1 -1
index 387f6b3ffbea..770e338a9b11 100644
@@ -87,7 +87,7 @@ unx_match(struct auth_cred *acred, struct rpc_cred *cred, int flags)
 	if (!uid_eq(cred->cr_cred->fsuid, acred->cred->fsuid) || !gid_eq(cred->cr_cred->fsgid, acred->cred->fsgid))
 		return 0;
 
-	if (acred->cred && acred->cred->group_info != NULL)
+	if (acred->cred->group_info != NULL)
 		groups = acred->cred->group_info->ngroups;
 	if (groups > UNX_NGROUPS)
 		groups = UNX_NGROUPS;
Signature · 1 line
2.14.0.rc0.dirty
#2 lore raw

Re: [PATCH] SUNRPC: remove pointless test in unx_match()

Quoted 11 lines · NeilBrown

As reported by Dan Carpenter, this test for acred->cred being set is inconsistent with the dereference of the pointer a few lines earlier.

An 'auth_cred' *always* has ->cred set - every place that creates one initializes this field, often as the first thing done.

So remove this test.

Thanks Neil! Applied to the linux-next branch for inclusion in the 5.1 merge window.

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]