]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
seccomp: avoid the lock trip seccomp_filter_release in common case
authorMateusz Guzik <mjguzik@gmail.com>
Thu, 13 Feb 2025 17:09:10 +0000 (18:09 +0100)
committerKees Cook <kees@kernel.org>
Mon, 24 Feb 2025 19:17:10 +0000 (11:17 -0800)
commit8f19331384e6ca816f5bea20ab45c4b72a5cd05f
treed652ee7c41fda60e07ec6f528498fd4d306c006e
parente1cec5107c394911c32ddd907e89d77249c48559
seccomp: avoid the lock trip seccomp_filter_release in common case

Vast majority of threads don't have any seccomp filters, all while the
lock taken here is shared between all threads in given process and
frequently used.

Safety of the check relies on the following:
- seccomp_filter_release is only legally called for PF_EXITING threads
- SIGNAL_GROUP_EXIT is only ever set with the sighand lock held
- PF_EXITING is only ever set with the sighand lock held *or* after
  SIGNAL_GROUP_EXIT is set *or* the process is single-threaded
- seccomp_sync_threads holds the sighand lock and skips all threads if
  SIGNAL_GROUP_EXIT is set, PF_EXITING threads if not

Resulting reduction of contention gives me a 5% boost in a
microbenchmark spawning and killing threads within the same process.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Link: https://lore.kernel.org/r/20250213170911.1140187-1-mjguzik@gmail.com
Signed-off-by: Kees Cook <kees@kernel.org>
kernel/seccomp.c