All of lore.kernel.org
 help / color / mirror / Atom feed
From: Al Viro <viro-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
To: Steve French <smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: LKML <linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
	linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: new sparse warning fs/cifs/cifsfs.c:168:15: warning: dereference of noderef expression fs/cifs/cifsfs.c:542:15: warning: dereference of noderef expression
Date: Sun, 7 Aug 2011 18:48:29 +0100	[thread overview]
Message-ID: <20110807174829.GY2203@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CAH2r5mszsiu2Gm-DPbfT8UReT=eBTf4Du4eyEapG8Ayn7UN1pw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

On Sun, Aug 07, 2011 at 11:22:51AM -0500, Steve French wrote:
> I noticed a series of sparse warnings (on all calls to cifs's GetXid
> after building on a newly install fc15 system (yum installed a sparse
> binary dated June 23).
> 
> fs/cifs/cifsfs.c:168:15: warning: dereference of noderef expression
> fs/cifs/cifsfs.c:542:15: warning: dereference of noderef expression
> 
> Has sparse changed to add a new warning - I see (from quick search)
> others getting this on other modules years ago, but I didn't see
> anything obvious wrong with the definition of the function, and I
> hadn't noticed sparse complaining about it before, and would like to
> remove the 50+ new messages as they clutter the build output.

It's not sparse change - the whinge comes from current_fsuid(), i.e. direct
read of current->cred, even though it's declared with __rcu.  The thing is,
current->cred does *not* need rcu_dereference() - only the task itself
can change it.  Easily fixed...

Signed-off-by: Al Viro <viro-RmSDqhL/yNMiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
---
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 48e82af..98f46ef 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -265,10 +265,11 @@ static inline void put_cred(const struct cred *_cred)
 /**
  * current_cred - Access the current task's subjective credentials
  *
- * Access the subjective credentials of the current task.
+ * Access the subjective credentials of the current task.  RCU-safe,
+ * since nobody else can modify it.
  */
 #define current_cred() \
-	(current->cred)
+	(*(__force struct cred **)&current->cred)
 
 /**
  * __task_cred - Access a task's objective credentials
@@ -307,7 +308,7 @@ static inline void put_cred(const struct cred *_cred)
 ({							\
 	struct user_struct *__u;			\
 	struct cred *__cred;				\
-	__cred = (struct cred *) current_cred();	\
+	__cred = current_cred();			\
 	__u = get_uid(__cred->user);			\
 	__u;						\
 })
@@ -322,7 +323,7 @@ static inline void put_cred(const struct cred *_cred)
 ({							\
 	struct group_info *__groups;			\
 	struct cred *__cred;				\
-	__cred = (struct cred *) current_cred();	\
+	__cred = current_cred();			\
 	__groups = get_group_info(__cred->group_info);	\
 	__groups;					\
 })
@@ -341,7 +342,7 @@ static inline void put_cred(const struct cred *_cred)
 
 #define current_cred_xxx(xxx)			\
 ({						\
-	current->cred->xxx;			\
+	current_cred()->xxx;			\
 })
 
 #define current_uid()		(current_cred_xxx(uid))

WARNING: multiple messages have this Message-ID (diff)
From: Al Viro <viro@ZenIV.linux.org.uk>
To: Steve French <smfrench@gmail.com>
Cc: LKML <linux-kernel@vger.kernel.org>, linux-cifs@vger.kernel.org
Subject: Re: new sparse warning fs/cifs/cifsfs.c:168:15: warning: dereference of noderef expression fs/cifs/cifsfs.c:542:15: warning: dereference of noderef expression
Date: Sun, 7 Aug 2011 18:48:29 +0100	[thread overview]
Message-ID: <20110807174829.GY2203@ZenIV.linux.org.uk> (raw)
In-Reply-To: <CAH2r5mszsiu2Gm-DPbfT8UReT=eBTf4Du4eyEapG8Ayn7UN1pw@mail.gmail.com>

On Sun, Aug 07, 2011 at 11:22:51AM -0500, Steve French wrote:
> I noticed a series of sparse warnings (on all calls to cifs's GetXid
> after building on a newly install fc15 system (yum installed a sparse
> binary dated June 23).
> 
> fs/cifs/cifsfs.c:168:15: warning: dereference of noderef expression
> fs/cifs/cifsfs.c:542:15: warning: dereference of noderef expression
> 
> Has sparse changed to add a new warning - I see (from quick search)
> others getting this on other modules years ago, but I didn't see
> anything obvious wrong with the definition of the function, and I
> hadn't noticed sparse complaining about it before, and would like to
> remove the 50+ new messages as they clutter the build output.

It's not sparse change - the whinge comes from current_fsuid(), i.e. direct
read of current->cred, even though it's declared with __rcu.  The thing is,
current->cred does *not* need rcu_dereference() - only the task itself
can change it.  Easily fixed...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
---
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 48e82af..98f46ef 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -265,10 +265,11 @@ static inline void put_cred(const struct cred *_cred)
 /**
  * current_cred - Access the current task's subjective credentials
  *
- * Access the subjective credentials of the current task.
+ * Access the subjective credentials of the current task.  RCU-safe,
+ * since nobody else can modify it.
  */
 #define current_cred() \
-	(current->cred)
+	(*(__force struct cred **)&current->cred)
 
 /**
  * __task_cred - Access a task's objective credentials
@@ -307,7 +308,7 @@ static inline void put_cred(const struct cred *_cred)
 ({							\
 	struct user_struct *__u;			\
 	struct cred *__cred;				\
-	__cred = (struct cred *) current_cred();	\
+	__cred = current_cred();			\
 	__u = get_uid(__cred->user);			\
 	__u;						\
 })
@@ -322,7 +323,7 @@ static inline void put_cred(const struct cred *_cred)
 ({							\
 	struct group_info *__groups;			\
 	struct cred *__cred;				\
-	__cred = (struct cred *) current_cred();	\
+	__cred = current_cred();			\
 	__groups = get_group_info(__cred->group_info);	\
 	__groups;					\
 })
@@ -341,7 +342,7 @@ static inline void put_cred(const struct cred *_cred)
 
 #define current_cred_xxx(xxx)			\
 ({						\
-	current->cred->xxx;			\
+	current_cred()->xxx;			\
 })
 
 #define current_uid()		(current_cred_xxx(uid))

  parent reply	other threads:[~2011-08-07 17:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-07 16:22 new sparse warning fs/cifs/cifsfs.c:168:15: warning: dereference of noderef expression fs/cifs/cifsfs.c:542:15: warning: dereference of noderef expression Steve French
2011-08-07 16:22 ` Steve French
     [not found] ` <CAH2r5mszsiu2Gm-DPbfT8UReT=eBTf4Du4eyEapG8Ayn7UN1pw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2011-08-07 17:48   ` Al Viro [this message]
2011-08-07 17:48     ` Al Viro
     [not found]     ` <20110807174829.GY2203-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org>
2011-08-07 19:32       ` Steve French
2011-08-07 19:32         ` Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110807174829.GY2203@ZenIV.linux.org.uk \
    --to=viro-3bdd1+5odreifsdqtta3olvcufugdwfn@public.gmane.org \
    --cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.