Skip to contentSkip to conversation

nfsd: silence sparse warning about accessing credentials

PATCH In review Jeff Layton 3 participants 3 messages Jul 15, 2014

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

PATCH 1/1 nfsd: silence sparse warning about accessing credentials

sparse says:

fs/nfsd/auth.c:31:38: warning: incorrect type in argument 1 (different address spaces)
fs/nfsd/auth.c:31:38: expected struct cred const *cred
fs/nfsd/auth.c:31:38: got struct cred const [noderef] <asn:4>*real_cred

Add a new accessor for the ->real_cred and use that to fetch the pointer. Accessing current->real_cred directly is actually quite safe since we know that they can't go away so this is mostly a cosmetic fixup to silence sparse.

---
 fs/nfsd/auth.c       | 2 +-
 include/linux/cred.h | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)
fs/nfsd/auth.c +1 -1
index 72f44823adbb..9d46a0bdd9f9 100644
@@ -28,7 +28,7 @@ int nfsd_setuser(struct svc_rqst *rqstp, struct svc_export *exp)
 	validate_process_creds();
 
 	/* discard any old override before preparing the new set */
-	revert_creds(get_cred(current->real_cred));
+	revert_creds(get_cred(current_real_cred()));
 	new = prepare_creds();
 	if (!new)
 		return -ENOMEM;
include/linux/cred.h +9 -0
index f61d6c8f5ef3..b2d0820837c4 100644
@@ -259,6 +259,15 @@ static inline void put_cred(const struct cred *_cred)
 	rcu_dereference_protected(current->cred, 1)
 
 /**
+ * current_real_cred - Access the current task's objective credentials
+ *
+ * Access the objective credentials of the current task.  RCU-safe,
+ * since nobody else can modify it.
+ */
+#define current_real_cred() \
+	rcu_dereference_protected(current->real_cred, 1)
+
+/**
  * __task_cred - Access a task's objective credentials
  * @task: The task to query
  *
Signature · 1 line
1.9.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jeff Layton

sparse says:

fs/nfsd/auth.c:31:38: warning: incorrect type in argument 1 (different address spaces)
fs/nfsd/auth.c:31:38: expected struct cred const *cred
fs/nfsd/auth.c:31:38: got struct cred const [noderef] <asn:4>*real_cred

Add a new accessor for the ->real_cred and use that to fetch the pointer. Accessing current->real_cred directly is actually quite safe since we know that they can't go away so this is mostly a cosmetic fixup to silence sparse.

This looks reasonable, but I'd suggest Ccing linux-kernel for changes to global headers.

#2 lore raw
Quoted 12 lines · On Tue, 15 Jul 2014 09:45:27 -0700 Christoph Hellwig <[email protected]> wrote:
Quoted 10 lines · Jeff Layton

sparse says:

fs/nfsd/auth.c:31:38: warning: incorrect type in argument 1 (different address spaces)
fs/nfsd/auth.c:31:38: expected struct cred const *cred
fs/nfsd/auth.c:31:38: got struct cred const [noderef] <asn:4>*real_cred

Add a new accessor for the ->real_cred and use that to fetch the pointer. Accessing current->real_cred directly is actually quite safe since we know that they can't go away so this is mostly a cosmetic fixup to silence sparse.

Quoted 4 lines

This looks reasonable, but I'd suggest Ccing linux-kernel for changes to global headers.

Ok, good point. I'll resend and cc there.

FWIW, I also sent a patch to linux-sparse today which will silence the last sparse warning when building nfsd.ko.

Thanks,

Signature · 1 line
Jeff Layton <[email protected]>