public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: David Howells <dhowells@redhat.com>
Cc: torvalds@osdl.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org,
	Jiri Olsa <jolsa@redhat.com>
Subject: Re: [PATCH 2/2] CRED: Fix __task_cred()'s lockdep check and banner comment
Date: Mon, 2 Aug 2010 13:40:00 -0700	[thread overview]
Message-ID: <20100802204000.GH2405@linux.vnet.ibm.com> (raw)
In-Reply-To: <20100729114555.29508.4525.stgit@warthog.procyon.org.uk>

On Thu, Jul 29, 2010 at 12:45:55PM +0100, David Howells wrote:
> Fix __task_cred()'s lockdep check by removing the following validation
> condition:
> 
> 	lockdep_tasklist_lock_is_held()
> 
> as commit_creds() does not take the tasklist_lock, and nor do most of the
> functions that call it, so this check is pointless and it can prevent
> detection of the RCU lock not being held if the tasklist_lock is held.
> 
> Instead, add the following validation condition:
> 
> 	task->exit_state >= 0
> 
> to permit the access if the target task is dead and therefore unable to change
> its own credentials.
> 
> 
> Fix __task_cred()'s comment to:
> 
>  (1) discard the bit that says that the caller must prevent the target task
>      from being deleted.  That shouldn't need saying.
> 
>  (2) Add a comment indicating the result of __task_cred() should not be passed
>      directly to get_cred(), but rather than get_task_cred() should be used
>      instead.
> 
> Also put a note into the documentation to enforce this point there too.

Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

> Signed-off-by: David Howells <dhowells@redhat.com>
> Acked-by: Jiri Olsa <jolsa@redhat.com>
> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
> ---
> 
>  Documentation/credentials.txt |    3 +++
>  include/linux/cred.h          |   15 ++++++++++-----
>  include/linux/sched.h         |    1 +
>  3 files changed, 14 insertions(+), 5 deletions(-)
> 
> diff --git a/Documentation/credentials.txt b/Documentation/credentials.txt
> index a2db352..995baf3 100644
> --- a/Documentation/credentials.txt
> +++ b/Documentation/credentials.txt
> @@ -417,6 +417,9 @@ reference on them using:
>  This does all the RCU magic inside of it.  The caller must call put_cred() on
>  the credentials so obtained when they're finished with.
> 
> + [*] Note: The result of __task_cred() should not be passed directly to
> +     get_cred() as this may race with commit_cred().
> +
>  There are a couple of convenience functions to access bits of another task's
>  credentials, hiding the RCU magic from the caller:
> 
> diff --git a/include/linux/cred.h b/include/linux/cred.h
> index ce40cbc..4d2c395 100644
> --- a/include/linux/cred.h
> +++ b/include/linux/cred.h
> @@ -274,13 +274,18 @@ static inline void put_cred(const struct cred *_cred)
>   * @task: The task to query
>   *
>   * Access the objective credentials of a task.  The caller must hold the RCU
> - * readlock.
> + * readlock or the task must be dead and unable to change its own credentials.
>   *
> - * The caller must make sure task doesn't go away, either by holding a ref on
> - * task or by holding tasklist_lock to prevent it from being unlinked.
> + * The result of this function should not be passed directly to get_cred();
> + * rather get_task_cred() should be used instead.
>   */
> -#define __task_cred(task) \
> -	((const struct cred *)(rcu_dereference_check((task)->real_cred, rcu_read_lock_held() || lockdep_tasklist_lock_is_held())))
> +#define __task_cred(task)						\
> +	({								\
> +		const struct task_struct *__t = (task);			\
> +		rcu_dereference_check(__t->real_cred,			\
> +				      rcu_read_lock_held() ||		\
> +				      task_is_dead(__t));		\
> +	})
> 
>  /**
>   * get_current_cred - Get the current task's subjective credentials
> diff --git a/include/linux/sched.h b/include/linux/sched.h
> index 747fcae..0478888 100644
> --- a/include/linux/sched.h
> +++ b/include/linux/sched.h
> @@ -214,6 +214,7 @@ extern char ___assert_task_state[1 - 2*!!(
> 
>  #define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
>  #define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
> +#define task_is_dead(task)	((task)->exit_state != 0)
>  #define task_is_stopped_or_traced(task)	\
>  			((task->state & (__TASK_STOPPED | __TASK_TRACED)) != 0)
>  #define task_contributes_to_load(task)	\
> 

  reply	other threads:[~2010-08-02 20:40 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-29 11:45 [PATCH 1/2] CRED: Fix get_task_cred() and task_state() to not resurrect dead credentials David Howells
2010-07-29 11:45 ` [PATCH 2/2] CRED: Fix __task_cred()'s lockdep check and banner comment David Howells
2010-08-02 20:40   ` Paul E. McKenney [this message]
2010-08-03  0:55     ` Tetsuo Handa
2010-08-03  9:34       ` David Howells
2010-08-03 16:07         ` Linus Torvalds
2010-08-03 17:48           ` Thomas Gleixner
2010-08-04 13:17           ` Oleg Nesterov
2010-08-04 14:01             ` David Howells
2010-08-04 15:08               ` Oleg Nesterov
2010-08-04 15:22                 ` David Howells
2010-08-04 15:44                   ` Oleg Nesterov
2010-08-05  7:19           ` Eric W. Biederman
2010-08-05 16:14             ` Linus Torvalds
2010-08-05 18:16               ` Oleg Nesterov
2010-08-05 20:13               ` Eric W. Biederman
2010-08-05 20:26                 ` Linus Torvalds
2010-08-05 21:20                   ` Eric W. Biederman
2010-08-04  0:38         ` Tetsuo Handa

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=20100802204000.GH2405@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=torvalds@osdl.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox