Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Mon, 30 Sep 2019 22:55:43 -0400
From: Rich Felker <dalias@...c.org>
To: Joshua Hudson <joshudson@...il.com>
Cc: musl <musl@...ts.openwall.com>
Subject: Re: Re: posix_spawn

On Mon, Sep 30, 2019 at 07:41:32PM -0700, Joshua Hudson wrote:
> > > You now have a quirk and I need to actually detect musl libc.
> 
> > Huh? This does not sound musl-specific.
> 
> Musl seems to be the only library that actually implements vfork
> shared memory that can't tolerate calling setuid() inside it.

Oh, so you're still trying to do something that is documented as
invalid...

> This patch should take care of the issue.
> 
> diff --git a/src/thread/synccall.c b/src/thread/synccall.c
> index 648a6ad4..e152ccfe 100644
> --- a/src/thread/synccall.c
> +++ b/src/thread/synccall.c
> @@ -48,6 +48,9 @@ void __synccall(void (*func)(void *), void *ctx)
>         struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler };
>         pthread_t self = __pthread_self(), td;
>         int count = 0;
> +       /* If we aren't in the process we think we're in, this is the best we
> +         * can hope for. */
> +       if (__pthread_self()->tid != syscall(SYS_gettid)) goto single_threaded;
> 
>         /* Blocking signals in two steps, first only app-level signals
>          * before taking the lock, then all signals after taking the lock,

This is not safe and creates a false sense that something broken might
work. Moreover it's a vulnerability to use it this way. You have a
window where different tasks sharing VM space are executing with
different privilege levels, and thereby one is able to seize execution
of the other and achieve its privilege level. This is the whole
situation that the robust multithreaded set*id() is designed to
preclude.

A better patch here would be:

+	if (__pthread_self()->tid != syscall(SYS_gettid)) a_crash();

to prevent forward progress in a process with dangerously corrupt
state.

Rich

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.