Skip to content

Commit 667161b

Browse files
committed
Merge tag 'seccomp-v6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull seccomp updates from Kees Cook: - Add missing kerndoc parameter (Randy Dunlap) - Improve seccomp selftest to check CAP_SYS_ADMIN (Gautam Menghani) - Fix allocation leak when cloned thread immediately dies (Kuniyuki Iwashima) * tag 'seccomp-v6.2-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: seccomp: document the "filter_count" field seccomp: Move copy_seccomp() to no failure path. selftests/seccomp: Check CAP_SYS_ADMIN capability in the test mode_filter_without_nnp
2 parents 059c4a3 + b906972 commit 667161b

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

include/linux/seccomp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ struct seccomp_filter;
2727
*
2828
* @mode: indicates one of the valid values above for controlled
2929
* system calls available to a process.
30+
* @filter_count: number of seccomp filters
3031
* @filter: must always point to a valid seccomp-filter or NULL as it is
3132
* accessed without locking during system call entry.
3233
*

kernel/fork.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,9 @@ void put_task_stack(struct task_struct *tsk)
535535

536536
void free_task(struct task_struct *tsk)
537537
{
538+
#ifdef CONFIG_SECCOMP
539+
WARN_ON_ONCE(tsk->seccomp.filter);
540+
#endif
538541
release_user_cpus_ptr(tsk);
539542
scs_release(tsk);
540543

@@ -2406,12 +2409,6 @@ static __latent_entropy struct task_struct *copy_process(
24062409

24072410
spin_lock(&current->sighand->siglock);
24082411

2409-
/*
2410-
* Copy seccomp details explicitly here, in case they were changed
2411-
* before holding sighand lock.
2412-
*/
2413-
copy_seccomp(p);
2414-
24152412
rv_task_fork(p);
24162413

24172414
rseq_fork(p, clone_flags);
@@ -2428,6 +2425,14 @@ static __latent_entropy struct task_struct *copy_process(
24282425
goto bad_fork_cancel_cgroup;
24292426
}
24302427

2428+
/* No more failure paths after this point. */
2429+
2430+
/*
2431+
* Copy seccomp details explicitly here, in case they were changed
2432+
* before holding sighand lock.
2433+
*/
2434+
copy_seccomp(p);
2435+
24312436
init_task_pid_links(p);
24322437
if (likely(p->pid)) {
24332438
ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);

tools/testing/selftests/seccomp/seccomp_bpf.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ TEST(mode_filter_without_nnp)
392392
.filter = filter,
393393
};
394394
long ret;
395+
cap_t cap = cap_get_proc();
396+
cap_flag_value_t is_cap_sys_admin = 0;
395397

396398
ret = prctl(PR_GET_NO_NEW_PRIVS, 0, NULL, 0, 0);
397399
ASSERT_LE(0, ret) {
@@ -400,8 +402,8 @@ TEST(mode_filter_without_nnp)
400402
errno = 0;
401403
ret = prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog, 0, 0);
402404
/* Succeeds with CAP_SYS_ADMIN, fails without */
403-
/* TODO(wad) check caps not euid */
404-
if (geteuid()) {
405+
cap_get_flag(cap, CAP_SYS_ADMIN, CAP_EFFECTIVE, &is_cap_sys_admin);
406+
if (!is_cap_sys_admin) {
405407
EXPECT_EQ(-1, ret);
406408
EXPECT_EQ(EACCES, errno);
407409
} else {

0 commit comments

Comments
 (0)