All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Tycho Andersen <tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Kees Cook <keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Andy Lutomirski <luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org>,
	Will Drewry <wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>,
	Roland McGrath <roland-/Z5OmTQCD9xF6kxbq+BtvQ@public.gmane.org>,
	Pavel Emelyanov <xemul-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>,
	"Serge E. Hallyn"
	<serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH] seccomp: add ptrace commands for suspend/resume
Date: Tue, 2 Jun 2015 20:28:29 +0200	[thread overview]
Message-ID: <20150602182829.GA23449@redhat.com> (raw)
In-Reply-To: <1433186918-9626-1-git-send-email-tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>

On 06/01, Tycho Andersen wrote:
>
> --- a/include/linux/seccomp.h
> +++ b/include/linux/seccomp.h
> @@ -25,6 +25,9 @@ struct seccomp_filter;
>  struct seccomp {
>  	int mode;
>  	struct seccomp_filter *filter;
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +	bool suspended;
> +#endif

Then afaics you need to change copy_seccomp() to clear ->suspended.
At least if the child is not traced.

> @@ -691,6 +697,11 @@ u32 seccomp_phase1(struct seccomp_data *sd)
>  	int this_syscall = sd ? sd->nr :
>  		syscall_get_nr(current, task_pt_regs(current));
>  
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +	if (unlikely(current->seccomp.suspended))
> +		return SECCOMP_PHASE1_OK;
> +#endif
> +

I am wondering if PTRACE_SUSPEND_SECCOMP can just clear/set TIF_SECCOMP.
Of course, it is not that resume_seccomp() can simply do set_tsk_thread_flag,
it should be more careful. And prctl_set_seccomp() paths will need some
changes. Probably not, this would be more complex.

So perhaps it would be better to add PTRACE_O_SUSPEND_SECCOMP? This also
solves the problem with the killed tracer. Except TIF_NOTSC...

But why do we bother to play with TIF_NOTSC, could you explain?

> +int suspend_seccomp(struct task_struct *task)
> +{
> +	int ret = -EACCES;
> +
> +	spin_lock_irq(&task->sighand->siglock);
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		goto out;

I am puzzled ;) Why do we need ->siglock? And even if we need it, why
we can't check CAP_SYS_ADMIN lockless?

And I am not sure I understand why do we need the additional security
check, but I leave this to you and Andy.

If you have the rights to trace this task, then you can do anything
the tracee could do without the filtering.

> +
> +	task->seccomp.suspended = true;
> +
> +#ifdef TIF_NOTSC
> +	if (task->seccomp.mode == SECCOMP_MODE_STRICT)
> +		clear_tsk_thread_flag(task, TIF_NOTSC);
> +#endif
> +
> +	ret = 0;
> +out:
> +	spin_unlock_irq(&task->sighand->siglock);
> +
> +	return ret;
> +}
> +
> +int resume_seccomp(struct task_struct *task)
> +{
> +	int ret = -EACCES;
> +
> +	spin_lock_irq(&task->sighand->siglock);
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		goto out;
> +
> +	task->seccomp.suspended = false;
> +
> +#ifdef TIF_NOTSC
> +	if (task->seccomp.mode == SECCOMP_MODE_STRICT)
> +		set_tsk_thread_flag(task, TIF_NOTSC);
> +#endif
> +
> +	ret = 0;
> +out:
> +	spin_unlock_irq(&task->sighand->siglock);
> +
> +	return ret;
> +}
> +#endif /* CONFIG_CHECKPOINT_RESTORE */

Well, I do not think we need 2 helpers, just one which takes a boolean
will look better, imo.

Oleg.

WARNING: multiple messages have this Message-ID (diff)
From: Oleg Nesterov <oleg@redhat.com>
To: Tycho Andersen <tycho.andersen@canonical.com>
Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
	Kees Cook <keescook@chromium.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Will Drewry <wad@chromium.org>,
	Roland McGrath <roland@hack.frob.com>,
	Pavel Emelyanov <xemul@parallels.com>,
	"Serge E. Hallyn" <serge.hallyn@ubuntu.com>
Subject: Re: [PATCH] seccomp: add ptrace commands for suspend/resume
Date: Tue, 2 Jun 2015 20:28:29 +0200	[thread overview]
Message-ID: <20150602182829.GA23449@redhat.com> (raw)
In-Reply-To: <1433186918-9626-1-git-send-email-tycho.andersen@canonical.com>

On 06/01, Tycho Andersen wrote:
>
> --- a/include/linux/seccomp.h
> +++ b/include/linux/seccomp.h
> @@ -25,6 +25,9 @@ struct seccomp_filter;
>  struct seccomp {
>  	int mode;
>  	struct seccomp_filter *filter;
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +	bool suspended;
> +#endif

Then afaics you need to change copy_seccomp() to clear ->suspended.
At least if the child is not traced.

> @@ -691,6 +697,11 @@ u32 seccomp_phase1(struct seccomp_data *sd)
>  	int this_syscall = sd ? sd->nr :
>  		syscall_get_nr(current, task_pt_regs(current));
>  
> +#ifdef CONFIG_CHECKPOINT_RESTORE
> +	if (unlikely(current->seccomp.suspended))
> +		return SECCOMP_PHASE1_OK;
> +#endif
> +

I am wondering if PTRACE_SUSPEND_SECCOMP can just clear/set TIF_SECCOMP.
Of course, it is not that resume_seccomp() can simply do set_tsk_thread_flag,
it should be more careful. And prctl_set_seccomp() paths will need some
changes. Probably not, this would be more complex.

So perhaps it would be better to add PTRACE_O_SUSPEND_SECCOMP? This also
solves the problem with the killed tracer. Except TIF_NOTSC...

But why do we bother to play with TIF_NOTSC, could you explain?

> +int suspend_seccomp(struct task_struct *task)
> +{
> +	int ret = -EACCES;
> +
> +	spin_lock_irq(&task->sighand->siglock);
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		goto out;

I am puzzled ;) Why do we need ->siglock? And even if we need it, why
we can't check CAP_SYS_ADMIN lockless?

And I am not sure I understand why do we need the additional security
check, but I leave this to you and Andy.

If you have the rights to trace this task, then you can do anything
the tracee could do without the filtering.

> +
> +	task->seccomp.suspended = true;
> +
> +#ifdef TIF_NOTSC
> +	if (task->seccomp.mode == SECCOMP_MODE_STRICT)
> +		clear_tsk_thread_flag(task, TIF_NOTSC);
> +#endif
> +
> +	ret = 0;
> +out:
> +	spin_unlock_irq(&task->sighand->siglock);
> +
> +	return ret;
> +}
> +
> +int resume_seccomp(struct task_struct *task)
> +{
> +	int ret = -EACCES;
> +
> +	spin_lock_irq(&task->sighand->siglock);
> +
> +	if (!capable(CAP_SYS_ADMIN))
> +		goto out;
> +
> +	task->seccomp.suspended = false;
> +
> +#ifdef TIF_NOTSC
> +	if (task->seccomp.mode == SECCOMP_MODE_STRICT)
> +		set_tsk_thread_flag(task, TIF_NOTSC);
> +#endif
> +
> +	ret = 0;
> +out:
> +	spin_unlock_irq(&task->sighand->siglock);
> +
> +	return ret;
> +}
> +#endif /* CONFIG_CHECKPOINT_RESTORE */

Well, I do not think we need 2 helpers, just one which takes a boolean
will look better, imo.

Oleg.


  parent reply	other threads:[~2015-06-02 18:28 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-01 19:28 [PATCH] seccomp: add ptrace commands for suspend/resume Tycho Andersen
2015-06-01 19:28 ` Tycho Andersen
     [not found] ` <1433186918-9626-1-git-send-email-tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org>
2015-06-01 19:38   ` Andy Lutomirski
2015-06-01 19:38     ` Andy Lutomirski
     [not found]     ` <CALCETrVaE5UsTSQDf=48R8J9gG6YiMdp30wOMD+aZvxtOjrLRQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-01 19:47       ` Tycho Andersen
2015-06-01 19:47         ` Tycho Andersen
2015-06-01 19:51         ` Andy Lutomirski
2015-06-01 19:51           ` Andy Lutomirski
     [not found]           ` <CALCETrU2c99wQHfVS6Bi_7=sAYSr-gEUpRdgz=+FiGgGxbPyMg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-01 20:12             ` Tycho Andersen
2015-06-01 20:12               ` Tycho Andersen
2015-06-02 15:46               ` Tycho Andersen
2015-06-01 20:00       ` Tycho Andersen
2015-06-01 20:00         ` Tycho Andersen
2015-06-02  9:36   ` Andrey Wagin
2015-06-02  9:36     ` Andrey Wagin
     [not found]     ` <CANaxB-zacYuo21jLVZyEfyf=UdDnTjYvHdgNpfL+c_DXWRz-eg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-02 13:05       ` Tycho Andersen
2015-06-02 13:05         ` Tycho Andersen
2015-06-02 18:48         ` Oleg Nesterov
     [not found]           ` <20150602184848.GA24907-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-03 16:13             ` Tycho Andersen
2015-06-03 16:13               ` Tycho Andersen
2015-06-03 16:54               ` Oleg Nesterov
2015-06-03 16:54                 ` Oleg Nesterov
     [not found]                 ` <20150603165451.GA20911-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-03 16:58                   ` Tycho Andersen
2015-06-03 16:58                     ` Tycho Andersen
2015-06-03 18:36                   ` Tycho Andersen
2015-06-03 18:36                     ` Tycho Andersen
2015-06-02 18:28   ` Oleg Nesterov [this message]
2015-06-02 18:28     ` Oleg Nesterov
     [not found]     ` <20150602182829.GA23449-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-02 19:02       ` Pavel Emelyanov
2015-06-02 19:02         ` Pavel Emelyanov
2015-06-02 19:24         ` Jann Horn
     [not found]         ` <556DFDB2.3050205-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2015-06-02 19:27           ` Andy Lutomirski
2015-06-02 19:27             ` Andy Lutomirski
     [not found]             ` <CALCETrVYHYfogj3nTY-3ui87+tVi3mG3D4=Xdk-_MpisG8BczA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-06-03 14:45               ` Tycho Andersen
2015-06-03 14:45                 ` Tycho Andersen
2015-06-02 21:27           ` Oleg Nesterov
2015-06-02 21:27             ` Oleg Nesterov
2015-06-03 14:43       ` Tycho Andersen
2015-06-03 14:43         ` Tycho Andersen
2015-06-03 16:41         ` Oleg Nesterov
2015-06-03 16:41           ` Oleg Nesterov
     [not found]           ` <20150603164121.GA19189-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2015-06-03 17:10             ` Tycho Andersen
2015-06-03 17:10               ` Tycho Andersen
2015-06-03 17:11           ` Andy Lutomirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150602182829.GA23449@redhat.com \
    --to=oleg-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
    --cc=keescook-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=linux-api-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=luto-kltTT9wpgjJwATOyAt5JVQ@public.gmane.org \
    --cc=roland-/Z5OmTQCD9xF6kxbq+BtvQ@public.gmane.org \
    --cc=serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org \
    --cc=tycho.andersen-Z7WLFzj8eWMS+FvcfC7Uqw@public.gmane.org \
    --cc=wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org \
    --cc=xemul-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.