lkml.org 
[lkml]   [2021]   [Apr]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH RESEND 2/5] seccomp: Add wait_killable semantic to seccomp user notifier
On Tue, Apr 27, 2021 at 6:48 AM Tycho Andersen <tycho@tycho.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?
>
> Tycho

You're right.

I think an alternative solution would be to make it on a per-action
basis, and in the filter have a different action for non-preemptible
user notifications.

Since you can only install one filter, I do not think we want to make
it so we do it on a entire filter basis, in case a filter handles a combination
of preemptible and non-preemptible syscalls. For example if you mix
mount and accept.

\
 
 \ /
  Last update: 2021-04-27 18:35    [W:0.087 / U:1.240 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site