mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter()
@ 2017-09-27 15:25 Tycho Andersen
  2017-09-27 15:42 ` Kees Cook
  0 siblings, 1 reply; 2+ messages in thread
From: Tycho Andersen @ 2017-09-27 15:25 UTC (permalink / raw)
  To: Kees Cook
  Cc: linux-kernel, Andy Lutomirski, Will Drewry, security,
	Chris Salls, Oleg Nesterov, stable, Tycho Andersen

From: Oleg Nesterov <oleg@redhat.com>

As Chris explains, get_seccomp_filter() and put_seccomp_filter() can
use the different filters, once we drop ->siglock task->seccomp.filter
can be replaced by SECCOMP_FILTER_FLAG_TSYNC.

v2: add __get_seccomp_filter vs. open coding refcount_inc()

Fixes: f8e529ed941b ("seccomp, ptrace: add support for dumping seccomp filters")
Reported-by: Chris Salls <chrissalls5@gmail.com>
Cc: stable@vger.kernel.org
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Tycho Andersen <tycho@docker.com>
---
 kernel/seccomp.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/kernel/seccomp.c b/kernel/seccomp.c
index c24579dfa7a1..bb3a38005b9c 100644
--- a/kernel/seccomp.c
+++ b/kernel/seccomp.c
@@ -473,14 +473,19 @@ static long seccomp_attach_filter(unsigned int flags,
 	return 0;
 }
 
+void __get_seccomp_filter(struct seccomp_filter *filter)
+{
+	/* Reference count is bounded by the number of total processes. */
+	refcount_inc(&filter->usage);
+}
+
 /* get_seccomp_filter - increments the reference count of the filter on @tsk */
 void get_seccomp_filter(struct task_struct *tsk)
 {
 	struct seccomp_filter *orig = tsk->seccomp.filter;
 	if (!orig)
 		return;
-	/* Reference count is bounded by the number of total processes. */
-	refcount_inc(&orig->usage);
+	__get_seccomp_filter(orig);
 }
 
 static inline void seccomp_filter_free(struct seccomp_filter *filter)
@@ -491,10 +496,8 @@ static inline void seccomp_filter_free(struct seccomp_filter *filter)
 	}
 }
 
-/* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */
-void put_seccomp_filter(struct task_struct *tsk)
+static void __put_seccomp_filter(struct seccomp_filter *orig)
 {
-	struct seccomp_filter *orig = tsk->seccomp.filter;
 	/* Clean up single-reference branches iteratively. */
 	while (orig && refcount_dec_and_test(&orig->usage)) {
 		struct seccomp_filter *freeme = orig;
@@ -503,6 +506,12 @@ void put_seccomp_filter(struct task_struct *tsk)
 	}
 }
 
+/* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */
+void put_seccomp_filter(struct task_struct *tsk)
+{
+	__put_seccomp_filter(tsk->seccomp.filter);
+}
+
 static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason)
 {
 	memset(info, 0, sizeof(*info));
@@ -1025,13 +1034,13 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
 	if (!data)
 		goto out;
 
-	get_seccomp_filter(task);
+	__get_seccomp_filter(filter);
 	spin_unlock_irq(&task->sighand->siglock);
 
 	if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog)))
 		ret = -EFAULT;
 
-	put_seccomp_filter(task);
+	__put_seccomp_filter(filter);
 	return ret;
 
 out:
-- 
2.11.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter()
  2017-09-27 15:25 [PATCH v2] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter() Tycho Andersen
@ 2017-09-27 15:42 ` Kees Cook
  0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2017-09-27 15:42 UTC (permalink / raw)
  To: Tycho Andersen
  Cc: LKML, Andy Lutomirski, Will Drewry, security, Chris Salls,
	Oleg Nesterov, # 3.4.x

On Wed, Sep 27, 2017 at 5:25 PM, Tycho Andersen <tycho@docker.com> wrote:
> From: Oleg Nesterov <oleg@redhat.com>
>
> As Chris explains, get_seccomp_filter() and put_seccomp_filter() can
> use the different filters, once we drop ->siglock task->seccomp.filter
> can be replaced by SECCOMP_FILTER_FLAG_TSYNC.
>
> v2: add __get_seccomp_filter vs. open coding refcount_inc()
>
> Fixes: f8e529ed941b ("seccomp, ptrace: add support for dumping seccomp filters")
> Reported-by: Chris Salls <chrissalls5@gmail.com>
> Cc: stable@vger.kernel.org
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> Signed-off-by: Tycho Andersen <tycho@docker.com>

Thanks, applied!

-Kees

> ---
>  kernel/seccomp.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
>
> diff --git a/kernel/seccomp.c b/kernel/seccomp.c
> index c24579dfa7a1..bb3a38005b9c 100644
> --- a/kernel/seccomp.c
> +++ b/kernel/seccomp.c
> @@ -473,14 +473,19 @@ static long seccomp_attach_filter(unsigned int flags,
>         return 0;
>  }
>
> +void __get_seccomp_filter(struct seccomp_filter *filter)
> +{
> +       /* Reference count is bounded by the number of total processes. */
> +       refcount_inc(&filter->usage);
> +}
> +
>  /* get_seccomp_filter - increments the reference count of the filter on @tsk */
>  void get_seccomp_filter(struct task_struct *tsk)
>  {
>         struct seccomp_filter *orig = tsk->seccomp.filter;
>         if (!orig)
>                 return;
> -       /* Reference count is bounded by the number of total processes. */
> -       refcount_inc(&orig->usage);
> +       __get_seccomp_filter(orig);
>  }
>
>  static inline void seccomp_filter_free(struct seccomp_filter *filter)
> @@ -491,10 +496,8 @@ static inline void seccomp_filter_free(struct seccomp_filter *filter)
>         }
>  }
>
> -/* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */
> -void put_seccomp_filter(struct task_struct *tsk)
> +static void __put_seccomp_filter(struct seccomp_filter *orig)
>  {
> -       struct seccomp_filter *orig = tsk->seccomp.filter;
>         /* Clean up single-reference branches iteratively. */
>         while (orig && refcount_dec_and_test(&orig->usage)) {
>                 struct seccomp_filter *freeme = orig;
> @@ -503,6 +506,12 @@ void put_seccomp_filter(struct task_struct *tsk)
>         }
>  }
>
> +/* put_seccomp_filter - decrements the ref count of tsk->seccomp.filter */
> +void put_seccomp_filter(struct task_struct *tsk)
> +{
> +       __put_seccomp_filter(tsk->seccomp.filter);
> +}
> +
>  static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason)
>  {
>         memset(info, 0, sizeof(*info));
> @@ -1025,13 +1034,13 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
>         if (!data)
>                 goto out;
>
> -       get_seccomp_filter(task);
> +       __get_seccomp_filter(filter);
>         spin_unlock_irq(&task->sighand->siglock);
>
>         if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog)))
>                 ret = -EFAULT;
>
> -       put_seccomp_filter(task);
> +       __put_seccomp_filter(filter);
>         return ret;
>
>  out:
> --
> 2.11.0
>



-- 
Kees Cook
Pixel Security

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-27 15:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-27 15:25 [PATCH v2] seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter() Tycho Andersen
2017-09-27 15:42 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®