seccomp.c (8e01b51a31a1e08e2c3e8fcc0ef6790441be2f61) seccomp.c (0d8315dddd2899f519fe1ca3d4d5cdaf44ea421e)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/kernel/seccomp.c
4 *
5 * Copyright 2004-2005 Andrea Arcangeli <andrea@cpushare.com>
6 *
7 * Copyright (C) 2012 Google, Inc.
8 * Will Drewry <wad@chromium.org>

--- 539 unchanged lines hidden (view full) ---

548 * This function should only be called when the task is exiting as
549 * it detaches it from its filter tree. As such, READ_ONCE() and
550 * barriers are not needed here, as would normally be needed.
551 */
552void seccomp_filter_release(struct task_struct *tsk)
553{
554 struct seccomp_filter *orig = tsk->seccomp.filter;
555
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * linux/kernel/seccomp.c
4 *
5 * Copyright 2004-2005 Andrea Arcangeli <andrea@cpushare.com>
6 *
7 * Copyright (C) 2012 Google, Inc.
8 * Will Drewry <wad@chromium.org>

--- 539 unchanged lines hidden (view full) ---

548 * This function should only be called when the task is exiting as
549 * it detaches it from its filter tree. As such, READ_ONCE() and
550 * barriers are not needed here, as would normally be needed.
551 */
552void seccomp_filter_release(struct task_struct *tsk)
553{
554 struct seccomp_filter *orig = tsk->seccomp.filter;
555
556 /* We are effectively holding the siglock by not having any sighand. */
557 WARN_ON(tsk->sighand != NULL);
558
556 /* Detach task from its filter tree. */
557 tsk->seccomp.filter = NULL;
558 __seccomp_filter_release(orig);
559}
560
561/**
562 * seccomp_sync_threads: sets all threads to use current's filter
563 *

--- 1766 unchanged lines hidden (view full) ---

2330 kmemleak_not_leak(hdr);
2331
2332 return 0;
2333}
2334
2335device_initcall(seccomp_sysctl_init)
2336
2337#endif /* CONFIG_SYSCTL */
559 /* Detach task from its filter tree. */
560 tsk->seccomp.filter = NULL;
561 __seccomp_filter_release(orig);
562}
563
564/**
565 * seccomp_sync_threads: sets all threads to use current's filter
566 *

--- 1766 unchanged lines hidden (view full) ---

2333 kmemleak_not_leak(hdr);
2334
2335 return 0;
2336}
2337
2338device_initcall(seccomp_sysctl_init)
2339
2340#endif /* CONFIG_SYSCTL */
2341
2342#ifdef CONFIG_SECCOMP_CACHE_DEBUG
2343/* Currently CONFIG_SECCOMP_CACHE_DEBUG implies SECCOMP_ARCH_NATIVE */
2344static void proc_pid_seccomp_cache_arch(struct seq_file *m, const char *name,
2345 const void *bitmap, size_t bitmap_size)
2346{
2347 int nr;
2348
2349 for (nr = 0; nr < bitmap_size; nr++) {
2350 bool cached = test_bit(nr, bitmap);
2351 char *status = cached ? "ALLOW" : "FILTER";
2352
2353 seq_printf(m, "%s %d %s\n", name, nr, status);
2354 }
2355}
2356
2357int proc_pid_seccomp_cache(struct seq_file *m, struct pid_namespace *ns,
2358 struct pid *pid, struct task_struct *task)
2359{
2360 struct seccomp_filter *f;
2361 unsigned long flags;
2362
2363 /*
2364 * We don't want some sandboxed process to know what their seccomp
2365 * filters consist of.
2366 */
2367 if (!file_ns_capable(m->file, &init_user_ns, CAP_SYS_ADMIN))
2368 return -EACCES;
2369
2370 if (!lock_task_sighand(task, &flags))
2371 return -ESRCH;
2372
2373 f = READ_ONCE(task->seccomp.filter);
2374 if (!f) {
2375 unlock_task_sighand(task, &flags);
2376 return 0;
2377 }
2378
2379 /* prevent filter from being freed while we are printing it */
2380 __get_seccomp_filter(f);
2381 unlock_task_sighand(task, &flags);
2382
2383 proc_pid_seccomp_cache_arch(m, SECCOMP_ARCH_NATIVE_NAME,
2384 f->cache.allow_native,
2385 SECCOMP_ARCH_NATIVE_NR);
2386
2387#ifdef SECCOMP_ARCH_COMPAT
2388 proc_pid_seccomp_cache_arch(m, SECCOMP_ARCH_COMPAT_NAME,
2389 f->cache.allow_compat,
2390 SECCOMP_ARCH_COMPAT_NR);
2391#endif /* SECCOMP_ARCH_COMPAT */
2392
2393 __put_seccomp_filter(f);
2394 return 0;
2395}
2396#endif /* CONFIG_SECCOMP_CACHE_DEBUG */