linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 00/30] Landlock audit support
@ 2025-01-08 15:43 Mickaël Salaün
  2025-01-08 15:43 ` [PATCH v4 01/30] lsm: Only build lsm_audit.c if CONFIG_SECURITY and CONFIG_AUDIT are set Mickaël Salaün
                   ` (29 more replies)
  0 siblings, 30 replies; 58+ messages in thread
From: Mickaël Salaün @ 2025-01-08 15:43 UTC (permalink / raw)
  To: Eric Paris, Paul Moore, Günther Noack, Serge E . Hallyn
  Cc: Mickaël Salaün, Ben Scarlato, Casey Schaufler,
	Charles Zaffery, Daniel Burgener, Francis Laniel, James Morris,
	Jann Horn, Jeff Xu, Jorge Lucangeli Obes, Kees Cook,
	Konstantin Meskhidze, Matt Bobrowski, Mikhail Ivanov, Phil Sutter,
	Praveen K Paladugu, Robert Salvet, Shervin Oloumi, Song Liu,
	Tahera Fahimi, Tyler Hicks, audit, linux-kernel,
	linux-security-module

Hi,

This patch series adds audit support to Landlock.

Logging denied requests is useful for different use cases:
- sysadmins: to look for users' issues,
- security experts: to detect attack attempts,
- power users: to understand denials,
- developers: to ease sandboxing support and get feedback from users.

Because of its unprivileged nature, Landlock can compose standalone
security policies (i.e. domains).  To make logs useful, they need to
contain the most relevant Landlock domain that denied an action, and the
reason of such denial.  This translates to the latest nested domain and
the related blockers: missing access rights or other kind of
restrictions.

# Changes from previous version

This fourth patch series mainly adds a new AUDIT_EXE_LANDLOCK_DENY rule
type to filter Landlock denials according to the executable that loaded
the policy responsible for this restriction.  New tests are added on top
of that.

Domain's metadata are now stored in a dedicated struct landlock_details
that contains the resolved exe's path, because we cannot keep a
reference to the related struct path.  This fixes umount of the
mount point containing a binary that restricted itself (if the domain is
still alive).  Add a dedicated test to check this issue.

Formatting of blockers are slightly improved.

Audit timestamps are no longer exported but dedicated Landlock
timestamps are use instead for domain creation.

The new landlock_restrict_self()'s flag is renamed to
LANDLOCK_RESTRICT_SELF_QUIET.

# Design

Log records are created for any denied actions caused by a Landlock
policy, which means that a well-sandboxed applications should not log
anything except for unattended access requests that might be the result
of attacks or bugs.

However, sandbox tools creating restricted environments could lead to
abundant log entries because the sandboxed processes may not be aware of
the related restrictions.  To avoid log spam, the
landlock_restrict_self(2) syscall gets a new
LANDLOCK_RESTRICT_SELF_QUIET flag to not log denials related to this
specific domain.  Except for well-understood exceptions, this flag
should not be set.  Indeed, applications sandboxing themselves should
only try to bypass their own sandbox if they are compromised, which
should ring a bell thanks to log events.

When an action is denied, the related Landlock domain ID is specified.
If this domain was not previously described in a log record, one is
created.  This record contains the domain ID, its creation time, and
informations about the process that enforced the restriction (at the
time of the call to landlock_restrict_self): PID, UID, executable path,
and name (comm).

This new approach also brings building blocks for an upcoming
unprivileged introspection interface.  The unique Landlock IDs will be
useful to tie audit log entries to running processes, and to get
properties of the related Landlock domains.  This will replace the
previously logged ruleset properties.

# Samples

Here are two examples of log events (see serial numbers):

$ LL_FS_RO=/ LL_FS_RW=/ LL_SCOPED=s LL_FORCE_LOG=1 ./sandboxer kill 1

  type=LANDLOCK_DENY msg=audit(1729738800.268:30): domain=1a6fdc66f blockers=scope.signal opid=1 ocomm="systemd"
  type=LANDLOCK_DOM_INFO msg=audit(1729738800.268:30): domain=1a6fdc66f creation=1729738800.264 pid=286 uid=0 exe="/root/sandboxer" comm="sandboxer"UID="root"
  type=SYSCALL msg=audit(1729738800.268:30): arch=c000003e syscall=62 success=no exit=-1 [..] ppid=272 pid=286 auid=0 uid=0 gid=0 [...] comm="kill" [...]
  type=PROCTITLE msg=audit(1729738800.268:30): proctitle=6B696C6C0031
  type=LANDLOCK_DOM_DROP msg=audit(1729738800.324:31): domain=1a6fdc66f denials=1

$ LL_FS_RO=/ LL_FS_RW=/tmp LL_FORCE_LOG=1 ./sandboxer sh -c "echo > /etc/passwd"

  type=LANDLOCK_DENY msg=audit(1729738800.221:33): domain=1a6fdc679 blockers=fs.write_file path="/dev/tty" dev="devtmpfs" ino=9
  type=LANDLOCK_DOM_INFO msg=audit(1729738800.221:33): domain=1a6fdc679 creation=1729738800.217 pid=289 uid=0 exe="/root/sandboxer" comm="sandboxer"UID="root"
  type=SYSCALL msg=audit(1729738800.221:33): arch=c000003e syscall=257 success=no exit=-13 [...] ppid=272 pid=289 auid=0 uid=0 gid=0 [...] comm="sh" [...]
  type=PROCTITLE msg=audit(1729738800.221:33): proctitle=7368002D63006563686F203E202F6574632F706173737764
  type=LANDLOCK_DENY msg=audit(1729738800.221:34): domain=1a6fdc679 blockers=fs.write_file path="/etc/passwd" dev="vda2" ino=143821
  type=SYSCALL msg=audit(1729738800.221:34): arch=c000003e syscall=257 success=no exit=-13 [...] ppid=272 pid=289 auid=0 uid=0 gid=0 [...] comm="sh" [...]
  type=PROCTITLE msg=audit(1729738800.221:34): proctitle=7368002D63006563686F203E202F6574632F706173737764
  type=LANDLOCK_DOM_DROP msg=audit(1729738800.261:35): domain=1a6fdc679 denials=2

# Future changes

I'll add more tests to check each kind of denied access.

We might want to add new audit rule types to filter according to other
domain properties (e.g. UID, AUID, session ID), but
AUDIT_EXE_LANDLOCK_DENY should be enough to mute buggy programs before
fixing them.

# Previous versions

v3: https://lore.kernel.org/r/20241122143353.59367-1-mic@digikod.net
v2: https://lore.kernel.org/r/20241022161009.982584-1-mic@digikod.net
v1: https://lore.kernel.org/r/20230921061641.273654-1-mic@digikod.net

Regards,

Mickaël Salaün (30):
  lsm: Only build lsm_audit.c if CONFIG_SECURITY and CONFIG_AUDIT are
    set
  lsm: Add audit_log_lsm_data() helper
  landlock: Factor out check_access_path()
  landlock: Add unique ID generator
  landlock: Move access types
  landlock: Simplify initially denied access rights
  landlock: Move domain hierarchy management and export helpers
  landlock: Add AUDIT_LANDLOCK_DENY and log ptrace denials
  landlock: Add AUDIT_LANDLOCK_DOM_{INFO,DROP} and log domain properties
  landlock: Log mount-related denials
  landlock: Align partial refer access checks with final ones
  selftests/landlock: Add test to check partial access in a mount tree
  landlock: Optimize file path walks and prepare for audit support
  landlock: Log file-related denials
  landlock: Log truncate and IOCTL denials
  landlock: Log TCP bind and connect denials
  landlock: Log scoped denials
  landlock: Control log events with LANDLOCK_RESTRICT_SELF_QUIET
  samples/landlock: Do not log denials from the sandboxer by default
  selftests/landlock: Fix error message
  selftests/landlock: Add wrappers.h
  selftests/landlock: Add layout1.umount_sandboxer tests
  selftests/landlock: Extend tests for landlock_restrict_self()'s flags
  selftests/landlock: Add tests for audit and
    LANDLOCK_RESTRICT_SELF_QUIET
  selftests/landlock: Add audit tests for ptrace
  landlock: Export and rename landlock_get_inode_object()
  fs: Add iput() cleanup helper
  audit,landlock: Add AUDIT_EXE_LANDLOCK_DENY rule type
  selftests/landlock: Test audit rule with AUDIT_EXE_LANDLOCK_DOM
  selftests/landlock: Test compatibility with audit rule lists

 Documentation/userspace-api/landlock.rst      |   2 +-
 MAINTAINERS                                   |   1 +
 include/linux/audit.h                         |  11 +
 include/linux/fs.h                            |   6 +-
 include/linux/landlock.h                      |  41 ++
 include/linux/lsm_audit.h                     |  22 +
 include/uapi/linux/audit.h                    |   6 +-
 include/uapi/linux/landlock.h                 |  14 +
 kernel/audit.c                                |   4 +-
 kernel/audit.h                                |   5 +-
 kernel/auditfilter.c                          |  30 +-
 kernel/auditsc.c                              |  31 ++
 samples/landlock/sandboxer.c                  |  35 +-
 security/Kconfig                              |   5 +
 security/Makefile                             |   2 +-
 security/landlock/.kunitconfig                |   2 +
 security/landlock/Makefile                    |  15 +-
 security/landlock/access.h                    | 100 ++++
 security/landlock/audit.c                     | 510 ++++++++++++++++++
 security/landlock/audit.h                     |  76 +++
 security/landlock/domain.c                    | 339 ++++++++++++
 security/landlock/domain.h                    | 145 +++++
 security/landlock/fs.c                        | 305 ++++++++---
 security/landlock/fs.h                        |  12 +
 security/landlock/id.c                        | 249 +++++++++
 security/landlock/id.h                        |  25 +
 security/landlock/net.c                       |  51 +-
 security/landlock/object.h                    |   4 +-
 security/landlock/ruleset.c                   |  38 +-
 security/landlock/ruleset.h                   |  95 ++--
 security/landlock/setup.c                     |   2 +
 security/landlock/syscalls.c                  |  28 +-
 security/landlock/task.c                      | 152 +++++-
 security/lsm_audit.c                          |  27 +-
 tools/testing/kunit/configs/all_tests.config  |   2 +
 tools/testing/selftests/landlock/Makefile     |   2 +-
 tools/testing/selftests/landlock/audit.h      | 371 +++++++++++++
 tools/testing/selftests/landlock/audit_test.c | 389 +++++++++++++
 tools/testing/selftests/landlock/base_test.c  |  19 +-
 tools/testing/selftests/landlock/common.h     |  40 +-
 tools/testing/selftests/landlock/config       |   1 +
 tools/testing/selftests/landlock/fs_test.c    | 151 +++++-
 .../testing/selftests/landlock/ptrace_test.c  |  67 ++-
 .../selftests/landlock/sandbox-and-launch.c   |  82 +++
 tools/testing/selftests/landlock/wait-pipe.c  |  70 +++
 tools/testing/selftests/landlock/wrappers.h   |  47 ++
 46 files changed, 3360 insertions(+), 271 deletions(-)
 create mode 100644 include/linux/landlock.h
 create mode 100644 security/landlock/access.h
 create mode 100644 security/landlock/audit.c
 create mode 100644 security/landlock/audit.h
 create mode 100644 security/landlock/domain.c
 create mode 100644 security/landlock/domain.h
 create mode 100644 security/landlock/id.c
 create mode 100644 security/landlock/id.h
 create mode 100644 tools/testing/selftests/landlock/audit.h
 create mode 100644 tools/testing/selftests/landlock/audit_test.c
 create mode 100644 tools/testing/selftests/landlock/sandbox-and-launch.c
 create mode 100644 tools/testing/selftests/landlock/wait-pipe.c
 create mode 100644 tools/testing/selftests/landlock/wrappers.h


base-commit: 9d89551994a430b50c4fffcb1e617a057fa76e20
-- 
2.47.1


^ permalink raw reply	[flat|nested] 58+ messages in thread

end of thread, other threads:[~2025-01-16 20:24 UTC | newest]

Thread overview: 58+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-08 15:43 [PATCH v4 00/30] Landlock audit support Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 01/30] lsm: Only build lsm_audit.c if CONFIG_SECURITY and CONFIG_AUDIT are set Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 02/30] lsm: Add audit_log_lsm_data() helper Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 03/30] landlock: Factor out check_access_path() Mickaël Salaün
2025-01-10 11:23   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 04/30] landlock: Add unique ID generator Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 05/30] landlock: Move access types Mickaël Salaün
2025-01-10 11:23   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 06/30] landlock: Simplify initially denied access rights Mickaël Salaün
2025-01-10 11:24   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 07/30] landlock: Move domain hierarchy management and export helpers Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 08/30] landlock: Add AUDIT_LANDLOCK_DENY and log ptrace denials Mickaël Salaün
2025-01-15 23:53   ` [PATCH v4 8/30] " Paul Moore
2025-01-16 10:49     ` Mickaël Salaün
2025-01-16 20:00       ` Paul Moore
2025-01-08 15:43 ` [PATCH v4 09/30] landlock: Add AUDIT_LANDLOCK_DOM_{INFO,DROP} and log domain properties Mickaël Salaün
2025-01-15 23:53   ` [PATCH v4 9/30] " Paul Moore
2025-01-16 10:51     ` Mickaël Salaün
2025-01-16 20:19       ` Paul Moore
2025-01-08 15:43 ` [PATCH v4 10/30] landlock: Log mount-related denials Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 11/30] landlock: Align partial refer access checks with final ones Mickaël Salaün
2025-01-10 11:24   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 12/30] selftests/landlock: Add test to check partial access in a mount tree Mickaël Salaün
2025-01-10 11:24   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 13/30] landlock: Optimize file path walks and prepare for audit support Mickaël Salaün
2025-01-10 11:24   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 14/30] landlock: Log file-related denials Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 15/30] landlock: Log truncate and IOCTL denials Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 16/30] landlock: Log TCP bind and connect denials Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 17/30] landlock: Log scoped denials Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 18/30] landlock: Control log events with LANDLOCK_RESTRICT_SELF_QUIET Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 19/30] samples/landlock: Do not log denials from the sandboxer by default Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 20/30] selftests/landlock: Fix error message Mickaël Salaün
2025-01-10 11:24   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 21/30] selftests/landlock: Add wrappers.h Mickaël Salaün
2025-01-10 11:24   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 22/30] selftests/landlock: Add layout1.umount_sandboxer tests Mickaël Salaün
2025-01-10 11:25   ` Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 23/30] selftests/landlock: Extend tests for landlock_restrict_self()'s flags Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 24/30] selftests/landlock: Add tests for audit and LANDLOCK_RESTRICT_SELF_QUIET Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 25/30] selftests/landlock: Add audit tests for ptrace Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 26/30] landlock: Export and rename landlock_get_inode_object() Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 27/30] fs: Add iput() cleanup helper Mickaël Salaün
2025-01-13 11:15   ` Mickaël Salaün
2025-01-13 16:45     ` Al Viro
2025-01-13 14:00   ` Jann Horn
2025-01-13 15:00     ` Christian Brauner
2025-01-13 16:55       ` Mickaël Salaün
2025-01-13 14:36   ` (subset) " Christian Brauner
2025-01-08 15:43 ` [PATCH v4 28/30] audit,landlock: Add AUDIT_EXE_LANDLOCK_DENY rule type Mickaël Salaün
2025-01-13 14:55   ` Jann Horn
2025-01-13 15:02     ` Christian Brauner
2025-01-13 16:55     ` Mickaël Salaün
2025-01-15 23:53   ` Paul Moore
2025-01-16 10:57     ` Mickaël Salaün
2025-01-16 20:24       ` Paul Moore
2025-01-08 15:43 ` [PATCH v4 29/30] selftests/landlock: Test audit rule with AUDIT_EXE_LANDLOCK_DOM Mickaël Salaün
2025-01-08 15:43 ` [PATCH v4 30/30] selftests/landlock: Test compatibility with audit rule lists Mickaël Salaün

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).