Re: [PATCH v4] seccomp: add ptrace options for suspend/resume

From: Tycho Andersen
Date: Wed Jun 10 2015 - 11:19:11 EST


Hi Andy,

On Tue, Jun 09, 2015 at 06:08:42PM -0700, Andy Lutomirski wrote:
>
> > + if (unlikely(data & PTRACE_O_SUSPEND_SECCOMP)) {
> > + if (!config_enabled(CONFIG_CHECKPOINT_RESTORE) ||
> > + !config_enabled(CONFIG_SECCOMP))
> > + return -EINVAL;
> > +
> > + if (!capable(CAP_SYS_ADMIN))
> > + return -EPERM;
>
> I tend to think that we should also require that current not be using
> seccomp. Otherwise, in principle, there's a seccomp bypass for
> privileged-but-seccomped programs. In any event, CRIU isn't going to
> work well if you run the restorer under seccomp, since it'll start
> nesting in a manner that probably isn't desirable.

Ok, I can resend with that. (sorry Oleg :)

> > + }
> > +
> > /* Avoid intermediate state when all opts are cleared */
> > flags = child->ptrace;
> > flags &= ~(PTRACE_O_MASK << PT_OPT_FLAG_SHIFT);
> > diff --git a/kernel/seccomp.c b/kernel/seccomp.c
> > index 980fd26..645e42d 100644
> > --- a/kernel/seccomp.c
> > +++ b/kernel/seccomp.c
> > @@ -590,6 +590,10 @@ void secure_computing_strict(int this_syscall)
> > {
> > int mode = current->seccomp.mode;
> >
> > + if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&
> > + unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
> > + return;
> > +
> > if (mode == 0)
> > return;
> > else if (mode == SECCOMP_MODE_STRICT)
> > @@ -691,6 +695,10 @@ u32 seccomp_phase1(struct seccomp_data *sd)
> > int this_syscall = sd ? sd->nr :
> > syscall_get_nr(current, task_pt_regs(current));
> >
> > + if (config_enabled(CONFIG_CHECKPOINT_RESTORE) &&
> > + unlikely(current->ptrace & PT_SUSPEND_SECCOMP))
> > + return SECCOMP_PHASE1_OK;
> > +
>
> If it's not hard, it might still be nice to try to fold this into
> mode. This code is rather hot. If it would be a mess, then don't
> worry about it for now.

The part I'm not immediately clear on is what to do when the tracer
dies and the task is running. Oleg pointed out that we can't play with
TIF_SECCOMP (or we could, but restoring it in this case is
complicated), and I'm not sure if playing with ->seccomp.mode has any
similar complications. I /think/ it should be ok to just re-enable it,
but I'm not sure.

I'd like to leave this patch as is (modulo the extra check) for now.
I'm still looking at a way to export mode 2 filters, so there will
hopefully be more patches in this area soon and we can reexamine then.

Thanks for the review.

Tycho
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/