Skip to content

Landlock pr1 api v1.1 - #16375

Open
regit wants to merge 5 commits into
OISF:mainfrom
regit:landlock-pr1-api-v1.1
Open

regit wants to merge 5 commits into
OISF:mainfrom
regit:landlock-pr1-api-v1.1

Conversation

@regit

@regit regit commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

First part of #16005 introducing support for new Landlock features.

Contribution style:

Our Contribution agreements:

Changes (if applicable):

Link to ticket: https://redmine.openinfosecfoundation.org/issues/8606

Describe changes:

  • Update landlock API to latest version
  • Add network access to sandbox

regit added 5 commits October 5, 2026 06:17
The landlock read and write path helpers were static and only usable
from the sandboxing function itself. Rename them to the SC prefixed
public API and declare them in the header so that other parts of the
engine, and later plugins and output modules, can declare the paths
they need before the sandbox is enforced.

The ruleset is passed as an opaque void pointer to avoid exposing the
landlock internal structure to callers, and the helpers are no-op when
landlock is not available so they can be called unconditionally.

Ticket: 8606
Landlock gained network access control in ABI version 4 (Linux 6.7),
allowing to restrict TCP bind and connect to a set of ports.

Handle the network access rights in the ruleset and add two helpers,
SCLandlockGrantNetBindTCP() and SCLandlockGrantNetConnectTCP(), so that
the components needing to bind or connect a socket can declare the port
they use before the sandbox is enforced.

The ABI check is turned into a switch as the number of features
depending on the kernel version is growing: the network access rights
are removed from the ruleset when running on a kernel with an ABI lower
than 4.

Ticket: 8606
Recent kernels added filesystem access rights that were not handled by
the ruleset: LANDLOCK_ACCESS_FS_TRUNCATE (ABI 3), IOCTL_DEV (ABI 5) and
RESOLVE_UNIX (ABI 9). As they are not part of the handled access, they
were simply allowed, weakening the sandbox.

Add them to the write access set and extend the ABI switch to remove
the ones that are not known by the running kernel. Asking for an access
right the kernel does not know makes the ruleset creation fail, so a
missing case here would disable the sandbox instead of loosening it.

Ticket: 8606
As the plugin may not implement correctly landlock, user has a way
to override the configuration.

Ticket: 8606
struct landlock_ruleset_attr gained the scoped field in Linux 6.12
(Landlock ABI 6) and handled_access_net in Linux 6.7 (ABI 4). Missing
constants can be defined by hand, a struct member cannot, so both need
their own configure check and the code using them has to be guarded.

Ticket: 8606
@regit
regit requested review from a team and victorjulien as code owners October 5, 2026 06:32

@suricata-review-bot suricata-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review.

Verdict: changes requested

3 findings posted as inline comments:

  • High — src/util-landlock.c:102-104 — The fallback value for LANDLOCK_ACCESS_FS_RESOLVE_UNIX is (1ULL << 18), but the kernel UAPI defines it as (1ULL << 16).
  • High — src/util-landlock.c:120-121 — TRUNCATE, IOCTL_DEV and RESOLVE_UNIX are now handled, but _LANDLOCK_SURI_ACCESS_FS_WRITE and the data-dir rule never grant them, so they…
  • Medium — src/util-landlock.c:152-154 — On ABI ≥ 4 kernels (Linux 6.7+), handling network rights denies every TCP connect and bind after sandboxing, and no component grants any…

Automated at commit 0dc246a9e596 using Claude Code with claude-opus-5-5/xhigh. Run: a442ee84465240d8.

Comment thread src/util-landlock.c
Comment on lines +102 to +104
#ifndef LANDLOCK_ACCESS_FS_RESOLVE_UNIX
#define LANDLOCK_ACCESS_FS_RESOLVE_UNIX (1ULL << 18)
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High — The fallback value for LANDLOCK_ACCESS_FS_RESOLVE_UNIX is (1ULL << 18), but the kernel UAPI defines it as (1ULL << 16). Consider a build against headers older than Landlock ABI 9 that runs on an ABI ≥ 9 kernel. Bit 18 stays in handled_access_fs, so landlock_create_ruleset() fails with EINVAL and Suricata runs with no sandbox. The same setup is sandboxed today. Use (1ULL << 16).

Comment thread src/util-landlock.c
Comment on lines +120 to +121
LANDLOCK_ACCESS_FS_REFER | LANDLOCK_ACCESS_FS_TRUNCATE | \
LANDLOCK_ACCESS_FS_IOCTL_DEV | LANDLOCK_ACCESS_FS_RESOLVE_UNIX)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High — TRUNCATE, IOCTL_DEV and RESOLVE_UNIX are now handled, but _LANDLOCK_SURI_ACCESS_FS_WRITE and the data-dir rule never grant them, so they are denied everywhere. On Linux ≥ 6.2, DatasetsSave() calls fopen(set->save, "w") on the existing state file. That open fails with EACCES, so dataset state is silently lost at shutdown. On ABI ≥ 9, EVE unix-socket and Redis unix reconnects are denied. Grant TRUNCATE and RESOLVE_UNIX where needed, as Redmine #8606 asks, or hold off handling these rights.

Comment thread src/util-landlock.c
Comment on lines +152 to +154
#ifdef HAVE_LANDLOCK_RULESET_ATTR_HANDLED_ACCESS_NET
ruleset->attr.handled_access_net = _LANDLOCK_ACCESS_NET;
#endif

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Medium — On ABI ≥ 4 kernels (Linux 6.7+), handling network rights denies every TCP connect and bind after sandboxing, and no component grants any port. Redis output reconnects fail after a Redis restart. In unix-socket runmode, outputs are opened after sandboxing, so a TCP Redis output never connects. The only workaround is the new security.landlock.network.{connect,bind}.tcp keys, which landlock.rst and suricata.yaml.in do not document. Grant the configured output ports or defer network handling, and document the keys.

@victorjulien victorjulien left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI failures + the AI review needs a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants