Skip to content

Commit 35e886e

Browse files
committed
Merge tag 'landlock-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mic/linux
Pull landlock updates from Mickaël Salaün: "Some miscellaneous improvements, including new KUnit tests, extended documentation and boot help, and some cosmetic cleanups. Additional test changes already went through the net tree" * tag 'landlock-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/mic/linux: samples/landlock: Don't error out if a file path cannot be opened landlock: Use f_cred in security_file_open() hook landlock: Rename "ptrace" files to "task" landlock: Simplify current_check_access_socket() landlock: Warn once if a Landlock action is requested while disabled landlock: Extend documentation for kernel support landlock: Add support for KUnit tests selftests/landlock: Clean up error logs related to capabilities
2 parents 29da654 + a17c60e commit 35e886e

File tree

14 files changed

+363
-65
lines changed

14 files changed

+363
-65
lines changed

Documentation/userspace-api/landlock.rst

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ unexpected/malicious behaviors in user space applications. Landlock empowers
1919
any process, including unprivileged ones, to securely restrict themselves.
2020

2121
We can quickly make sure that Landlock is enabled in the running system by
22-
looking for "landlock: Up and running" in kernel logs (as root): ``dmesg | grep
23-
landlock || journalctl -kg landlock`` . Developers can also easily check for
24-
Landlock support with a :ref:`related system call <landlock_abi_versions>`. If
25-
Landlock is not currently supported, we need to :ref:`configure the kernel
26-
appropriately <kernel_support>`.
22+
looking for "landlock: Up and running" in kernel logs (as root):
23+
``dmesg | grep landlock || journalctl -kb -g landlock`` .
24+
Developers can also easily check for Landlock support with a
25+
:ref:`related system call <landlock_abi_versions>`.
26+
If Landlock is not currently supported, we need to
27+
:ref:`configure the kernel appropriately <kernel_support>`.
2728

2829
Landlock rules
2930
==============
@@ -499,6 +500,9 @@ access rights.
499500
Kernel support
500501
==============
501502

503+
Build time configuration
504+
------------------------
505+
502506
Landlock was first introduced in Linux 5.13 but it must be configured at build
503507
time with ``CONFIG_SECURITY_LANDLOCK=y``. Landlock must also be enabled at boot
504508
time as the other security modules. The list of security modules enabled by
@@ -507,11 +511,52 @@ contains ``CONFIG_LSM=landlock,[...]`` with ``[...]`` as the list of other
507511
potentially useful security modules for the running system (see the
508512
``CONFIG_LSM`` help).
509513

514+
Boot time configuration
515+
-----------------------
516+
510517
If the running kernel does not have ``landlock`` in ``CONFIG_LSM``, then we can
511-
still enable it by adding ``lsm=landlock,[...]`` to
512-
Documentation/admin-guide/kernel-parameters.rst thanks to the bootloader
518+
enable Landlock by adding ``lsm=landlock,[...]`` to
519+
Documentation/admin-guide/kernel-parameters.rst in the boot loader
513520
configuration.
514521

522+
For example, if the current built-in configuration is:
523+
524+
.. code-block:: console
525+
526+
$ zgrep -h "^CONFIG_LSM=" "/boot/config-$(uname -r)" /proc/config.gz 2>/dev/null
527+
CONFIG_LSM="lockdown,yama,integrity,apparmor"
528+
529+
...and if the cmdline doesn't contain ``landlock`` either:
530+
531+
.. code-block:: console
532+
533+
$ sed -n 's/.*\(\<lsm=\S\+\).*/\1/p' /proc/cmdline
534+
lsm=lockdown,yama,integrity,apparmor
535+
536+
...we should configure the boot loader to set a cmdline extending the ``lsm``
537+
list with the ``landlock,`` prefix::
538+
539+
lsm=landlock,lockdown,yama,integrity,apparmor
540+
541+
After a reboot, we can check that Landlock is up and running by looking at
542+
kernel logs:
543+
544+
.. code-block:: console
545+
546+
# dmesg | grep landlock || journalctl -kb -g landlock
547+
[ 0.000000] Command line: [...] lsm=landlock,lockdown,yama,integrity,apparmor
548+
[ 0.000000] Kernel command line: [...] lsm=landlock,lockdown,yama,integrity,apparmor
549+
[ 0.000000] LSM: initializing lsm=lockdown,capability,landlock,yama,integrity,apparmor
550+
[ 0.000000] landlock: Up and running.
551+
552+
The kernel may be configured at build time to always load the ``lockdown`` and
553+
``capability`` LSMs. In that case, these LSMs will appear at the beginning of
554+
the ``LSM: initializing`` log line as well, even if they are not configured in
555+
the boot loader.
556+
557+
Network support
558+
---------------
559+
515560
To be able to explicitly allow TCP operations (e.g., adding a network rule with
516561
``LANDLOCK_ACCESS_NET_BIND_TCP``), the kernel must support TCP
517562
(``CONFIG_INET=y``). Otherwise, sys_landlock_add_rule() returns an

samples/landlock/sandboxer.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: BSD-3-Clause
22
/*
3-
* Simple Landlock sandbox manager able to launch a process restricted by a
4-
* user-defined filesystem access control policy.
3+
* Simple Landlock sandbox manager able to execute a process restricted by
4+
* user-defined file system and network access control policies.
55
*
66
* Copyright © 2017-2020 Mickaël Salaün <[email protected]>
77
* Copyright © 2020 ANSSI
@@ -120,9 +120,11 @@ static int populate_ruleset_fs(const char *const env_var, const int ruleset_fd,
120120
if (path_beneath.parent_fd < 0) {
121121
fprintf(stderr, "Failed to open \"%s\": %s\n",
122122
path_list[i], strerror(errno));
123-
goto out_free_name;
123+
continue;
124124
}
125125
if (fstat(path_beneath.parent_fd, &statbuf)) {
126+
fprintf(stderr, "Failed to stat \"%s\": %s\n",
127+
path_list[i], strerror(errno));
126128
close(path_beneath.parent_fd);
127129
goto out_free_name;
128130
}
@@ -227,7 +229,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
227229
ENV_FS_RO_NAME, ENV_FS_RW_NAME, ENV_TCP_BIND_NAME,
228230
ENV_TCP_CONNECT_NAME, argv[0]);
229231
fprintf(stderr,
230-
"Launch a command in a restricted environment.\n\n");
232+
"Execute a command in a restricted environment.\n\n");
231233
fprintf(stderr,
232234
"Environment variables containing paths and ports "
233235
"each separated by a colon:\n");
@@ -248,7 +250,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
248250
ENV_TCP_CONNECT_NAME);
249251
fprintf(stderr,
250252
"\nexample:\n"
251-
"%s=\"/bin:/lib:/usr:/proc:/etc:/dev/urandom\" "
253+
"%s=\"${PATH}:/lib:/usr:/proc:/etc:/dev/urandom\" "
252254
"%s=\"/dev/null:/dev/full:/dev/zero:/dev/pts:/tmp\" "
253255
"%s=\"9418\" "
254256
"%s=\"80:443\" "
@@ -383,6 +385,7 @@ int main(const int argc, char *const argv[], char *const *const envp)
383385

384386
cmd_path = argv[1];
385387
cmd_argv = argv + 1;
388+
fprintf(stderr, "Executing the sandboxed command...\n");
386389
execvpe(cmd_path, cmd_argv, envp);
387390
fprintf(stderr, "Failed to execute \"%s\": %s\n", cmd_path,
388391
strerror(errno));

security/landlock/.kunitconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CONFIG_KUNIT=y
2+
CONFIG_SECURITY=y
3+
CONFIG_SECURITY_LANDLOCK=y
4+
CONFIG_SECURITY_LANDLOCK_KUNIT_TEST=y

security/landlock/Kconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@ config SECURITY_LANDLOCK
2020
If you are unsure how to answer this question, answer N. Otherwise,
2121
you should also prepend "landlock," to the content of CONFIG_LSM to
2222
enable Landlock at boot time.
23+
24+
config SECURITY_LANDLOCK_KUNIT_TEST
25+
bool "KUnit tests for Landlock" if !KUNIT_ALL_TESTS
26+
depends on KUNIT=y
27+
depends on SECURITY_LANDLOCK
28+
default KUNIT_ALL_TESTS
29+
help
30+
Build KUnit tests for Landlock.
31+
32+
See the KUnit documentation in Documentation/dev-tools/kunit
33+
34+
Run all KUnit tests for Landlock with:
35+
./tools/testing/kunit/kunit.py run --kunitconfig security/landlock
36+
37+
If you are unsure how to answer this question, answer N.

security/landlock/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o
22

33
landlock-y := setup.o syscalls.o object.o ruleset.o \
4-
cred.o ptrace.o fs.o
4+
cred.o task.o fs.o
55

66
landlock-$(CONFIG_INET) += net.o

security/landlock/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717

1818
#define pr_fmt(fmt) LANDLOCK_NAME ": " fmt
1919

20+
#define BIT_INDEX(bit) HWEIGHT(bit - 1)
21+
2022
#endif /* _SECURITY_LANDLOCK_COMMON_H */

0 commit comments

Comments
 (0)