public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Paul Moore <paul@paul-moore.com>,
	James Morris <jmorris@namei.org>,
	"Serge E. Hallyn" <serge@hallyn.com>,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] yama: don't abuse rcu_read_lock/get_task_struct in yama_task_prctl()
Date: Wed, 19 Feb 2025 11:33:12 -0800	[thread overview]
Message-ID: <202502191125.1A6F07E@keescook> (raw)
In-Reply-To: <20250219161417.GA20851@redhat.com>

On Wed, Feb 19, 2025 at 05:14:17PM +0100, Oleg Nesterov wrote:
> current->group_leader is stable, no need to take rcu_read_lock() and do
> get/put_task_struct().

Can you explain why this is true? In trying to figure this out again,
it seems that the only way current->group_leader can vanish is if
the entire process vanishes (fork or thread exec), in which case the
"current" in this prctl can't be happening; this appears to be locked
behind tsk->sighand->siglock ?

-Kees

> 
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
>  security/yama/yama_lsm.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
> 
> diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
> index 1971710620c1..3d064dd4e03f 100644
> --- a/security/yama/yama_lsm.c
> +++ b/security/yama/yama_lsm.c
> @@ -222,7 +222,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
>  			   unsigned long arg4, unsigned long arg5)
>  {
>  	int rc = -ENOSYS;
> -	struct task_struct *myself = current;
> +	struct task_struct *myself;
>  
>  	switch (option) {
>  	case PR_SET_PTRACER:
> @@ -232,11 +232,7 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
>  		 * leader checking is handled later when walking the ancestry
>  		 * at the time of PTRACE_ATTACH check.
>  		 */
> -		rcu_read_lock();
> -		if (!thread_group_leader(myself))
> -			myself = rcu_dereference(myself->group_leader);
> -		get_task_struct(myself);
> -		rcu_read_unlock();
> +		myself = current->group_leader;
>  
>  		if (arg2 == 0) {
>  			yama_ptracer_del(NULL, myself);
> @@ -255,7 +251,6 @@ static int yama_task_prctl(int option, unsigned long arg2, unsigned long arg3,
>  			}
>  		}
>  
> -		put_task_struct(myself);
>  		break;
>  	}
>  
> -- 
> 2.25.1.362.g51ebf55
> 
> 

-- 
Kees Cook

  reply	other threads:[~2025-02-19 19:33 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-19 16:14 [PATCH] yama: don't abuse rcu_read_lock/get_task_struct in yama_task_prctl() Oleg Nesterov
2025-02-19 19:33 ` Kees Cook [this message]
2025-02-19 20:17   ` Oleg Nesterov
2025-02-19 21:00     ` Oleg Nesterov
2025-02-19 21:42       ` Oleg Nesterov
2025-03-04 23:53 ` Kees Cook

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=202502191125.1A6F07E@keescook \
    --to=kees@kernel.org \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    /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