| 316d06b0 | 20-Mar-2025 |
Mickaël Salaün <[email protected]> |
selftests/landlock: Add audit tests for filesystem
Test all filesystem blockers, including events with several records, and record with several blockers: - fs.execute - fs.write_file - fs.read_file
selftests/landlock: Add audit tests for filesystem
Test all filesystem blockers, including events with several records, and record with several blockers: - fs.execute - fs.write_file - fs.read_file - fs_read_dir - fs.remove_dir - fs.remove_file - fs.make_char - fs.make_dir - fs.make_reg - fs.make_sock - fs.make_fifo - fs.make_block - fs.make_sym - fs.refer - fs.truncate - fs.ioctl_dev - fs.change_topology
Cc: Günther Noack <[email protected]> Cc: Paul Moore <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| e2893c0a | 20-Mar-2025 |
Mickaël Salaün <[email protected]> |
selftests/landlock: Add audit tests for ptrace
Add tests for all ptrace actions checking "blockers=ptrace" records.
This also improves PTRACE_TRACEME and PTRACE_ATTACH tests by making sure that the
selftests/landlock: Add audit tests for ptrace
Add tests for all ptrace actions checking "blockers=ptrace" records.
This also improves PTRACE_TRACEME and PTRACE_ATTACH tests by making sure that the restrictions comes from Landlock, and with the expected process. These extended tests are like enhanced errno checks that make sure Landlock enforcement is consistent.
Cc: Günther Noack <[email protected]> Cc: Paul Moore <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| 6a500b22 | 20-Mar-2025 |
Mickaël Salaün <[email protected]> |
selftests/landlock: Add tests for audit flags and domain IDs
Add audit_test.c to check with and without LANDLOCK_RESTRICT_SELF_* flags against the two Landlock audit record types: AUDIT_LANDLOCK_ACC
selftests/landlock: Add tests for audit flags and domain IDs
Add audit_test.c to check with and without LANDLOCK_RESTRICT_SELF_* flags against the two Landlock audit record types: AUDIT_LANDLOCK_ACCESS and AUDIT_LANDLOCK_DOMAIN.
Check consistency of domain IDs per layer in AUDIT_LANDLOCK_ACCESS and AUDIT_LANDLOCK_DOMAIN messages: denied access, domain allocation, and domain deallocation.
These tests use signal scoping to make it simple. They are not in the scoped_signal_test.c file but in the new dedicated audit_test.c file.
Tests are run with audit filters to ensure the audit records come from the test program. Moreover, because there can only be one audit process, tests would failed if run in parallel. Because of audit limitations, tests can only be run in the initial namespace.
The audit test helpers were inspired by libaudit and tools/testing/selftests/net/netfilter/audit_logread.c
Cc: Günther Noack <[email protected]> Cc: Paul Moore <[email protected]> Cc: Phil Sutter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| e178b404 | 20-Mar-2025 |
Mickaël Salaün <[email protected]> |
selftests/landlock: Extend tests for landlock_restrict_self(2)'s flags
Add the base_test's restrict_self_fd_flags tests to align with previous restrict_self_fd tests but with the new LANDLOCK_RESTRI
selftests/landlock: Extend tests for landlock_restrict_self(2)'s flags
Add the base_test's restrict_self_fd_flags tests to align with previous restrict_self_fd tests but with the new LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF flag.
Add the restrict_self_flags tests to check that LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF, LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON, and LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF are valid but not the next bit. Some checks are similar to restrict_self_checks_ordering's ones.
Cc: Günther Noack <[email protected]> Cc: Paul Moore <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| 12bfcda7 | 20-Mar-2025 |
Mickaël Salaün <[email protected]> |
landlock: Add LANDLOCK_RESTRICT_SELF_LOG_*_EXEC_* flags
Most of the time we want to log denied access because they should not happen and such information helps diagnose issues. However, when sandbo
landlock: Add LANDLOCK_RESTRICT_SELF_LOG_*_EXEC_* flags
Most of the time we want to log denied access because they should not happen and such information helps diagnose issues. However, when sandboxing processes that we know will try to access denied resources (e.g. unknown, bogus, or malicious binary), we might want to not log related access requests that might fill up logs.
By default, denied requests are logged until the task call execve(2).
If the LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF flag is set, denied requests will not be logged for the same executed file.
If the LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON flag is set, denied requests from after an execve(2) call will be logged.
The rationale is that a program should know its own behavior, but not necessarily the behavior of other programs.
Because LANDLOCK_RESTRICT_SELF_LOG_SAME_EXEC_OFF is set for a specific Landlock domain, it makes it possible to selectively mask some access requests that would be logged by a parent domain, which might be handy for unprivileged processes to limit logs. However, system administrators should still use the audit filtering mechanism. There is intentionally no audit nor sysctl configuration to re-enable these logs. This is delegated to the user space program.
Increment the Landlock ABI version to reflect this interface change.
Cc: Günther Noack <[email protected]> Cc: Paul Moore <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mic: Rename variables and fix __maybe_unused] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| c5efa393 | 18-Mar-2025 |
Mickaël Salaün <[email protected]> |
selftests/landlock: Add a new test for setuid()
The new signal_scoping_thread_setuid tests check that the libc's setuid() function works as expected even when a thread is sandboxed with scoped signa
selftests/landlock: Add a new test for setuid()
The new signal_scoping_thread_setuid tests check that the libc's setuid() function works as expected even when a thread is sandboxed with scoped signal restrictions.
Before the signal scoping fix, this test would have failed with the setuid() call:
[pid 65] getpid() = 65 [pid 65] tgkill(65, 66, SIGRT_1) = -1 EPERM (Operation not permitted) [pid 65] futex(0x40a66cdc, FUTEX_WAKE_PRIVATE, 1) = 0 [pid 65] setuid(1001) = 0
After the fix, tgkill(2) is successfully leveraged to synchronize credentials update across threads:
[pid 65] getpid() = 65 [pid 65] tgkill(65, 66, SIGRT_1) = 0 [pid 66] <... read resumed>0x40a65eb7, 1) = ? ERESTARTSYS (To be restarted if SA_RESTART is set) [pid 66] --- SIGRT_1 {si_signo=SIGRT_1, si_code=SI_TKILL, si_pid=65, si_uid=1000} --- [pid 66] getpid() = 65 [pid 66] setuid(1001) = 0 [pid 66] futex(0x40a66cdc, FUTEX_WAKE_PRIVATE, 1) = 0 [pid 66] rt_sigreturn({mask=[]}) = 0 [pid 66] read(3, <unfinished ...> [pid 65] setuid(1001) = 0
Test coverage for security/landlock is 92.9% of 1137 lines according to gcc/gcov-14.
Fixes: c8994965013e ("selftests/landlock: Test signal scoping for threads") Cc: Günther Noack <[email protected]> Cc: Tahera Fahimi <[email protected]> Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] [mic: Update test coverage] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| 18eb75f3 | 18-Mar-2025 |
Mickaël Salaün <[email protected]> |
landlock: Always allow signals between threads of the same process
Because Linux credentials are managed per thread, user space relies on some hack to synchronize credential update across threads fr
landlock: Always allow signals between threads of the same process
Because Linux credentials are managed per thread, user space relies on some hack to synchronize credential update across threads from the same process. This is required by the Native POSIX Threads Library and implemented by set*id(2) wrappers and libcap(3) to use tgkill(2) to synchronize threads. See nptl(7) and libpsx(3). Furthermore, some runtimes like Go do not enable developers to have control over threads [1].
To avoid potential issues, and because threads are not security boundaries, let's relax the Landlock (optional) signal scoping to always allow signals sent between threads of the same process. This exception is similar to the __ptrace_may_access() one.
hook_file_set_fowner() now checks if the target task is part of the same process as the caller. If this is the case, then the related signal triggered by the socket will always be allowed.
Scoping of abstract UNIX sockets is not changed because kernel objects (e.g. sockets) should be tied to their creator's domain at creation time.
Note that creating one Landlock domain per thread puts each of these threads (and their future children) in their own scope, which is probably not what users expect, especially in Go where we do not control threads. However, being able to drop permissions on all threads should not be restricted by signal scoping. We are working on a way to make it possible to atomically restrict all threads of a process with the same domain [2].
Add erratum for signal scoping.
Closes: https://github.com/landlock-lsm/go-landlock/issues/36 Fixes: 54a6e6bbf3be ("landlock: Add signal scoping") Fixes: c8994965013e ("selftests/landlock: Test signal scoping for threads") Depends-on: 26f204380a3c ("fs: Fix file_set_fowner LSM hook inconsistencies") Link: https://pkg.go.dev/kernel.org/pub/linux/libs/security/libcap/psx [1] Link: https://github.com/landlock-lsm/linux/issues/2 [2] Cc: Günther Noack <[email protected]> Cc: Paul Moore <[email protected]> Cc: Serge Hallyn <[email protected]> Cc: Tahera Fahimi <[email protected]> Cc: [email protected] Acked-by: Christian Brauner <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mic: Add extra pointer check and RCU guard, and ease backport] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|
| 2a794ee6 | 08-Jan-2025 |
Mickaël Salaün <[email protected]> |
selftests/landlock: Add layout1.umount_sandboxer tests
Check that a domain is not tied to the executable file that created it. For instance, that could happen if a Landlock domain took a reference t
selftests/landlock: Add layout1.umount_sandboxer tests
Check that a domain is not tied to the executable file that created it. For instance, that could happen if a Landlock domain took a reference to a struct path.
Move global path names to common.h and replace copy_binary() with a more generic copy_file() helper.
Test coverage for security/landlock is 92.7% of 1133 lines according to gcc/gcov-14.
Cc: Günther Noack <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mic: Update date and add test coverage] Signed-off-by: Mickaël Salaün <[email protected]>
show more ...
|