Landlock LSM
Subsystems (22)
Mickaël Salaün
maintainerv17 cover Landlock LSM
Hi,
This new patch series brings some improvements and add new tests:
Use smaller userspace structures (attributes) to save space, and check at built time that every attribute don't contain hole and are 8-bits aligned.
Allow enforcement of empty ruleset, which enables deny-all policies (useful for strict sandboxes).
I found that UML may not keep the same internal struct inode for an open file. Because the Landlock filesystem access-control relies on internal kernel states, special architectures such as UML can't support Landlock. Add a new ARCH_EPHEMERAL_STATES to identify such architectures.
Add a size_attr_features field to struct landlock_attr_features for self-introspection
Switch syscall attribute pointer and size arguments to follow similar syscalls argument order (e.g. bpf, clone3, openat2).
The SLOC count is 1288 for security/landlock/ and 1740 for tools/testing/selftest/landlock/ . Test coverage for security/landlock/ is 93.6% of lines. The code not covered only deals with internal kernel errors (e.g. memory allocation) and race conditions.
The compiled documentation is available here:
https://landlock.io/linux-doc/landlock-v17/security/landlock/index.html
This series can be applied on top of v5.7-rc5. This can be tested with CONFIG_SECURITY_LANDLOCK and CONFIG_SAMPLE_LANDLOCK. This patch series can be found in a Git repository here:
https://github.com/landlock-lsm/linux/commits/landlock-v17
I would really appreciate constructive comments on this patch series.
# Landlock LSM
The goal of Landlock is to enable to restrict ambient rights (e.g. global filesystem access) for a set of processes. Because Landlock is a stackable LSM [2], it makes possible to create safe security sandboxes as new security layers in addition to the existing system-wide access-controls. This kind of sandbox is expected to help mitigate the security impact of bugs or unexpected/malicious behaviors in user-space applications. Landlock empowers any process, including unprivileged ones, to securely restrict themselves.
Landlock is inspired by seccomp-bpf but instead of filtering syscalls and their raw arguments, a Landlock rule can restrict the use of kernel objects like file hierarchies, according to the kernel semantic. Landlock also takes inspiration from other OS sandbox mechanisms: XNU Sandbox, FreeBSD Capsicum or OpenBSD Pledge/Unveil.
Previous version:
https://lore.kernel.org/lkml/[email protected]/
[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
Regards,
Mickaël Salaün (10):
landlock: Add object management
landlock: Add ruleset and domain management
landlock: Set up the security framework and manage credentials
landlock: Add ptrace restrictions
fs,landlock: Support filesystem access-control
landlock: Add syscall implementation
arch: Wire up landlock() syscall
selftests/landlock: Add initial tests samples/landlock: Add a sandbox manager example
landlock: Add user and kernel documentation
Documentation/security/index.rst | 1 + Documentation/security/landlock/index.rst | 18 + Documentation/security/landlock/kernel.rst | 69 + Documentation/security/landlock/user.rst | 268 +++ MAINTAINERS | 12 + arch/Kconfig | 7 + arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 + arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/um/Kconfig | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + fs/super.c | 2 + include/linux/fs.h | 5 + include/linux/landlock.h | 22 + include/linux/syscalls.h | 3 + include/uapi/asm-generic/unistd.h | 4 +- include/uapi/linux/landlock.h | 302 +++ kernel/sys_ni.c | 3 + samples/Kconfig | 7 + samples/Makefile | 1 + samples/landlock/.gitignore | 1 + samples/landlock/Makefile | 15 + samples/landlock/sandboxer.c | 228 +++ security/Kconfig | 11 +- security/Makefile | 2 + security/landlock/Kconfig | 18 + security/landlock/Makefile | 4 + security/landlock/common.h | 20 + security/landlock/cred.c | 46 + security/landlock/cred.h | 58 + security/landlock/fs.c | 601 ++++++ security/landlock/fs.h | 42 + security/landlock/object.c | 66 + security/landlock/object.h | 91 + security/landlock/ptrace.c | 120 ++ security/landlock/ptrace.h | 14 + security/landlock/ruleset.c | 342 ++++ security/landlock/ruleset.h | 161 ++ security/landlock/setup.c | 39 + security/landlock/setup.h | 18 + security/landlock/syscall.c | 532 +++++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/landlock/.gitignore | 2 + tools/testing/selftests/landlock/Makefile | 29 + tools/testing/selftests/landlock/base_test.c | 170 ++ tools/testing/selftests/landlock/common.h | 108 + tools/testing/selftests/landlock/config | 5 + tools/testing/selftests/landlock/fs_test.c | 1729 +++++++++++++++++ .../testing/selftests/landlock/ptrace_test.c | 293 +++ tools/testing/selftests/landlock/true.c | 5 + 64 files changed, 5509 insertions(+), 7 deletions(-) create mode 100644 Documentation/security/landlock/index.rst create mode 100644 Documentation/security/landlock/kernel.rst create mode 100644 Documentation/security/landlock/user.rst create mode 100644 include/linux/landlock.h create mode 100644 include/uapi/linux/landlock.h create mode 100644 samples/landlock/.gitignore create mode 100644 samples/landlock/Makefile create mode 100644 samples/landlock/sandboxer.c create mode 100644 security/landlock/Kconfig create mode 100644 security/landlock/Makefile create mode 100644 security/landlock/common.h create mode 100644 security/landlock/cred.c create mode 100644 security/landlock/cred.h create mode 100644 security/landlock/fs.c create mode 100644 security/landlock/fs.h create mode 100644 security/landlock/object.c create mode 100644 security/landlock/object.h create mode 100644 security/landlock/ptrace.c create mode 100644 security/landlock/ptrace.h create mode 100644 security/landlock/ruleset.c create mode 100644 security/landlock/ruleset.h create mode 100644 security/landlock/setup.c create mode 100644 security/landlock/setup.h create mode 100644 security/landlock/syscall.c create mode 100644 tools/testing/selftests/landlock/.gitignore create mode 100644 tools/testing/selftests/landlock/Makefile create mode 100644 tools/testing/selftests/landlock/base_test.c create mode 100644 tools/testing/selftests/landlock/common.h create mode 100644 tools/testing/selftests/landlock/config create mode 100644 tools/testing/selftests/landlock/fs_test.c create mode 100644 tools/testing/selftests/landlock/ptrace_test.c create mode 100644 tools/testing/selftests/landlock/true.c
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 1/10 landlock: Add object management
A Landlock object enables to identify a kernel object (e.g. an inode). A Landlock rule is a set of access rights allowed on an object. Rules are grouped in rulesets that may be tied to a set of processes (i.e. subjects) to enforce a scoped access-control (i.e. a domain).
Because Landlock's goal is to empower any process (especially unprivileged ones) to sandbox themselves, we can't rely on a system-wide object identification such as file extended attributes. Indeed, we need innocuous, composable and modular access-controls.
The main challenge with these constraints is to identify kernel objects while this identification is useful (i.e. when a security policy makes use of this object). But this identification data should be freed once no policy is using it. This ephemeral tagging should not and may not be written in the filesystem. We then need to manage the lifetime of a rule according to the lifetime of its object. To avoid a global lock, this implementation make use of RCU and counters to safely reference objects.
A following commit uses this generic object management for inodes.
---
Changes since v14:
* Simplify the object, rule and ruleset management at the expense of a less aggressive memory freeing (contributed by Jann Horn, with additional modifications):
- Remove object->list aggregating the rules tied to an object.
- Remove landlock_get_object(), landlock_drop_object(), {get,put}_object_cleaner() and landlock_rule_is_disabled().
- Rewrite landlock_put_object() to use a more simple mechanism (no tricky RCU).
- Replace enum landlock_object_type and landlock_release_object() with
landlock_object_underops->release()
- Adjust unions and Sparse annotations.
Cf. https://lore.kernel.org/lkml/CAG48ez21bEn0wL1bbmTiiu8j9jP5iEWtHOwz4tURUJ+ki0ydYw@mail.gmail.com/
* Merge struct landlock_rule into landlock_ruleset_elem to simplify the
rule management.
* Constify variables.
* Improve kernel documentation.
* Cosmetic variable renames.
* Remove the "default" in the Kconfig (suggested by Jann Horn).
* Only use refcount_inc() through getter helpers.
* Update Kconfig description.
Changes since v13:
* New dedicated implementation, removing the need for eBPF.
Previous changes:
https://lore.kernel.org/lkml/[email protected]/
--- MAINTAINERS | 10 +++++ security/Kconfig | 1 + security/Makefile | 2 + security/landlock/Kconfig | 18 ++++++++ security/landlock/Makefile | 3 ++ security/landlock/object.c | 66 +++++++++++++++++++++++++++ security/landlock/object.h | 91 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 191 insertions(+) create mode 100644 security/landlock/Kconfig create mode 100644 security/landlock/Makefile create mode 100644 security/landlock/object.c create mode 100644 security/landlock/object.h
MAINTAINERS +10 -0
@@ -9487,6 +9487,16 @@ F: net/core/sock_map.c F: net/ipv4/tcp_bpf.c F: net/ipv4/udp_bpf.c +LANDLOCK SECURITY MODULE +M: Mickaël Salaün <[email protected]> +L: [email protected] +S: Supported +W: https://landlock.io +T: git https://github.com/landlock-lsm/linux.git +F: security/landlock/ +K: landlock +K: LANDLOCK + LANTIQ / INTEL Ethernet drivers M: Hauke Mehrtens <[email protected]> L: [email protected]
security/Kconfig +1 -0
@@ -238,6 +238,7 @@ source "security/loadpin/Kconfig" source "security/yama/Kconfig" source "security/safesetid/Kconfig" source "security/lockdown/Kconfig" +source "security/landlock/Kconfig" source "security/integrity/Kconfig"
security/Makefile +2 -0
@@ -13,6 +13,7 @@ subdir-$(CONFIG_SECURITY_LOADPIN) += loadpin subdir-$(CONFIG_SECURITY_SAFESETID) += safesetid subdir-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown subdir-$(CONFIG_BPF_LSM) += bpf +subdir-$(CONFIG_SECURITY_LANDLOCK) += landlock # always enable default capabilities obj-y += commoncap.o
@@ -30,6 +31,7 @@ obj-$(CONFIG_SECURITY_YAMA) += yama/ obj-$(CONFIG_SECURITY_LOADPIN) += loadpin/ obj-$(CONFIG_SECURITY_SAFESETID) += safesetid/ obj-$(CONFIG_SECURITY_LOCKDOWN_LSM) += lockdown/ +obj-$(CONFIG_SECURITY_LANDLOCK) += landlock/ obj-$(CONFIG_CGROUP_DEVICE) += device_cgroup.o obj-$(CONFIG_BPF_LSM) += bpf/
security/landlock/Kconfig new file +18 -0
@@ -0,0 +1,18 @@ +# SPDX-License-Identifier: GPL-2.0-only + +config SECURITY_LANDLOCK + bool "Landlock support" + depends on SECURITY + select SECURITY_PATH + help + Landlock is a safe sandboxing mechanism which enables processes to + restrict themselves (and their future children) by gradually + enforcing tailored access control policies. A security policy is a + set of access rights (e.g. open a file in read-only, make a + directory) tied to a file hierarchy. The configuration can be set by + any processes, including unprivileged ones, thanks to the landlock() + system call. + + See Documentation/security/landlock/ for further information. + + If you are unsure how to answer this question, answer N.
security/landlock/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o + +landlock-y := object.o
security/landlock/object.c new file +66 -0
66 lines not on this page · raw message
security/landlock/object.h new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 2/10 landlock: Add ruleset and domain management
In reply to Mickaël SalaünA Landlock ruleset is mainly a red-black tree with Landlock rules as nodes. This enables quick update and lookup to match a requested access e.g., to a file. A ruleset is usable through a dedicated file descriptor (cf. following commit implementing the syscall) which enables a process to create and populate a ruleset with new rules.
A domain is a ruleset tied to a set of processes. This group of rules define the security policy enforced on these processes and their future children. A domain can transition to a new domain which is the intersection of all its constraints and those of a ruleset provided by the current process. This modification only impact the current process. This means that a process can only gain more constraints (i.e. lose accesses) over time.
---
Changes since v16:
* Allow enforcement of empty ruleset, which enables deny-all policies.
Changes since v15:
* Replace layer_levels and layer_depth with a bitfield of layers, cf. filesystem commit.
* Rename the LANDLOCK_ACCESS_FS_{UNLINK,RMDIR} with LANDLOCK_ACCESS_FS_REMOVE_{FILE,DIR} because it makes sense to use them for the action of renaming a file or a directory, which may lead to the removal of the source file or directory. Removes the LANDLOCK_ACCESS_FS_{LINK_TO,RENAME_FROM,RENAME_TO} which are now replaced with LANDLOCK_ACCESS_FS_REMOVE_{FILE,DIR} and LANDLOCK_ACCESS_FS_MAKE_* .
* Update the documentation accordingly and highlight how the access rights are taken into account.
* Change nb_rules from atomic_t to u32 because it is not use anymore by show_fdinfo().
* Add safeguard for level variables types.
* Check max number of rules.
* Replace struct landlock_access (self and beneath bitfields) with one bitfield.
* Remove useless variable.
* Add comments.
Changes since v14:
* Simplify the object, rule and ruleset management at the expense of a
less aggressive memory freeing (contributed by Jann Horn, with
additional modifications):
- Make a domain immutable (remove the opportunistic cleaning).
- Remove RCU pointers.
- Merge struct landlock_ref and struct landlock_ruleset_elem into
landlock_rule: get ride of rule's RCU.
- Adjust union.
- Remove the landlock_insert_rule() check about a new object with the
same address as a previously disabled one, because it is not
possible to disable a rule anymore.
Cf. https://lore.kernel.org/lkml/CAG48ez21bEn0wL1bbmTiiu8j9jP5iEWtHOwz4tURUJ+ki0ydYw@mail.gmail.com/
* Fix nested domains by implementing a notion of layer level and depth:
- Update landlock_insert_rule() to manage such layers.
- Add an inherit_ruleset() helper to properly create a new domain.
- Rename landlock_find_access() to landlock_find_rule() and return a
full rule reference.
- Add a layer_level and a layer_depth fields to struct landlock_rule.
- Add a top_layer_level field to struct landlock_ruleset.
* Remove access rights that may be required for FD-only requests:
truncate, getattr, lock, chmod, chown, chgrp, ioctl. This will be
handle in a future evolution of Landlock, but right now the goal is to
lighten the code to ease review.
* Remove LANDLOCK_ACCESS_FS_OPEN and rename
LANDLOCK_ACCESS_FS_{READ,WRITE} with a FILE suffix.
* Rename LANDLOCK_ACCESS_FS_READDIR to match the *_FILE pattern.
* Remove LANDLOCK_ACCESS_FS_MAP which was useless.
* Fix memory leak in put_hierarchy() (reported by Jann Horn).
* Fix user-after-free and rename free_ruleset() (reported by Jann Horn).
* Replace the for loops with rbtree_postorder_for_each_entry_safe().
* Constify variables.
* Only use refcount_inc() through getter helpers.
* Change Landlock_insert_ruleset_access() to
Landlock_insert_ruleset_rule().
* Rename landlock_put_ruleset_enqueue() to landlock_put_ruleset_deferred().
* Improve kernel documentation and add a warning about the unhandled
access/syscall families.
* Move ABI check to syscall.c .
Changes since v13:
* New implementation, inspired by the previous inode eBPF map, but agnostic to the underlying kernel object.
Previous changes:
https://lore.kernel.org/lkml/[email protected]/
--- MAINTAINERS | 1 + include/uapi/linux/landlock.h | 78 ++++++++ security/landlock/Makefile | 2 +- security/landlock/ruleset.c | 342 ++++++++++++++++++++++++++++++++++ security/landlock/ruleset.h | 161 ++++++++++++++++ 5 files changed, 583 insertions(+), 1 deletion(-) create mode 100644 include/uapi/linux/landlock.h create mode 100644 security/landlock/ruleset.c create mode 100644 security/landlock/ruleset.h
MAINTAINERS +1 -0
@@ -9493,6 +9493,7 @@ L: [email protected] S: Supported W: https://landlock.io T: git https://github.com/landlock-lsm/linux.git +F: include/uapi/linux/landlock.h F: security/landlock/ K: landlock K: LANDLOCK
include/uapi/linux/landlock.h new file +78 -0
78 lines not on this page · raw message
security/landlock/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o -landlock-y := object.o +landlock-y := object.o ruleset.o
security/landlock/ruleset.c new file +342 -0
342 lines not on this page · raw message
security/landlock/ruleset.h new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.26.2
James Morris
maintainerRe: [PATCH v17 02/10] landlock: Add ruleset and domain management
Quoted 8 lines · Mickaël Salaün
+ * .. warning::
+ *+ * It is currently not possible to restrict some file-related actions + * accessible through these syscall families: :manpage:`chdir(2)`, + * :manpage:`truncate(2)`, :manpage:`stat(2)`, :manpage:`flock(2)`, + * :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`setxattr(2)`, + * :manpage:`ioctl(2)`, :manpage:`fcntl(2)`. + * Future Landlock evolutions will enable to restrict them.
I have to wonder how useful Landlock will be without more coverage per the above.
It would be helpful if you could outline a threat model for this initial version, so people can get an idea of what kind of useful protection may be gained from it.
Are there any distros or other major users who are planning on enabling or at least investigating Landlock?
Do you have any examples of a practical application of this scheme?
Signature · 2 lines
James Morris <[email protected]>
Mickaël Salaün
maintainerRe: [PATCH v17 02/10] landlock: Add ruleset and domain management
Quoted 11 lines · James Morris
Quoted 8 lines · Mickaël Salaün
+ * .. warning::
+ *+ * It is currently not possible to restrict some file-related actions + * accessible through these syscall families: :manpage:`chdir(2)`, + * :manpage:`truncate(2)`, :manpage:`stat(2)`, :manpage:`flock(2)`, + * :manpage:`chmod(2)`, :manpage:`chown(2)`, :manpage:`setxattr(2)`, + * :manpage:`ioctl(2)`, :manpage:`fcntl(2)`. + * Future Landlock evolutions will enable to restrict them.
Quoted 2 lines
I have to wonder how useful Landlock will be without more coverage per the above.
This is the result of previous discussions (on mailing lists and conferences) to minimize the code of Landlock to ease review. There is also network and other subsystems which are not covered, the same way other LSMs may not cover everything. However, Landlock is designed to be extensible without breaking user space, so extending this access-control will not be a problem. Previous versions of this patch series handled much more.
Moreover, we can compare the current situation with seccomp. Indeed, seccomp only enables to restrict system calls according to their number and their raw arguments. seccomp is designed to limit the attack surface of the kernel but it is also used to remove ways to access kernel resources. Application developers willing to sandbox their products are already using seccomp but there is limitations (e.g. file access control). Landlock addresses such limitations, which improves the current situation.
We can also view seccomp as a complementary solution to the current limitations of Landlock. Indeed, seccomp filters can block or restrict the use of syscall families which may not be currently handled by Landlock.
Quoted 4 lines
It would be helpful if you could outline a threat model for this initial version, so people can get an idea of what kind of useful protection may be gained from it.
The main threat model may be seen as protecting from vulnerable (i.e. malicious) code. But because Landlock policies are defined by application developers, they also define their own threat model.
Quoted 3 lines
Are there any distros or other major users who are planning on enabling or at least investigating Landlock?
I think the question should be: is there any distros which are not interested to improve the security of their users? :) Landlock is mainly designed for application developers, and most Linux distros rely on applications which are not developed by themselves.
Some hardened distros such as CLIP OS and Chrome OS are interested to extend the security of the whole system with tailored sandboxing (e.g. internal and critical services, security brokers). For example, Chrome OS folks investigated with a previous version of Landlock:
https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel-next/+/658517/
I'm sure there is other tailored distros which will be interested once Landlock will be upstream (e.g. Tails, Qubes OS, Subgraph OS, etc.).
Quoted 2 lines
Do you have any examples of a practical application of this scheme?
We can start with applications with builtin sandboxing, like web browsers, web services, email services, SSH, etc. There is also all system services handled by an init system which provides security features (e.g. systemd). There is also the security sandbox tools (e.g. Minijail [1], Firejail [2], nsjail [3], Flatpak [4], etc.). And finally, security-oriented APIs such as Sandboxed API [5]. Most of them should welcome new Linux sandboxing features provided by Landlock.
[1] https://android.googlesource.com/platform/external/minijail
[2] https://firejail.wordpress.com/
[3] https://nsjail.dev/
[4] https://flatpak.org/
[5] https://github.com/google/sandboxed-api
Mickaël Salaün
maintainerPATCH v17 3/10 landlock: Set up the security framework and manage credentials
In reply to Mickaël SalaünA process credentials point to a Landlock domain, which is underneath implemented with a ruleset. In the following commits, this domain is used to check and enforce the ptrace and filesystem security policies. A domain is inherited from a parent to its child the same way a thread inherits a seccomp policy.
---
Changes since v15:
* Optimize landlocked() for current thread.
* Display the greeting message when everything is initialized.
Changes since v14:
* Uses pr_fmt from common.h .
* Constify variables.
* Remove useless NULL initialization.
Changes since v13:
* totally get ride of the seccomp dependency
* only keep credential management and LSM setup.
Previous changes:
https://lore.kernel.org/lkml/20191104172146.30797-4-mic-WFhQfpSGs3bR7s880joybQ@public.gmane.org/
--- security/Kconfig | 10 +++---- security/landlock/Makefile | 3 +- security/landlock/common.h | 20 +++++++++++++ security/landlock/cred.c | 46 ++++++++++++++++++++++++++++++ security/landlock/cred.h | 58 ++++++++++++++++++++++++++++++++++++++ security/landlock/setup.c | 31 ++++++++++++++++++++ security/landlock/setup.h | 16 +++++++++++ 7 files changed, 178 insertions(+), 6 deletions(-) create mode 100644 security/landlock/common.h create mode 100644 security/landlock/cred.c create mode 100644 security/landlock/cred.h create mode 100644 security/landlock/setup.c create mode 100644 security/landlock/setup.h
security/Kconfig +5 -5
@@ -278,11 +278,11 @@ endchoice config LSM string "Ordered list of enabled LSMs" - default "lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK - default "lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR - default "lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO - default "lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC - default "lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" + default "landlock,lockdown,yama,loadpin,safesetid,integrity,smack,selinux,tomoyo,apparmor,bpf" if DEFAULT_SECURITY_SMACK + default "landlock,lockdown,yama,loadpin,safesetid,integrity,apparmor,selinux,smack,tomoyo,bpf" if DEFAULT_SECURITY_APPARMOR + default "landlock,lockdown,yama,loadpin,safesetid,integrity,tomoyo,bpf" if DEFAULT_SECURITY_TOMOYO + default "landlock,lockdown,yama,loadpin,safesetid,integrity,bpf" if DEFAULT_SECURITY_DAC + default "landlock,lockdown,yama,loadpin,safesetid,integrity,selinux,smack,tomoyo,apparmor,bpf" help A comma-separated list of LSMs, in initialization order. Any LSMs left off this list will be ignored. This can be
security/landlock/Makefile +2 -1
@@ -1,3 +1,4 @@ obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o -landlock-y := object.o ruleset.o +landlock-y := setup.o object.o ruleset.o \ + cred.o
security/landlock/common.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Landlock LSM - Common constants and helpers +* +* Copyright © 2016-2020 Mickaël Salaün <[email protected]> +* Copyright © 2018-2020 ANSSI +*/ + +#ifndef _SECURITY_LANDLOCK_COMMON_H +#define _SECURITY_LANDLOCK_COMMON_H + +#define LANDLOCK_NAME "landlock" + +#ifdef pr_fmt +#undef pr_fmt +#endif + +#define pr_fmt (fmt) LANDLOCK_NAME ": " fmt + +#endif /* _SECURITY_LANDLOCK_COMMON_H */
security/landlock/cred.c new file +46 -0
46 lines not on this page · raw message
security/landlock/cred.h new file +58 -0
58 lines not on this page · raw message
security/landlock/setup.c new file +31 -0
@@ -0,0 +1,31 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Landlock LSM - Security framework setup +* +* Copyright © 2016-2020 Mickaël Salaün <[email protected]> +* Copyright © 2018-2020 ANSSI +*/ + +#include <linux/init.h> +#include <linux/lsm_hooks.h> + +#include "common.h" +#include "cred.h" +#include "setup.h" + +struct lsm_blob_sizes landlock_blob_sizes __lsm_ro_after_init = { + .lbs_cred =sizeof (struct landlock_cred_security ), +}; + +static int __init landlock_init (void ) +{ +landlock_add_hooks_cred (); +pr_info ("Up and running.\n" ); +return 0 ; +} + +DEFINE_LSM (LANDLOCK_NAME ) = { + .name =LANDLOCK_NAME , + .init = landlock_init, + .blobs = &landlock_blob_sizes, +};
security/landlock/setup.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Landlock LSM - Security framework setup +* +* Copyright © 2016-2020 Mickaël Salaün <[email protected]> +* Copyright © 2018-2020 ANSSI +*/ + +#ifndef _SECURITY_LANDLOCK_SETUP_H +#define _SECURITY_LANDLOCK_SETUP_H + +#include <linux/lsm_hooks.h> + +extern struct lsm_blob_sizes landlock_blob_sizes; + +#endif /* _SECURITY_LANDLOCK_SETUP_H */
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 4/10 landlock: Add ptrace restrictions
In reply to Mickaël SalaünUsing ptrace(2) and related debug features on a target process can lead to a privilege escalation. Indeed, ptrace(2) can be used by an attacker to impersonate another task and to remain undetected while performing malicious activities. Thanks to ptrace_may_access(), various part of the kernel can check if a tracer is more privileged than a tracee.
A landlocked process has fewer privileges than a non-landlocked process and must then be subject to additional restrictions when manipulating processes. To be allowed to use ptrace(2) and related syscalls on a target process, a landlocked process must have a subset of the target process' rules (i.e. the tracee must be in a sub-domain of the tracer).
---
Changes since v14:
* Constify variables.
Changes since v13:
* Make the ptrace restriction mandatory, like in the v10.
* Remove the eBPF dependency.
Previous changes:
https://lore.kernel.org/lkml/20191104172146.30797-5-mic-WFhQfpSGs3bR7s880joybQ@public.gmane.org/
--- security/landlock/Makefile | 2 +- security/landlock/ptrace.c | 120 +++++++++++++++++++++++++++++++++++++ security/landlock/ptrace.h | 14 +++++ security/landlock/setup.c | 2 + 4 files changed, 137 insertions(+), 1 deletion(-) create mode 100644 security/landlock/ptrace.c create mode 100644 security/landlock/ptrace.h
security/landlock/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o landlock-y := setup.o object.o ruleset.o \ - cred.o + cred.o ptrace.o
security/landlock/ptrace.c new file +120 -0
120 lines not on this page · raw message
security/landlock/ptrace.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Landlock LSM - Ptrace hooks +* +* Copyright © 2017-2019 Mickaël Salaün <[email protected]> +* Copyright © 2019 ANSSI +*/ + +#ifndef _SECURITY_LANDLOCK_PTRACE_H +#define _SECURITY_LANDLOCK_PTRACE_H + +__init void landlock_add_hooks_ptrace (void ); + +#endif /* _SECURITY_LANDLOCK_PTRACE_H */
security/landlock/setup.c +2 -0
@@ -11,6 +11,7 @@#include "common.h" #include "cred.h" +#include "ptrace.h" #include "setup.h" struct lsm_blob_sizes landlock_blob_sizes __lsm_ro_after_init = {
@@ -20,6 +21,7 @@ struct lsm_blob_sizes landlock_blob_sizes __lsm_ro_after_init = {static int __init landlock_init (void ) {landlock_add_hooks_cred (); +landlock_add_hooks_ptrace ();pr_info ("Up and running.\n" );return 0 ; }
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 5/10 fs,landlock: Support filesystem access-control
In reply to Mickaël SalaünThanks to the Landlock objects and ruleset, it is possible to identify inodes according to a process's domain. To enable an unprivileged process to express a file hierarchy, it first needs to open a directory (or a file) and pass this file descriptor to the kernel through landlock(2). When checking if a file access request is allowed, we walk from the requested dentry to the real root, following the different mount layers. The access to each "tagged" inodes are collected according to their rule layer level, and ANDed to create access to the requested file hierarchy. This makes possible to identify a lot of files without tagging every inodes nor modifying the filesystem, while still following the view and understanding the user has from the filesystem.
Add a new ARCH_EPHEMERAL_STATES for UML because it currently does not keep the same struct inodes for the same inodes whereas these inodes are in use.
---
Changes since v16:
* Add ARCH_EPHEMERAL_STATES and enable it for UML.
Changes since v15:
* Replace layer_levels and layer_depth with a bitfield of layers: this enables to properly manage superset and subset of access rights, whatever their order in the stack of layers.
Cf. https://lore.kernel.org/lkml/[email protected]/
* Allow to open pipes and similar special files through /proc/self/fd/.
* Properly handle internal filesystems such as nsfs: always allow these kind of roots because disconnected path cannot be evaluated.
* Remove the LANDLOCK_ACCESS_FS_LINK_TO and LANDLOCK_ACCESS_FS_RENAME_{TO,FROM}, but use the LANDLOCK_ACCESS_FS_REMOVE_{FILE,DIR} and LANDLOCK_ACCESS_FS_MAKE_* instead. Indeed, it is not possible for now (and not really useful) to express the semantic of a source and a destination.
* Check access rights to remove a directory or a file with rename(2).
* Forbid reparenting when linking or renaming. This is needed to easily protect against possible privilege escalation by changing the place of a file or directory in relation to an enforced access policy (from the set of layers). This will be relaxed in the future.
* Update hooks to take into account replacement of the object's self and beneath access bitfields with one. Simplify the code.
* Check file related access rights.
* Check d_is_negative() instead of !d_backing_inode() in check_access_path_continue(), and continue the path walk while there is no mapped inode e.g., with rename(2).
* Check private inode in check_access_path().
* Optimize get_file_access() when dealing with a directory.
* Add missing atomic.h .
Changes since v14:
* Simplify the object, rule and ruleset management at the expense of a
less aggressive memory freeing (contributed by Jann Horn, with
additional modifications):
- Rewrite release_inode() to use inode->sb->s_landlock_inode_refs.
- Remove useless checks in landlock_release_inodes(), clean object
pointer according to the new struct landlock_object and wait for all
iput() to complete.
- Rewrite get_inode_object() according to the new struct
landlock_object. If there is a race-condition when cleaning up an
object, we retry until the concurrent thread finished the object
cleaning.
Cf. https://lore.kernel.org/lkml/CAG48ez21bEn0wL1bbmTiiu8j9jP5iEWtHOwz4tURUJ+ki0ydYw@mail.gmail.com/
* Fix nested domains by implementing a notion of layer level and depth:
- Check for matching level ranges when walking through a file path.
- Only allow access if every layer granted the access request.
* Handles files without mount points (e.g. pipes).
* Hardens path walk by checking inode pointer values.
* Prefetches d_parent when walking to the root directory.
* Remove useless inode_alloc_security hook() (suggested by Jann Horn):
already initialized by lsm_inode_alloc().
* Remove the inode_free_security hook.
* Remove access checks that may be required for FD-only requests:
truncate, getattr, lock, chmod, chown, chgrp, ioctl. This will be
handle in a future evolution of Landlock, but right now the goal is to
lighten the code to ease review.
* Constify variables.
* Move ABI checks into syscall.c .
* Cosmetic variable renames.
Changes since v11:
* Add back, revamp and make a fully working filesystem access-control based on paths and inodes.
* Remove the eBPF dependency.
Previous changes:
https://lore.kernel.org/lkml/[email protected]/
--- MAINTAINERS | 1 + arch/Kconfig | 7 + arch/um/Kconfig | 1 + fs/super.c | 2 + include/linux/fs.h | 5 + include/linux/landlock.h | 22 ++ security/landlock/Kconfig | 2 +- security/landlock/Makefile | 2 +- security/landlock/fs.c | 601 +++++++++++++++++++++++++++++++++++++ security/landlock/fs.h | 42 +++ security/landlock/setup.c | 6 + security/landlock/setup.h | 2 + 12 files changed, 691 insertions(+), 2 deletions(-) create mode 100644 include/linux/landlock.h create mode 100644 security/landlock/fs.c create mode 100644 security/landlock/fs.h
MAINTAINERS +1 -0
@@ -9493,6 +9493,7 @@ L: [email protected] S: Supported W: https://landlock.io T: git https://github.com/landlock-lsm/linux.git +F: include/linux/landlock.h F: include/uapi/linux/landlock.h F: security/landlock/ K: landlock
arch/Kconfig +7 -0
@@ -826,6 +826,13 @@ config COMPAT_32BIT_TIME config ARCH_NO_PREEMPT bool +config ARCH_EPHEMERAL_STATES + def_bool n + help + An arch should select this symbol if it do not keep an internal kernel + state for kernel objects such as inodes, but instead rely on something + else (e.g. the host kernel for an UML kernel). + config ARCH_SUPPORTS_RT bool
arch/um/Kconfig +1 -0
@@ -5,6 +5,7 @@ menu "UML-specific options" config UML bool default y + select ARCH_EPHEMERAL_STATES select ARCH_HAS_KCOV select ARCH_NO_PREEMPT select HAVE_ARCH_AUDITSYSCALL
fs/super.c +2 -0
@@ -34,6 +34,7 @@#include <linux/cleancache.h> #include <linux/fscrypt.h> #include <linux/fsnotify.h> +#include <linux/landlock.h> #include <linux/lockdep.h> #include <linux/user_namespace.h> #include <linux/fs_context.h>
@@ -454,6 +455,7 @@ void generic_shutdown_super(struct super_block *sb)evict_inodes (sb);/* only nonzero refcount inodes can have marks */ fsnotify_sb_delete (sb); +landlock_release_inodes (sb);if (sb->s_dio_done_wq) {destroy_workqueue (sb->s_dio_done_wq);
include/linux/fs.h +5 -0
@@ -1517,6 +1517,11 @@ struct super_block {/* Pending fsnotify inode refs */ atomic_long_t s_fsnotify_inode_refs; +#ifdef CONFIG_SECURITY_LANDLOCK +/* References to Landlock underlying objects */ +atomic_long_t s_landlock_inode_refs; +#endif +/* Being remounted read-only */ int s_readonly_remount;
include/linux/landlock.h new file +22 -0
@@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Landlock LSM - public kernel headers +* +* Copyright © 2016-2019 Mickaël Salaün <[email protected]> +* Copyright © 2018-2019 ANSSI +*/ + +#ifndef _LINUX_LANDLOCK_H +#define _LINUX_LANDLOCK_H + +#include <linux/fs.h> + +#ifdef CONFIG_SECURITY_LANDLOCK +extern void landlock_release_inodes (struct super_block *sb); +#else +static inline void landlock_release_inodes (struct super_block *sb) +{ +} +#endif + +#endif /* _LINUX_LANDLOCK_H */
security/landlock/Kconfig +1 -1
@@ -2,7 +2,7 @@ config SECURITY_LANDLOCK bool "Landlock support" - depends on SECURITY + depends on SECURITY && !ARCH_EPHEMERAL_STATES select SECURITY_PATH help Landlock is a safe sandboxing mechanism which enables processes to
security/landlock/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o landlock-y := setup.o object.o ruleset.o \ - cred.o ptrace.o + cred.o ptrace.o fs.o
security/landlock/fs.c new file +601 -0
601 lines not on this page · raw message
security/landlock/fs.h new file +42 -0
42 lines not on this page · raw message
security/landlock/setup.c +6 -0
@@ -11,17 +11,23 @@#include "common.h" #include "cred.h" +#include "fs.h" #include "ptrace.h" #include "setup.h" +bool landlock_initialized __lsm_ro_after_init = false; + struct lsm_blob_sizes landlock_blob_sizes __lsm_ro_after_init = { .lbs_cred =sizeof (struct landlock_cred_security ), + .lbs_inode =sizeof (struct landlock_inode_security ), };static int __init landlock_init (void ) {landlock_add_hooks_cred ();landlock_add_hooks_ptrace (); +landlock_add_hooks_fs (); + landlock_initialized = true;pr_info ("Up and running.\n" );return 0 ; }
security/landlock/setup.h +2 -0
@@ -11,6 +11,8 @@#include <linux/lsm_hooks.h> +extern bool landlock_initialized; +extern struct lsm_blob_sizes landlock_blob_sizes;#endif /* _SECURITY_LANDLOCK_SETUP_H */
Signature · 1 line
2.26.2
James Morris
maintainerRe: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
include/linux/fs.h struct super_block { · line 1524
Quoted 13 lines · Mickaël Salaün
include/linux/fs.h +5
-0@@ -1517,6 +1517,11 @@ struct super_block {/* Pending fsnotify inode refs */ atomic_long_t s_fsnotify_inode_refs; +#ifdef CONFIG_SECURITY_LANDLOCK +/* References to Landlock underlying objects */ +atomic_long_t s_landlock_inode_refs; +#endif +
This needs to be converted to the LSM API via superblock blob stacking.
See Casey's old patch:
https://lore.kernel.org/linux-security-module/[email protected]/
Signature · 2 lines
James Morris <[email protected]>
Mickaël Salaün
maintainerRe: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
Quoted 19 lines · James Morris
include/linux/fs.h struct super_block { · line 1524
Quoted 13 lines · Mickaël Salaün
include/linux/fs.h +5
-0@@ -1517,6 +1517,11 @@ struct super_block {/* Pending fsnotify inode refs */ atomic_long_t s_fsnotify_inode_refs; +#ifdef CONFIG_SECURITY_LANDLOCK +/* References to Landlock underlying objects */ +atomic_long_t s_landlock_inode_refs; +#endif +This needs to be converted to the LSM API via superblock blob stacking.
Quoted 2 lines
See Casey's old patch:
https://lore.kernel.org/linux-security-module/[email protected]/
s_landlock_inode_refs is quite similar to s_fsnotify_inode_refs, but I can do it once the superblock security blob patch is upstream. Is it a blocker for now? What is the current status of lbs_superblock?
Anyway, we also need to have a call to landlock_release_inodes() in generic_shutdown_super(), which does not fit the LSM framework, and I think it is not an issue. Landlock handling of inodes is quite similar to fsnotify.
Re: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
Quoted 19 lines · Mickaël Salaün
Quoted 18 lines · James Morris
include/linux/fs.h struct super_block { · line 1524
Quoted 13 lines · Mickaël Salaün
include/linux/fs.h +5
-0@@ -1517,6 +1517,11 @@ struct super_block {/* Pending fsnotify inode refs */ atomic_long_t s_fsnotify_inode_refs; +#ifdef CONFIG_SECURITY_LANDLOCK +/* References to Landlock underlying objects */ +atomic_long_t s_landlock_inode_refs; +#endif +This needs to be converted to the LSM API via superblock blob stacking.
Quoted 5 lines
Quoted 2 lines
See Casey's old patch:
https://lore.kernel.org/linux-security-module/[email protected]/
s_landlock_inode_refsis quite similar tos_fsnotify_inode_refs, but I can do it once the superblock security blob patch is upstream. Is it a blocker for now? What is the current status oflbs_superblock?
As no currently stackable modules conflict over the superblock (SELinux and Smack are the existing users) there has been no need to move its management into the infrastructure. The active push for stacking does not (yet) include everything needed for SELinux+Smack. It includes what is needed for SELinux+AppArmor and Smack+AppArmor. That does not include the superblock blob.
You can include a patch in the landlock set that provides infrastructure management of the superblock blob. Feel free to glean it from my proposal.
Quoted 5 lines
Anyway, we also need to have a call to
landlock_release_inodes()ingeneric_shutdown_super(), which does not fit the LSM framework, and I think it is not an issue. Landlock handling of inodes is quite similar to fsnotify.
Mickaël Salaün
maintainerRe: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
Quoted 33 lines · Casey Schaufler
Quoted 19 lines · Mickaël Salaün
Quoted 18 lines · James Morris
include/linux/fs.h struct super_block { · line 1524
Quoted 13 lines · Mickaël Salaün
include/linux/fs.h +5
-0@@ -1517,6 +1517,11 @@ struct super_block {/* Pending fsnotify inode refs */ atomic_long_t s_fsnotify_inode_refs; +#ifdef CONFIG_SECURITY_LANDLOCK +/* References to Landlock underlying objects */ +atomic_long_t s_landlock_inode_refs; +#endif +This needs to be converted to the LSM API via superblock blob stacking.
Quoted 5 lines
Quoted 2 lines
See Casey's old patch:
https://lore.kernel.org/linux-security-module/[email protected]/
s_landlock_inode_refsis quite similar tos_fsnotify_inode_refs, but I can do it once the superblock security blob patch is upstream. Is it a blocker for now? What is the current status oflbs_superblock?As no currently stackable modules conflict over the superblock (SELinux and Smack are the existing users) there has been no need to move its management into the infrastructure. The active push for stacking does not (yet) include everything needed for SELinux+Smack. It includes what is needed for SELinux+AppArmor and Smack+AppArmor. That does not include the superblock blob.
Quoted 2 lines
You can include a patch in the landlock set that provides infrastructure management of the superblock blob. Feel free to glean it from my proposal.
OK, I'll add it to the next series.
James Morris
maintainerRe: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
In reply to Mickaël SalaünQuoted 8 lines · Mickaël Salaün
Quoted 4 lines
This needs to be converted to the LSM API via superblock blob stacking.
See Casey's old patch:
https://lore.kernel.org/linux-security-module/[email protected]/
s_landlock_inode_refsis quite similar tos_fsnotify_inode_refs, but I can do it once the superblock security blob patch is upstream. Is it a blocker for now? What is the current status oflbs_superblock?
Yes it is a blocker. Landlock should not be adding its own functions in core code, it should be using the LSM API (and extending that as needed).
Quoted 4 lines
Anyway, we also need to have a call to
landlock_release_inodes()ingeneric_shutdown_super(), which does not fit the LSM framework, and I think it is not an issue. Landlock handling of inodes is quite similar to fsnotify.
fsnotify is not an LSM.
Signature · 2 lines
James Morris <[email protected]>
Mickaël Salaün
maintainerRe: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
Quoted 7 lines · James Morris
Quoted 5 lines · Mickaël Salaün
Quoted 4 lines
This needs to be converted to the LSM API via superblock blob stacking.
See Casey's old patch:
https://lore.kernel.org/linux-security-module/[email protected]/
Quoted 6 lines
Quoted 3 lines
s_landlock_inode_refsis quite similar tos_fsnotify_inode_refs, but I can do it once the superblock security blob patch is upstream. Is it a blocker for now? What is the current status oflbs_superblock?Yes it is a blocker. Landlock should not be adding its own functions in core code, it should be using the LSM API (and extending that as needed).
OK, I'll use that in the next series.
Quoted 7 lines
Quoted 5 lines
Anyway, we also need to have a call to
landlock_release_inodes()ingeneric_shutdown_super(), which does not fit the LSM framework, and I think it is not an issue. Landlock handling of inodes is quite similar to fsnotify.fsnotify is not an LSM.
Yes, so I'll need to add a new LSM hook for this (release) call, right?
James Morris
maintainerRe: [PATCH v17 05/10] fs,landlock: Support filesystem access-control
Quoted 3 lines · Mickaël Salaün
Quoted 1 line
fsnotify is not an LSM.
Yes, so I'll need to add a new LSM hook for this (release) call, right?
Unless an existing one will work.
Signature · 2 lines
James Morris <[email protected]>
Mickaël Salaün
maintainerPATCH v17 6/10 landlock: Add syscall implementation
In reply to Mickaël SalaünThis system call, inspired from seccomp(2) and bpf(2), is designed to be used by unprivileged processes to sandbox themselves. It has the same usage restrictions as seccomp(2): the caller must have the no_new_privs attribute set or have CAP_SYS_ADMIN in the current user namespace.
Here are the motivations for this new syscall:
* A sandboxed process may not have access to file systems, including /dev, /sys or /proc, but it should still be able to add more restrictions to itself.
* Neither prctl(2) nor seccomp(2) (which was used in a previous version) fit well with the current definition of a Landlock security policy.
* It is quite easy to whitelist this syscall with seccomp-bpf to enable all processes to use it. It is also easy to filter specific commands or options to restrict a process to a subset of Landlock features.
There is currently four commands:
* LANDLOCK_CMD_GET_FEATURES: Gets the supported features (required for backward and forward compatibility, and best-effort security).
* LANDLOCK_CMD_CREATE_RULESET: Creates a ruleset and returns its file descriptor.
* LANDLOCK_CMD_ADD_RULE: Adds a rule (e.g. file hierarchy access) to a ruleset, identified by the dedicated file descriptor.
* LANDLOCK_CMD_ENFORCE_RULESET: Enforces a ruleset on the current thread and its future children (similar to seccomp).
Each command have at least one option, which enables to define the attribute types passed to the syscall. All attribute types (structures) are check at build time to ensure that they don't contain hole and that they are aligned the same way for each architectures. The struct landlock_attr_features contains __u32 options_* fields which is enough to store 32-bits syscall arguments, and __u16 size_attr_* fields which is enough for the maximal struct size (i.e. page size) passed through the landlock syscall. The other fields can have __u64 type for flags and bitfields, and __s32 type for file descriptors.
See the user and kernel documentation for more details (provided by a following commit): Documentation/security/landlock/
---
Changes since v16:
* Add a size_attr_features field to struct landlock_attr_features for self-introspection, and move the access_fs field to be more consistent.
* Replace __aligned_u64 types of attribute fields with __u16, __s32, __u32 and __u64, and check at build time that these structures does not contain hole and that they are aligned the same way (8-bits) on all architectures. This shrinks the size of the userspace ABI, which may be appreciated especially for struct landlock_attr_features which could grow a lot in the future. For instance, struct landlock_attr_features shrinks from 72 bytes to 32 bytes. This change also enables to remove 64-bits to 32-bits conversion checks.
* Switch syscall attribute pointer and size arguments to follow similar syscall argument order (e.g. bpf, clone3, openat2).
* Set LANDLOCK_OPT_* types to 32-bits.
* Allow enforcement of empty ruleset, which enables deny-all policies.
* Fix documentation inconsistency.
Changes since v15:
* Do not add file descriptors referring to internal filesystems (e.g. nsfs) in a ruleset.
* Replace is_user_mountable() with in-place clean checks.
* Replace EBADR with EBADFD in get_ruleset_from_fd() and get_path_from_fd().
* Remove ruleset's show_fdinfo() for now.
Changes since v14:
* Remove the security_file_open() check in get_path_from_fd(): an opened FD should not be restricted here, and even less with this hook. As a result, it is now allowed to add a path to a ruleset even if the access to this path is not allowed (without O_PATH). This doesn't change the fact that enforcing a ruleset can't grant any right, only remove some rights. The new layer levels add more consistent restrictions.
* Check minimal landlock_attr_* size/content. This fix the case when no data was provided and e.g., FD 0 was interpreted as ruleset_fd. Now this leads to a returned -EINVAL.
* Fix credential double-free error case.
* Complete struct landlock_attr_size with size_attr_enforce.
* Fix undefined reference to syscall when Landlock is not selected.
* Remove f.file->f_path.mnt check (suggested by Al Viro).
* Add build-time checks.
* Move ABI checks from fs.c .
* Constify variables.
* Fix spelling.
* Add comments.
Changes since v13:
* New implementation, replacing the dependency on seccomp(2) and bpf(2).
--- include/linux/syscalls.h | 3 + include/uapi/linux/landlock.h | 256 +++++++++++++++- kernel/sys_ni.c | 3 + security/landlock/Makefile | 2 +- security/landlock/syscall.c | 532 ++++++++++++++++++++++++++++++++++ 5 files changed, 779 insertions(+), 17 deletions(-) create mode 100644 security/landlock/syscall.c
include/linux/syscalls.h +3 -0
@@ -1003,6 +1003,9 @@ asmlinkage long sys_pidfd_send_signal(int pidfd, int sig,siginfo_t __user *info, unsigned int flags);asmlinkage long sys_pidfd_getfd (int pidfd,int fd,unsigned int flags); +asmlinkage long sys_landlock (unsigned int command,unsigned int options, +size_t attr1_size,void __user *attr1_ptr, +size_t attr2_size,void __user *attr2_ptr);/* * Architecture-specific system calls
include/uapi/linux/landlock.h +240 -16
279 lines not on this page · raw message
kernel/sys_ni.c +3 -0
@@ -264,6 +264,9 @@ COND_SYSCALL(request_key);COND_SYSCALL (keyctl);COND_SYSCALL_COMPAT (keyctl); +/* security/landlock/syscall.c */ +COND_SYSCALL (landlock); +/* arch/example/kernel/sys_example.c */ /* mm/fadvise.c */
security/landlock/Makefile +1 -1
@@ -1,4 +1,4 @@ obj-$(CONFIG_SECURITY_LANDLOCK) := landlock.o -landlock-y := setup.o object.o ruleset.o \ +landlock-y := setup.o syscall.o object.o ruleset.o \ cred.o ptrace.o fs.o
security/landlock/syscall.c new file +532 -0
532 lines not on this page · raw message
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 7/10 arch: Wire up landlock() syscall
In reply to Mickaël SalaünWire up the landlock() system call for all architectures.
---
Changes since v14:
* Add all architectures.
Changes since v13:
* New implementation.
--- arch/alpha/kernel/syscalls/syscall.tbl | 1 + arch/arm/tools/syscall.tbl | 1 + arch/arm64/include/asm/unistd.h | 2 +- arch/arm64/include/asm/unistd32.h | 2 ++ arch/ia64/kernel/syscalls/syscall.tbl | 1 + arch/m68k/kernel/syscalls/syscall.tbl | 1 + arch/microblaze/kernel/syscalls/syscall.tbl | 1 + arch/mips/kernel/syscalls/syscall_n32.tbl | 1 + arch/mips/kernel/syscalls/syscall_n64.tbl | 1 + arch/mips/kernel/syscalls/syscall_o32.tbl | 1 + arch/parisc/kernel/syscalls/syscall.tbl | 1 + arch/powerpc/kernel/syscalls/syscall.tbl | 1 + arch/s390/kernel/syscalls/syscall.tbl | 1 + arch/sh/kernel/syscalls/syscall.tbl | 1 + arch/sparc/kernel/syscalls/syscall.tbl | 1 + arch/x86/entry/syscalls/syscall_32.tbl | 1 + arch/x86/entry/syscalls/syscall_64.tbl | 1 + arch/xtensa/kernel/syscalls/syscall.tbl | 1 + include/uapi/asm-generic/unistd.h | 4 +++- 19 files changed, 22 insertions(+), 2 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +1 -0
@@ -477,3 +477,4 @@ # 545 reserved for clone3 547 common openat2 sys_openat2 548 common pidfd_getfd sys_pidfd_getfd +549 common landlock sys_landlock
arch/arm/tools/syscall.tbl +1 -0
@@ -451,3 +451,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/arm64/include/asm/unistd.h +1 -1
@@ -38,7 +38,7 @@#define __ARM_NR_compat_set_tls (__ARM_NR_COMPAT_BASE + 5)#define __ARM_NR_COMPAT_END (__ARM_NR_COMPAT_BASE + 0x800) -#define __NR_compat_syscalls 439 +#define __NR_compat_syscalls 440#endif #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +2 -0
@@ -883,6 +883,8 @@ __SYSCALL(__NR_clone3, sys_clone3) __SYSCALL(__NR_openat2, sys_openat2)#define __NR_pidfd_getfd 438 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) +#define __NR_landlock 439 +__SYSCALL (__NR_landlock, sys_landlock)/* * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +1 -0
@@ -358,3 +358,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/m68k/kernel/syscalls/syscall.tbl +1 -0
@@ -437,3 +437,4 @@ 435 common clone3 __sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/microblaze/kernel/syscalls/syscall.tbl +1 -0
@@ -443,3 +443,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/mips/kernel/syscalls/syscall_n32.tbl +1 -0
@@ -376,3 +376,4 @@ 435 n32 clone3 __sys_clone3 437 n32 openat2 sys_openat2 438 n32 pidfd_getfd sys_pidfd_getfd +439 n32 landlock sys_landlock
arch/mips/kernel/syscalls/syscall_n64.tbl +1 -0
@@ -352,3 +352,4 @@ 435 n64 clone3 __sys_clone3 437 n64 openat2 sys_openat2 438 n64 pidfd_getfd sys_pidfd_getfd +439 n64 landlock sys_landlock
arch/mips/kernel/syscalls/syscall_o32.tbl +1 -0
@@ -425,3 +425,4 @@ 435 o32 clone3 __sys_clone3 437 o32 openat2 sys_openat2 438 o32 pidfd_getfd sys_pidfd_getfd +439 o32 landlock sys_landlock
arch/parisc/kernel/syscalls/syscall.tbl +1 -0
@@ -435,3 +435,4 @@ 435 common clone3 sys_clone3_wrapper 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/powerpc/kernel/syscalls/syscall.tbl +1 -0
@@ -527,3 +527,4 @@ 435 spu clone3 sys_ni_syscall 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/s390/kernel/syscalls/syscall.tbl +1 -0
@@ -440,3 +440,4 @@ 435 common clone3 sys_clone3 sys_clone3 437 common openat2 sys_openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock sys_landlock
arch/sh/kernel/syscalls/syscall.tbl +1 -0
@@ -440,3 +440,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/sparc/kernel/syscalls/syscall.tbl +1 -0
@@ -483,3 +483,4 @@ # 435 reserved for clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
@@ -442,3 +442,4 @@ 435 i386 clone3 sys_clone3 437 i386 openat2 sys_openat2 438 i386 pidfd_getfd sys_pidfd_getfd +439 i386 landlock sys_landlock
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
@@ -359,6 +359,7 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock # # x32-specific system call numbers start at 512 to avoid cache impact
arch/xtensa/kernel/syscalls/syscall.tbl +1 -0
@@ -408,3 +408,4 @@ 435 common clone3 sys_clone3 437 common openat2 sys_openat2 438 common pidfd_getfd sys_pidfd_getfd +439 common landlock sys_landlock
include/uapi/asm-generic/unistd.h +3 -1
@@ -855,9 +855,11 @@ __SYSCALL(__NR_clone3, sys_clone3) __SYSCALL(__NR_openat2, sys_openat2)#define __NR_pidfd_getfd 438 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd) +#define __NR_landlock 439 +__SYSCALL(__NR_landlock, sys_landlock)#undef __NR_syscalls -#define __NR_syscalls 439 +#define __NR_syscalls 440/* * 32 bit systems traditionally used different
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 8/10 selftests/landlock: Add initial tests
In reply to Mickaël SalaünTest landlock syscall, ptrace hooks semantic and filesystem access-control.
Test coverage for security/landlock/ is 93.6% of lines. The code not covered only deals with internal kernel errors (e.g. memory allocation) and race conditions.
---
Changes since v16:
* Add new unpriv_enforce_without_no_new_privs test: check that ruleset enforcing is forbiden without no_new_privs and CAP_SYS_ADMIN.
* Drop capabilities when useful.
* Check the new size_attr_features field from struct landlock_attr_features.
* Update the empty_or_same_ruleset test to check complementary empty ruleset.
* Update base_test according to the new attribute structures and fix the inconsistent_attr test accordingly.
* Switch syscall attribute pointer and size arguments.
* Rename test files with a "_test" suffix.
Changes since v14:
* Add new tests:
- superset: check new layer bitmask.
- max_layers: check maximum number of layers.
- release_inodes: check that umount work well.
- empty_or_same_ruleset.
- inconsistent_attr: checks copy_to_user limits.
- in ruleset_rw.inval to check ruleset FD.
- proc_unlinked_file: check file access through /proc/self/fd .
- file_access_rights: check that a file can only get consistent access rights.
- unpriv: check that NO_NEW_PRIVS or CAP_SYS_ADMIN is required.
- check pipe access through /proc/self/fd .
- check move_mount(2).
- check ruleset file descriptor properties.
- proc_nsfs: extend to check that internal filesystems (e.g. nsfs) are allowed.
* Double-check read and write effective actions.
* Fix potential desynchronization between the kernel sources and installed headers by overriding the build step in the Makefile. This also enable to build with Clang.
* Add two files in the test directories (for link test and rename test).
* Remove test for ruleset's show_fdinfo().
* Replace EBADR with EBADFD.
* Update tests accordingly to the changes of rename and link rights.
* Fix (now) illegal access rights tied to files.
* Update rename and link tests.
* Remove superfluous '\n' in TH_LOG() calls.
* Make assert calls consistent and readable.
* Fix the execute test.
* Make tests future-proof.
* Cosmetic fixes.
Changes since v14:
* Add new tests:
- Compatibility: empty_attr_{ruleset,path_beneath,enforce} to check minimal attr size.
- Access types: link_to, rename_from, rename_to, rmdir, unlink, make_char, make_block, make_reg, make_sock, make_fifo, make_sym, make_dir, chroot, execute.
- Test privilege escalation prevention by enforcing a nested rule, on a parent directory, with less restrictions than one on a child directory.
- Test for empty and more than 32-bits allowed_access
* Merge the two test mount hierarchies.
* Complete relative path tests by combining chdir and chroot.
* Adjust tests:
- Remove the layout1/extend_ruleset_with_denied_path test.
- Extend layout1/whitelist test with checks on file.
- Add and use create_dir_and_file().
* Only use read/write checks but not stat(2) for tests.
* Rename test.h to common.h and improve it.
* Rename path name to make them more consistent, easy to understand and make them in a common directory.
* Make create_ruleset() more generic.
* Constify variables.
* Re-add static global variables.
* Remove useless openat(2).
* Fix and complete kernel config.
* Set umask and clean up file modes.
* Clean up open flags.
* Improve Makefile.
* Fix spelling.
* Improve comments and error messages.
Changes since v13:
* Add back the filesystem tests (from v10) and extend them.
* Add tests for the new syscall.
Previous changes:
https://lore.kernel.org/lkml/[email protected]/
--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/landlock/.gitignore | 2 + tools/testing/selftests/landlock/Makefile | 29 + tools/testing/selftests/landlock/base_test.c | 170 ++ tools/testing/selftests/landlock/common.h | 108 + tools/testing/selftests/landlock/config | 5 + tools/testing/selftests/landlock/fs_test.c | 1729 +++++++++++++++++ .../testing/selftests/landlock/ptrace_test.c | 293 +++ tools/testing/selftests/landlock/true.c | 5 + 9 files changed, 2342 insertions(+) create mode 100644 tools/testing/selftests/landlock/.gitignore create mode 100644 tools/testing/selftests/landlock/Makefile create mode 100644 tools/testing/selftests/landlock/base_test.c create mode 100644 tools/testing/selftests/landlock/common.h create mode 100644 tools/testing/selftests/landlock/config create mode 100644 tools/testing/selftests/landlock/fs_test.c create mode 100644 tools/testing/selftests/landlock/ptrace_test.c create mode 100644 tools/testing/selftests/landlock/true.c
tools/testing/selftests/Makefile +1 -0
@@ -24,6 +24,7 @@ TARGETS += ir TARGETS += kcmp TARGETS += kexec TARGETS += kvm +TARGETS += landlock TARGETS += lib TARGETS += livepatch TARGETS += lkdtm
tools/testing/selftests/landlock/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +/*_test +/true
tools/testing/selftests/landlock/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +# SPDX-License-Identifier: GPL-2.0 + +src_test := $(wildcard *_test.c) + +TEST_GEN_PROGS := $(src_test:.c=) + +TEST_GEN_PROGS_EXTENDED := true + +KSFT_KHDR_INSTALL := 1 +OVERRIDE_TARGETS := 1 +include ../lib.mk + +# Cf. tools/testing/selftests/arm64/Makefile +ifeq ($(KBUILD_OUTPUT),) +khdr_dir = $(top_srcdir)/usr/include +else +khdr_dir = $(KBUILD_OUTPUT)/kselftest/usr/include +endif + +CFLAGS += -Wall -O2 + +$(khdr_dir)/linux/landlock.h: khdr + @: + +$(OUTPUT)/true: true.c + $(LINK.c) $< $(LDLIBS) -o $@ -static + +$(OUTPUT)/%_test: %_test.c $(khdr_dir)/linux/landlock.h ../kselftest_harness.h common.h + $(LINK.c) $< $(LDLIBS) -o $@ -lcap -I$(khdr_dir)
tools/testing/selftests/landlock/base_test.c new file +170 -0
170 lines not on this page · raw message
tools/testing/selftests/landlock/common.h new file +108 -0
108 lines not on this page · raw message
tools/testing/selftests/landlock/config new file +5 -0
@@ -0,0 +1,5 @@ +CONFIG_SECURITY_LANDLOCK=y +CONFIG_SECURITY_PATH=y +CONFIG_SECURITY=y +CONFIG_SHMEM=y +CONFIG_TMPFS=y
tools/testing/selftests/landlock/fs_test.c new file +1729 -0
1,729 lines not on this page · raw message
tools/testing/selftests/landlock/ptrace_test.c new file +293 -0
293 lines not on this page · raw message
tools/testing/selftests/landlock/true.c new file +5 -0
@@ -0,0 +1,5 @@ +// SPDX-License-Identifier: GPL-2.0 +int main (void ) +{ +return 0 ; +}
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 9/10 samples/landlock: Add a sandbox manager example
In reply to Mickaël SalaünAdd a basic sandbox tool to launch a command which can only access a whitelist of file hierarchies in a read-only or read-write way.
---
Changes since v16:
* Switch syscall attribute pointer and size arguments.
Changes since v15:
* Update access right names.
* Properly assign access right to files according to the new related syscall restriction.
* Replace "select" with "depends on" HEADERS_INSTALL (suggested by Randy Dunlap).
Changes since v14:
* Fix Kconfig dependency.
* Remove access rights that may be required for FD-only requests:
mmap, truncate, getattr, lock, chmod, chown, chgrp, ioctl.
* Fix useless hardcoded syscall number.
* Use execvpe().
* Follow symlinks.
* Extend help with common file paths.
* Constify variables.
* Clean up comments.
* Improve error message.
Changes since v11:
* Add back the filesystem sandbox manager and update it to work with the new Landlock syscall.
Previous changes:
https://lore.kernel.org/lkml/[email protected]/
--- samples/Kconfig | 7 ++ samples/Makefile | 1 + samples/landlock/.gitignore | 1 + samples/landlock/Makefile | 15 +++ samples/landlock/sandboxer.c | 228 +++++++++++++++++++++++++++++++++++ 5 files changed, 252 insertions(+) create mode 100644 samples/landlock/.gitignore create mode 100644 samples/landlock/Makefile create mode 100644 samples/landlock/sandboxer.c
samples/Kconfig +7 -0
@@ -120,6 +120,13 @@ config SAMPLE_HIDRAW bool "hidraw sample" depends on HEADERS_INSTALL +config SAMPLE_LANDLOCK + bool "Build Landlock sample code" + depends on HEADERS_INSTALL + help + Build a simple Landlock sandbox manager able to launch a process + restricted by a user-defined filesystem access-control security policy. + config SAMPLE_PIDFD bool "pidfd sample" depends on HEADERS_INSTALL
samples/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_SAMPLE_KDB) += kdb/ obj-$(CONFIG_SAMPLE_KFIFO) += kfifo/ obj-$(CONFIG_SAMPLE_KOBJECT) += kobject/ obj-$(CONFIG_SAMPLE_KPROBES) += kprobes/ +subdir-$(CONFIG_SAMPLE_LANDLOCK) += landlock obj-$(CONFIG_SAMPLE_LIVEPATCH) += livepatch/ subdir-$(CONFIG_SAMPLE_PIDFD) += pidfd obj-$(CONFIG_SAMPLE_QMI_CLIENT) += qmi/
samples/landlock/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/sandboxer
samples/landlock/Makefile new file +15 -0
@@ -0,0 +1,15 @@ +# SPDX-License-Identifier: BSD-3-Clause + +hostprogs-y := sandboxer + +always := $(hostprogs-y) + +KBUILD_HOSTCFLAGS += -I$(objtree)/usr/include + +.PHONY: all clean + +all: + $(MAKE) -C ../.. samples/landlock/ + +clean: + $(MAKE) -C ../.. M=samples/landlock/ clean
samples/landlock/sandboxer.c new file +228 -0
228 lines not on this page · raw message
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerPATCH v17 10/10 landlock: Add user and kernel documentation
In reply to Mickaël SalaünThis documentation can be built with the Sphinx framework.
---
Changes since v15:
* Add current limitations.
Changes since v14:
* Fix spelling (contributed by Randy Dunlap).
* Extend documentation about inheritance and explain layer levels.
* Remove the use of now-removed access rights.
* Use GitHub links.
* Improve kernel documentation.
* Add section for tests.
* Update example.
Changes since v13:
* Rewrote the documentation according to the major revamp.
Previous changes:
https://lore.kernel.org/lkml/[email protected]/
--- Documentation/security/index.rst | 1 + Documentation/security/landlock/index.rst | 18 ++ Documentation/security/landlock/kernel.rst | 69 ++++++ Documentation/security/landlock/user.rst | 268 +++++++++++++++++++++ 4 files changed, 356 insertions(+) create mode 100644 Documentation/security/landlock/index.rst create mode 100644 Documentation/security/landlock/kernel.rst create mode 100644 Documentation/security/landlock/user.rst
Documentation/security/index.rst +1 -0
@@ -15,3 +15,4 @@ Security Documentation self-protection siphash tpm/index + landlock/index
Documentation/security/landlock/index.rst new file +18 -0
@@ -0,0 +1,18 @@ +========================================= +Landlock LSM: unprivileged access control +========================================= + +:Author: Mickaël Salaün + +The goal of Landlock is to enable to restrict ambient rights (e.g. global +filesystem access) for a set of processes. Because Landlock is a stackable +LSM, it makes possible to create safe security sandboxes as new security layers +in addition to the existing system-wide access-controls. This kind of sandbox +is expected to help mitigate the security impact of bugs or +unexpected/malicious behaviors in user-space applications. Landlock empowers +any process, including unprivileged ones, to securely restrict themselves. + +.. toctree:: + + user + kernel
Documentation/security/landlock/kernel.rst new file +69 -0
69 lines not on this page · raw message
Documentation/security/landlock/user.rst new file +268 -0
268 lines not on this page · raw message
Signature · 1 line
2.26.2
Mickaël Salaün
maintainerQuoted 7 lines · Mickaël Salaün
Hi,
This new patch series brings some improvements and add new tests:
Use smaller userspace structures (attributes) to save space, and check at built time that every attribute don't contain hole and are 8-bits aligned.
8-bytes aligned, of course.