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
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.
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: NeilBrown <[email protected]>
---
net/sunrpc/auth_unix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index 387f6b3ffbea..770e338a9b11 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -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;
--
2.14.0.rc0.dirty
On Mon, 2019-01-07 at 17:53 +1100, NeilBrown wrote:
> 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.
>
> Reported-by: Dan Carpenter <[email protected]>
> Signed-off-by: NeilBrown <[email protected]>
>
Thanks Neil! Applied to the linux-next branch for inclusion in the 5.1
merge window.
--
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]