mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-04-01 11:54:10 +00:00
seccomp: fix the usage of get/put_seccomp_filter() in seccomp_get_filter()
As Chris explains, get_seccomp_filter() and put_seccomp_filter() can end
up using different filters. Once we drop ->siglock it is possible for
task->seccomp.filter to have been replaced by SECCOMP_FILTER_FLAG_TSYNC.
Fixes: f8e529ed94
("seccomp, ptrace: add support for dumping seccomp filters")
Reported-by: Chris Salls <chrissalls5@gmail.com>
Cc: stable@vger.kernel.org # needs s/refcount_/atomic_/ for v4.12 and earlier
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
[tycho: add __get_seccomp_filter vs. open coding refcount_inc()]
Signed-off-by: Tycho Andersen <tycho@docker.com>
[kees: tweak commit log]
Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
parent
e19b205be4
commit
66a733ea6b
1 changed files with 16 additions and 7 deletions
|
@ -473,14 +473,19 @@ static long seccomp_attach_filter(unsigned int flags,
|
||||||
return 0;
|
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 */
|
/* get_seccomp_filter - increments the reference count of the filter on @tsk */
|
||||||
void get_seccomp_filter(struct task_struct *tsk)
|
void get_seccomp_filter(struct task_struct *tsk)
|
||||||
{
|
{
|
||||||
struct seccomp_filter *orig = tsk->seccomp.filter;
|
struct seccomp_filter *orig = tsk->seccomp.filter;
|
||||||
if (!orig)
|
if (!orig)
|
||||||
return;
|
return;
|
||||||
/* Reference count is bounded by the number of total processes. */
|
__get_seccomp_filter(orig);
|
||||||
refcount_inc(&orig->usage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void seccomp_filter_free(struct seccomp_filter *filter)
|
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 */
|
static void __put_seccomp_filter(struct seccomp_filter *orig)
|
||||||
void put_seccomp_filter(struct task_struct *tsk)
|
|
||||||
{
|
{
|
||||||
struct seccomp_filter *orig = tsk->seccomp.filter;
|
|
||||||
/* Clean up single-reference branches iteratively. */
|
/* Clean up single-reference branches iteratively. */
|
||||||
while (orig && refcount_dec_and_test(&orig->usage)) {
|
while (orig && refcount_dec_and_test(&orig->usage)) {
|
||||||
struct seccomp_filter *freeme = orig;
|
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)
|
static void seccomp_init_siginfo(siginfo_t *info, int syscall, int reason)
|
||||||
{
|
{
|
||||||
memset(info, 0, sizeof(*info));
|
memset(info, 0, sizeof(*info));
|
||||||
|
@ -1025,13 +1034,13 @@ long seccomp_get_filter(struct task_struct *task, unsigned long filter_off,
|
||||||
if (!data)
|
if (!data)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
get_seccomp_filter(task);
|
__get_seccomp_filter(filter);
|
||||||
spin_unlock_irq(&task->sighand->siglock);
|
spin_unlock_irq(&task->sighand->siglock);
|
||||||
|
|
||||||
if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog)))
|
if (copy_to_user(data, fprog->filter, bpf_classic_proglen(fprog)))
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
|
|
||||||
put_seccomp_filter(task);
|
__put_seccomp_filter(filter);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
out:
|
out:
|
||||||
|
|
Loading…
Add table
Reference in a new issue