linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH v2 00/14] Landlock audit support
@ 2024-10-22 16:09 Mickaël Salaün
  2024-10-22 16:09 ` [RFC PATCH v2 01/14] lsm: Only build lsm_audit.c if CONFIG_AUDIT is set Mickaël Salaün
                   ` (14 more replies)
  0 siblings, 15 replies; 29+ messages in thread
From: Mickaël Salaün @ 2024-10-22 16:09 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, James Morris, Jann Horn, Jeff Xu,
	Jorge Lucangeli Obes, Kees Cook, Konstantin Meskhidze,
	Matt Bobrowski, Mikhail Ivanov, Praveen K Paladugu, Robert Salvet,
	Shervin Oloumi, Song Liu, Tahera Fahimi, audit, linux-kernel,
	linux-security-module

Hi,

This patch series adds audit support to Landlock.

Logging denied requests is useful for different use cases:
* app developers: to ease and speed up sandboxing support
* power users: to understand denials
* sysadmins: to look for users' issues
* security experts: to detect attack attempts

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 constraints (e.g. scoped domain).

# Changes from previous version

This second patch series brings a full implementation with a novel
design fitted to an unprivileged access control system.

The previous approach created log records for any Landlock syscall and
denials.  We now only create log records related to denied actions.

This series does not include documentation nor user space tests yet, but
KUnit tests are provided.

# 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_LOGLESS 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, the domain ID of its parent
domain (or 0 if none), 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:

$ LL_FS_RO=/ LL_FS_RW=/ ./sandboxer sh -c "LL_FS_RO=/ LL_FS_RW=/tmp LL_SCOPED=s ./sandboxer kill 1"

  type=UNKNOWN[1423] msg=audit(1.102:31): domain=5264859566 blockers=scope_signal opid=1 ocomm="systemd"
  type=UNKNOWN[1424] msg=audit(1.102:31): domain=5264859566 parent=5264859553 pid=290 uid=0 exe="/root/sandboxer" comm="sandboxer"
  type=UNKNOWN[1424] msg=audit(1.102:31): domain=5264859553 parent=0 pid=290 uid=0 exe="/root/sandboxer" comm="sandboxer"
  type=SYSCALL msg=audit(1.102:31): arch=c000003e syscall=62 success=no exit=-1 ...
  type=PROCTITLE msg=audit(1.102:31): proctitle=...
  type=UNKNOWN[1425] msg=audit(1.158:32): domain=5264859566
  type=UNKNOWN[1425] msg=audit(1.182:33): domain=5264859553

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

  type=UNKNOWN[1423] msg=audit(2.832:37): domain=5264859570 blockers=fs_write_file path="/etc/passwd" dev="vda2" ino=143821
  type=UNKNOWN[1424] msg=audit(2.832:37): domain=5264859570 parent=0 pid=296 uid=0 exe="/root/sandboxer" comm="sandboxer"
  type=SYSCALL msg=audit(2.832:37): arch=c000003e syscall=257 success=no exit=-13 ...
  type=PROCTITLE msg=audit(2.832:37): proctitle=...
  type=UNKNOWN[1425] msg=audit(2.892:38): domain=5264859570

# Future changes

It would be interesting to enhance audit with the ability to filter on
the executable path that created a sandbox, or to filter on a Landlock
domain ID.


This series is based on my "next" branch, which includes these patches:
https://lore.kernel.org/r/20241022151144.872797-2-mic@digikod.net

Previous version:
v1: https://lore.kernel.org/r/20230921061641.273654-1-mic@digikod.net

Regards,

Mickaël Salaün (14):
  lsm: Only build lsm_audit.c if CONFIG_AUDIT is set
  lsm: Add audit_log_lsm_data() helper
  landlock: Factor out check_access_path()
  landlock: Add unique ID generator
  landlock: Move access types
  landlock: Move domain hierarchy management
  landlock: Log ptrace denials
  landlock: Log domain properties and release
  landlock: Log mount-related denials
  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_LOGLESS

 include/linux/lsm_audit.h                    |  22 +
 include/uapi/linux/audit.h                   |   5 +-
 include/uapi/linux/landlock.h                |  14 +
 security/Makefile                            |   2 +-
 security/landlock/.kunitconfig               |   2 +
 security/landlock/Makefile                   |   2 +
 security/landlock/access.h                   |  70 +++
 security/landlock/audit.c                    | 493 +++++++++++++++++++
 security/landlock/audit.h                    |  76 +++
 security/landlock/domain.c                   | 184 +++++++
 security/landlock/domain.h                   | 111 +++++
 security/landlock/fs.c                       | 210 ++++++--
 security/landlock/fs.h                       |  10 +
 security/landlock/id.c                       | 242 +++++++++
 security/landlock/id.h                       |  25 +
 security/landlock/net.c                      |  52 +-
 security/landlock/ruleset.c                  |  31 +-
 security/landlock/ruleset.h                  |  80 ++-
 security/landlock/setup.c                    |   2 +
 security/landlock/syscalls.c                 |  26 +-
 security/landlock/task.c                     | 150 +++++-
 security/lsm_audit.c                         |  27 +-
 tools/testing/kunit/configs/all_tests.config |   2 +
 23 files changed, 1692 insertions(+), 146 deletions(-)
 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


base-commit: 2798d07e6d416164119e83c2cd1bb50160297ec8
-- 
2.47.0


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

end of thread, other threads:[~2024-11-13 15:21 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-22 16:09 [RFC PATCH v2 00/14] Landlock audit support Mickaël Salaün
2024-10-22 16:09 ` [RFC PATCH v2 01/14] lsm: Only build lsm_audit.c if CONFIG_AUDIT is set Mickaël Salaün
2024-10-23  0:07   ` Paul Moore
2024-10-23 18:51   ` Guenter Roeck
2024-10-23 21:21     ` Paul Moore
2024-10-22 16:09 ` [RFC PATCH v2 02/14] lsm: Add audit_log_lsm_data() helper Mickaël Salaün
2024-10-23  0:07   ` Paul Moore
2024-10-24 16:30     ` Paul Moore
2024-10-22 16:09 ` [RFC PATCH v2 03/14] landlock: Factor out check_access_path() Mickaël Salaün
2024-10-22 16:09 ` [RFC PATCH v2 04/14] landlock: Add unique ID generator Mickaël Salaün
2024-10-25 15:18   ` Francis Laniel
2024-11-13 15:18     ` Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 05/14] landlock: Move access types Mickaël Salaün
2024-10-25 15:20   ` Francis Laniel
2024-11-13 15:18     ` Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 06/14] landlock: Move domain hierarchy management Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 07/14] landlock: Log ptrace denials Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 08/14] landlock: Log domain properties and release Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 09/14] landlock: Log mount-related denials Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 10/14] landlock: Log file-related denials Mickaël Salaün
2024-10-25 15:23   ` Francis Laniel
2024-11-13 15:21     ` Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 11/14] landlock: Log truncate and ioctl denials Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 12/14] landlock: Log TCP bind and connect denials Mickaël Salaün
2024-10-25 15:25   ` Francis Laniel
2024-11-13 15:21     ` Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 13/14] landlock: Log scoped denials Mickaël Salaün
2024-10-22 16:10 ` [RFC PATCH v2 14/14] landlock: Control log events with LANDLOCK_RESTRICT_SELF_LOGLESS Mickaël Salaün
2024-10-22 16:18 ` [RFC PATCH v2 00/14] Landlock audit support 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).