Skip to content

Commit

Permalink
Merge tag 'seccomp-v4.14-rc3' of git://git.kernel.org/pub/scm/linux/k…
Browse files Browse the repository at this point in the history
…ernel/git/kees/linux

Pull seccomp fix from Kees Cook:
 "Fix refcounting bug in CRIU interface, noticed by Chris Salls (Oleg &
  Tycho)"

* tag 'seccomp-v4.14-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter()
  • Loading branch information
Linus Torvalds committed Sep 28, 2017
2 parents 9cd6681 + 66a733e commit 26e811c
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions kernel/seccomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 26e811c

Please sign in to comment.