lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240207-vibrieren-waldarbeiten-30eeade05203@brauner>
Date: Wed, 7 Feb 2024 10:15:21 +0100
From: Christian Brauner <brauner@...nel.org>
To: Tycho Andersen <tycho@...ho.pizza>
Cc: Oleg Nesterov <oleg@...hat.com>, 
	"Eric W . Biederman" <ebiederm@...ssion.com>, linux-kernel@...r.kernel.org, linux-api@...r.kernel.org, 
	Tycho Andersen <tandersen@...flix.com>
Subject: Re: [PATCH v2] pidfd: getfd should always report ESRCH if a task is
 exiting

On Tue, Feb 06, 2024 at 12:23:57PM -0700, Tycho Andersen wrote:
> From: Tycho Andersen <tandersen@...flix.com>
> 
> We can get EBADF from __pidfd_fget() if a task is currently exiting, which
> might be confusing. Let's check PF_EXITING, and just report ESRCH if so.
> 
> I chose PF_EXITING, because it is set in exit_signals(), which is called
> before exit_files(). Since ->exit_status is mostly set after exit_files()
> in exit_notify(), using that still leaves a window open for the race.
> 
> Signed-off-by: Tycho Andersen <tandersen@...flix.com>
> v2: fix a race in the check by putting the check after __pidfd_fget()
>     (thanks Oleg)
> ---
>  kernel/pid.c                                  | 17 +++++++++-
>  .../selftests/pidfd/pidfd_getfd_test.c        | 31 ++++++++++++++++++-
>  2 files changed, 46 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/pid.c b/kernel/pid.c
> index de0bf2f8d18b..a8cd6296ed6d 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -693,8 +693,23 @@ static int pidfd_getfd(struct pid *pid, int fd)
>  
>  	file = __pidfd_fget(task, fd);
>  	put_task_struct(task);
> -	if (IS_ERR(file))
> +	if (IS_ERR(file)) {
> +		/*
> +		 * It is possible that the target thread is exiting; it can be
> +		 * either:
> +		 * 1. before exit_signals(), which gives a real fd
> +		 * 2. before exit_files() takes the task_lock() gives a real fd
> +		 * 3. after exit_files() releases task_lock(), ->files is NULL;
> +		 *    this has PF_EXITING, since it was set in exit_signals(),
> +		 *    __pidfd_fget() returns EBADF.
> +		 * In case 3 we get EBADF, but that really means ESRCH, since
> +		 * the task is currently exiting and has freed its files
> +		 * struct, so we fix it up.
> +		 */
> +		if (task->flags & PF_EXITING && PTR_ERR(file) == -EBADF)
> +			return -ESRCH;

Isn't that a potential UAF because we called put_task_struct() above but
this is exiting task->flags afterwards?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ