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: <20210427170753.GA1786245@cisco>
Date:   Tue, 27 Apr 2021 11:07:53 -0600
From:   Tycho Andersen <tycho@...ho.pizza>
To:     Andy Lutomirski <luto@...nel.org>
Cc:     Sargun Dhillon <sargun@...gun.me>,
        Kees Cook <keescook@...omium.org>,
        LKML <linux-kernel@...r.kernel.org>,
        Linux Containers <containers@...ts.linux-foundation.org>,
        Rodrigo Campos <rodrigo@...volk.io>,
        Christian Brauner <christian.brauner@...ntu.com>,
        Mauricio Vásquez Bernal 
        <mauricio@...volk.io>, Giuseppe Scrivano <gscrivan@...hat.com>,
        Will Drewry <wad@...omium.org>, Alban Crequy <alban@...volk.io>
Subject: Re: [PATCH RESEND 2/5] seccomp: Add wait_killable semantic to
 seccomp user notifier

On Tue, Apr 27, 2021 at 09:23:42AM -0700, Andy Lutomirski wrote:
> On Tue, Apr 27, 2021 at 6:48 AM Tycho Andersen <tycho@...ho.pizza> wrote:
> >
> > On Mon, Apr 26, 2021 at 10:15:28PM +0000, Sargun Dhillon wrote:
> > > On Mon, Apr 26, 2021 at 01:02:29PM -0600, Tycho Andersen wrote:
> > > > On Mon, Apr 26, 2021 at 11:06:07AM -0700, Sargun Dhillon wrote:
> > > > > @@ -1103,11 +1111,31 @@ static int seccomp_do_user_notification(int this_syscall,
> > > > >    * This is where we wait for a reply from userspace.
> > > > >    */
> > > > >   do {
> > > > > +         interruptible = notification_interruptible(&n);
> > > > > +
> > > > >           mutex_unlock(&match->notify_lock);
> > > > > -         err = wait_for_completion_interruptible(&n.ready);
> > > > > +         if (interruptible)
> > > > > +                 err = wait_for_completion_interruptible(&n.ready);
> > > > > +         else
> > > > > +                 err = wait_for_completion_killable(&n.ready);
> > > > >           mutex_lock(&match->notify_lock);
> > > > > -         if (err != 0)
> > > > > +
> > > > > +         if (err != 0) {
> > > > > +                 /*
> > > > > +                  * There is a race condition here where if the
> > > > > +                  * notification was received with the
> > > > > +                  * SECCOMP_USER_NOTIF_FLAG_WAIT_KILLABLE flag, but a
> > > > > +                  * non-fatal signal was received before we could
> > > > > +                  * transition we could erroneously end our wait early.
> > > > > +                  *
> > > > > +                  * The next wait for completion will ensure the signal
> > > > > +                  * was not fatal.
> > > > > +                  */
> > > > > +                 if (interruptible && !notification_interruptible(&n))
> > > > > +                         continue;
> > > >
> > > > I'm trying to understand how one would hit this race,
> > > >
> > >
> > > I'm thinking:
> > > P: Process that "generates" notification
> > > S: Supervisor
> > > U: User
> > >
> > > P: Generated notification
> > > S: ioctl(RECV...) // With wait_killable flag.
> > > ...complete is called in the supervisor, but the P may not be woken up...
> > > U: kill -SIGTERM $P
> > > ...signal gets delivered to p and causes wakeup and
> > > wait_for_completion_interruptible returns 1...
> > >
> > > Then you need to check the race
> >
> > I see, thanks. This seems like a consequence of having the flag be
> > per-RECV-call vs. per-filter. Seems like it might be simpler to have
> > it be per-filter?
> >
> 
> Backing up a minute, how is the current behavior not a serious
> correctness issue?  I can think of two scenarios that seem entirely
> broken right now:
> 
> 1. Process makes a syscall that is not permitted to return -EINTR.  It
> gets a signal and returns -EINTR when user notifiers are in use.
> 
> 2. Process makes a syscall that is permitted to return -EINTR.  But
> -EINTR for IO means "I got interrupted and *did not do the IO*".
> Nevertheless, the syscall returns -EINTR and the IO is done.
> 
> ISTM the current behavior is severely broken, and the new behavior
> isn't *that* much better since it simply ignores signals and can't
> emulate -EINTR (or all the various restart modes, sigh).  Surely the
> right behavior is to have the seccomped process notice that it got a
> signal and inform the monitor of that fact so that the monitor can
> take appropriate action.

This doesn't help your case (2) though, since the IO could be done
before the supervisor gets the notification.

> IOW, I don't think that the current behavior *or* the patched opt-in
> behavior is great.  I think we would do better to have the filter
> indicate that it is signal-aware and to document that non-signal-aware
> filters cannot behave correctly with respect to signals.

I think it would be hard to make a signal-aware filter, it really does
feel like the only thing to do is a killable wait.

Tycho

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ