landlock: Add scoped access bit for SysV message queues
Subsystems (4)
cover landlock: Add scoped access bit for SysV message queues
This series extends Landlock with a new scoped access right, LANDLOCK_SCOPE_SYSV_MSG_QUEUE, allowing a sandboxed process to be restricted from interacting with SysV message queues created outside of its Landlock domain (or a nested domain).
While use of SysV message queues is less common than other IPC types, they are commonly used in older applications which may be vulnerable to exploitation, so they are a meaningful attack surface to restrict.
Background
==========
SysV message queues differ from the IPC mechanisms Landlock already scopes (UNIX sockets and signals): they have no FD or process-local handle. A msqid is valid IPC-namespace-wide and can be obtained without calling msgget(), so simply hooking msgget() is insufficient. Domain provenance has to be tracked on the queue itself and checked on every operation against it.
Approach
========
A new credential blob is attached to each kern_ipc_perm at creation time, recording the creating task's Landlock domain and a @kind tag identifying the IPC object type. The @kind tag is required because the LSM core allocates an IPC blob for every kern_ipc_perm regardless of kind, and the generic ipc_permission hook fires for semaphores and shared memory as well as message queues.
The enum also leaves room to extend scoping to sem/shm later without changing the blob layout.
Enforcement is done from security_ipc_permission(), which is the single choke point for msgget() on an existing queue, msgsnd(), msgrcv(), and the msgctl() variants that go through ipcperms() (IPC_STAT, MSG_STAT, MSG_STAT_ANY). msgctl_down() (IPC_RMID and IPC_SET) bypasses ipcperms(), so the per-call msg_queue_msgctl hook is kept for those cases. msg_queue_msgctl also covers the IPC_INFO / MSG_INFO case where no specific queue exists.
Quirks
======
- Denials surface as -EACCES rather than -EPERM because the generic ipcperms() path maps every LSM denial to -EACCES before returning to userspace. This is documented and the selftests check for -EACCES accordingly.
- Because there is no persistent handle, a msqid already obtained by a process before it enforces this scope can become unusable once the restriction is in place; this is intentional and documented.
Patch layout
============
1. Add the kern_ipc_perm credential blob and @kind enum.
2. Implement LANDLOCK_SCOPE_SYSV_MSG_QUEUE, the ipc_permission hook, and msg_queue_msgctl coverage for IPC_RMID/IPC_SET and IPC_INFO/MSG_INFO.
3. Bump the Landlock ABI.
4. Selftests covering msgget plus a separate fixture for msgsnd, msgrcv, and msgctl using a pre-created msqid.
5. sandboxer sample support for the new scope.
6. Documentation updates covering the new scope, the -EACCES return code, and the implications of non-persistent handles.
Test coverage
=============
Selftests exercise denial and allow paths for msgget, msgsnd, msgrcv, and msgctl(IPC_STAT) across domain boundaries, including nested-domain inheritance. All existing and added tests are passing.
Kind Regards,
Justin Suess
Justin Suess (6):
landlock: Add kern_ipc_perm credential blob structs
landlock: Add LANDLOCK_SCOPE_SYSV_MSG_QUEUE
landlock: Bump ABI for LANDLOCK_SCOPE_SYSV_MSG_QUEUE selftests/landlock: Test LANDLOCK_SCOPE_SYSV_MSG_QUEUE samples/landlock: Support LANDLOCK_SCOPE_SYSV_MSG_QUEUE in sandboxer
landlock: Document LANDLOCK_SCOPE_SYSV_MESSAGE_QUEUE
Documentation/admin-guide/LSM/landlock.rst | 1 + Documentation/userspace-api/landlock.rst | 30 +- include/uapi/linux/landlock.h | 3 + samples/landlock/sandboxer.c | 20 +- security/landlock/audit.c | 4 + security/landlock/audit.h | 1 + security/landlock/limits.h | 2 +- security/landlock/setup.c | 1 + security/landlock/syscalls.c | 2 +- security/landlock/task.c | 137 ++++++++++ security/landlock/task.h | 50 ++++ tools/testing/selftests/landlock/base_test.c | 4 +- .../landlock/scoped_sysv_msg_queue_test.c | 256 ++++++++++++++++++ .../testing/selftests/landlock/scoped_test.c | 2 +- 14 files changed, 503 insertions(+), 10 deletions(-) create mode 100644 tools/testing/selftests/landlock/scoped_sysv_msg_queue_test.c
base-commit: 9c5b83756e7b7eab35335da0d5c02a8854bbf416
Signature · 1 line
2.53.0
PATCH 1/6 landlock: Add kern_ipc_perm credential blob structs
Add landlock_kern_ipc_perm_security, tracking ownership of SysV IPC objects.
The struct contains the creating task's Landlock credential (@owner_subject) and a @kind enum identifying which SysV IPC object this blob describes. The LSM core allocates the IPC blob for every kern_ipc_perm regardless of object kind, so the generic ipc_permission hook needs to be able to tell which objects it should enforce a given scope on. An enum makes it straightforward to extend Landlock to sem and shm scoping later without revisiting the blob layout.
Define the size of this struct in the lbs_ipc field for the Landlock blob sizes.
--- security/landlock/setup.c | 1 + security/landlock/task.h | 50 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
security/landlock/setup.c +1 -0
@@ -32,6 +32,7 @@ struct lsm_blob_sizes landlock_blob_sizes __ro_after_init = { .lbs_file = sizeof(struct landlock_file_security), .lbs_inode = sizeof(struct landlock_inode_security), .lbs_superblock = sizeof(struct landlock_superblock_security), + .lbs_ipc = sizeof(struct landlock_kern_ipc_perm_security), };int landlock_errata__ro_after_init ;
security/landlock/task.h +50 -0
56 lines not on this page · raw message
Signature · 1 line
2.53.0
PATCH 2/6 landlock: Add LANDLOCK_SCOPE_SYSV_MSG_QUEUE
In reply to Justin SuessAdd a new scoped access right LANDLOCK_SCOPE_SYSV_MSG_QUEUE for controlling operations msgget, msgsnd, msgrcv, and msgctl on SysV message queues.
Merely handling msgget is insufficient; SysV message queues do not use FDs or process local handles, and the msqid associated with a queue is valid within the IPC namespace. There is no requirement to perform a msgget to interact with a SysV message queue.
When a process enforces this scoping, access to SysV message queues by a restricted process is only allowed if the queue was created by a process in the same or a nested Landlock domain.
When a SysV message queue is allocated by a process in a Landlock domain, the security blob for the kern_ipc_perm is updated to reflect domain provenance and the blob is tagged as a message queue via the new @kind enum.
The scope is enforced from the generic ipc_permission hook rather than the per-call msg_queue_* hooks. ipc_permission is the choke point for msgget on an existing queue and for msgsnd / msgrcv / msgctl(IPC_STAT, MSG_STAT, MSG_STAT_ANY).
ipc_permission also fires for semaphores and shared memory, so the hook bails out when the blob's @kind is not LANDLOCK_SYSV_IPC_MSG_QUEUE.
msgctl_down() (IPC_RMID and IPC_SET) does not go through ipc_permission, so msg_queue_msgctl is kept to cover those. It also guards against the IPC_INFO / MSG_INFO case where @msq is NULL and there is no specific queue to scope.
Also update the scoped_test ACCESS_LAST sentinel to track the new last scope so the unknown-scope selftest does not falsely accept LANDLOCK_SCOPE_SYSV_MSG_QUEUE as unknown.
Audit records are generated for this scope on denials.
--- include/uapi/linux/landlock.h | 3 + security/landlock/audit.c | 4 + security/landlock/audit.h | 1 + security/landlock/limits.h | 2 +- security/landlock/task.c | 137 ++++++++++++++++++ .../testing/selftests/landlock/scoped_test.c | 2 +- 6 files changed, 147 insertions(+), 2 deletions(-)
include/uapi/linux/landlock.h +3 -0
@@ -398,10 +398,13 @@ struct landlock_net_port_attr {* related Landlock domain (e.g., a parent domain or a non-sandboxed process). * - %LANDLOCK_SCOPE_SIGNAL: Restrict a sandboxed process from sending a signal * to another process outside the domain. +* - %LANDLOCK_SCOPE_SYSV_MSG_QUEUE: Restrict a sandboxed process from interacting +* with a sysv msg queue created by a process outside the domain. */ /* clang-format off */ #define LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET (1ULL << 0)#define LANDLOCK_SCOPE_SIGNAL (1ULL << 1) +#define LANDLOCK_SCOPE_SYSV_MSG_QUEUE (1ULL << 2)/* clang-format on*/ #endif /* _UAPI_LINUX_LANDLOCK_H */
security/landlock/audit.c +4 -0
@@ -79,6 +79,10 @@ get_blocker(const enum landlock_request_type type,case LANDLOCK_REQUEST_SCOPE_SIGNAL :WARN_ON_ONCE (access_bit !=-1 );return "scope.signal" ; + +case LANDLOCK_REQUEST_SCOPE_MSG_QUEUE : +WARN_ON_ONCE (access_bit !=-1 ); +return "scope.sysv_msg_queue" ; }WARN_ON_ONCE (1 );
security/landlock/audit.h +1 -0
@@ -21,6 +21,7 @@ enum landlock_request_type {LANDLOCK_REQUEST_NET_ACCESS ,LANDLOCK_REQUEST_SCOPE_ABSTRACT_UNIX_SOCKET ,LANDLOCK_REQUEST_SCOPE_SIGNAL , + LANDLOCK_REQUEST_SCOPE_MSG_QUEUE, };/*
security/landlock/limits.h +1 -1
@@ -27,7 +27,7 @@#define LANDLOCK_MASK_ACCESS_NET ((LANDLOCK_LAST_ACCESS_NET << 1) - 1)#define LANDLOCK_NUM_ACCESS_NET __const_hweight64(LANDLOCK_MASK_ACCESS_NET) -#define LANDLOCK_LAST_SCOPE LANDLOCK_SCOPE_SIGNAL +#define LANDLOCK_LAST_SCOPE LANDLOCK_SCOPE_SYSV_MSG_QUEUE#define LANDLOCK_MASK_SCOPE ((LANDLOCK_LAST_SCOPE << 1) - 1)#define LANDLOCK_NUM_SCOPE __const_hweight64(LANDLOCK_MASK_SCOPE)
security/landlock/task.c +137 -0
149 lines not on this page · raw message
tools/testing/selftests/landlock/scoped_test.c +1 -1
@@ -12,7 +12,7 @@#include "common.h" -#define ACCESS_LAST LANDLOCK_SCOPE_SIGNAL +#define ACCESS_LAST LANDLOCK_SCOPE_SYSV_MSG_QUEUETEST (ruleset_with_unknown_scope) {
Signature · 1 line
2.53.0
PATCH 3/6 landlock: Bump ABI for LANDLOCK_SCOPE_SYSV_MSG_QUEUE
In reply to Justin SuessBump the ABI version for Landlock SysV message queue scoping.
--- security/landlock/syscalls.c | 2 +- tools/testing/selftests/landlock/base_test.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-)
security/landlock/syscalls.c +1 -1
@@ -166,7 +166,7 @@ static const struct file_operations ruleset_fops = {* If the change involves a fix that requires userspace awareness, also update * the errata documentation in Documentation/userspace-api/landlock.rst . */ -const int landlock_abi_version =9 ; +const int landlock_abi_version =10 ;/** * sys_landlock_create_ruleset - Create a new ruleset
tools/testing/selftests/landlock/base_test.c +2 -2
@@ -76,8 +76,8 @@ TEST(abi_version)const struct landlock_ruleset_attr ruleset_attr = { .handled_access_fs =LANDLOCK_ACCESS_FS_READ_FILE , }; -ASSERT_EQ (9 ,landlock_create_ruleset (NULL ,0 , -LANDLOCK_CREATE_RULESET_VERSION )); +ASSERT_EQ (10 ,landlock_create_ruleset (NULL ,0 , +LANDLOCK_CREATE_RULESET_VERSION ));ASSERT_EQ (-1 ,landlock_create_ruleset (&ruleset_attr,0 ,LANDLOCK_CREATE_RULESET_VERSION ));
Signature · 1 line
2.53.0
PATCH 4/6 selftests/landlock: Test LANDLOCK_SCOPE_SYSV_MSG_QUEUE
In reply to Justin SuessAdd selftests for SysV message queue scoped right.
Use the existing scoped domain harness for msgget, and another fixture for testing msgsnd, msgrcv and msgctl.
Pass the msqid around for coverage of non-msgget syscalls, since calling msgget while already restricted would fail and prevent testing the operation under test.
Denials are checked against -EACCES rather than -EPERM: msgget, msgsnd, msgrcv and msgctl(IPC_STAT) all reach the Landlock scope check via ipcperms(), whose callers map every non-zero return into -EACCES before propagating it to user space.
--- .../landlock/scoped_sysv_msg_queue_test.c | 256 ++++++++++++++++++ 1 file changed, 256 insertions(+) create mode 100644 tools/testing/selftests/landlock/scoped_sysv_msg_queue_test.c
tools/testing/selftests/landlock/scoped_sysv_msg_queue_test.c new file +256 -0
@@ -0,0 +1,256 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Landlock tests - SysV Message Queue Scoping +* +*/ + +#define _GNU_SOURCE +#include <errno.h> +#include <fcntl.h> +#include <linux/landlock.h> +#include <sys/ipc.h> +#include <sys/msg.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <unistd.h> + +#include "common.h" +#include "scoped_common.h" + +/* +* Removes the message queue identified by @msqid, ignoring any error since +* the caller might no longer have permission to operate on it (for example, +* after entering a scoped domain). +*/ +static void cleanup_msg_queue (int msqid) +{ +if (msqid >=0 ) +msgctl (msqid,IPC_RMID ,NULL ); +} + +/* clang-format off */ +FIXTURE (scoped_domains) {}; +/* clang-format on */ + +#include "scoped_base_variants.h" + +FIXTURE_SETUP (scoped_domains) +{ +drop_caps (_metadata); +} + +FIXTURE_TEARDOWN (scoped_domains) +{ +} + +/* +* Parent creates a SysV message queue, then the child tries to associate +* with it via msgget(2). When the child is in a domain that scopes message +* queues and the parent is not in that same scope, the association must be +* denied with -EACCES (msgget runs the scope check via ipcperms(), which +* masks every denial as -EACCES). +*/ +TEST_F(scoped_domains, check_access_msg_queue) +{ +pid_t child; +int status; +int msqid =-1 ; +int pipe_parent[2 ], pipe_child[2 ]; +char buf; +key_t key; +bool can_associate; + +/* +* The child can associate with the parent's queue unless the child +* is in a scoped domain that does not include the parent (i.e. the +* parent is outside the child's domain). +*/ + can_associate = !variant->domain_child; + +/* +* Picks a per-test key derived from PID to avoid collisions. Stale +* queues from a previous run are unlikely but handled by removing +* any matching entry before applying any scope. +*/ + key = (key_t)(getpid () &0x7fffffff ); +cleanup_msg_queue (msgget (key,0 )); + +if (variant->domain_both) +create_scoped_domain (_metadata,LANDLOCK_SCOPE_SYSV_MSG_QUEUE ); + +ASSERT_EQ (0 ,pipe2 (pipe_parent,O_CLOEXEC )); +ASSERT_EQ (0 ,pipe2 (pipe_child,O_CLOEXEC )); + + child =fork (); +ASSERT_LE (0 , child); +if (child ==0 ) { +int ret; + +EXPECT_EQ (0 ,close (pipe_child[0 ])); +EXPECT_EQ (0 ,close (pipe_parent[1 ])); + +if (variant->domain_child) +create_scoped_domain (_metadata, +LANDLOCK_SCOPE_SYSV_MSG_QUEUE ); + +/* Signals readiness to the parent. */ +ASSERT_EQ (1 ,write (pipe_child[1 ],"." ,1 )); +EXPECT_EQ (0 ,close (pipe_child[1 ])); + +/* Waits for the parent to have created the queue. */ +ASSERT_EQ (1 ,read (pipe_parent[0 ], &buf,1 )); +EXPECT_EQ (0 ,close (pipe_parent[0 ])); + + ret =msgget (key,0 ); +if (can_associate) { +ASSERT_LE (0 , ret); + }else { +ASSERT_EQ (-1 , ret); +/* +* msgget uses ipcperms(), which masks every LSM +* denial as -EACCES regardless of the value the +* LSM hook returns. +*/ +ASSERT_EQ (EACCES , errno); + } + +_exit (_metadata->exit_code); +return ; + } +EXPECT_EQ (0 ,close (pipe_child[1 ])); +EXPECT_EQ (0 ,close (pipe_parent[0 ])); + +if (variant->domain_parent) +create_scoped_domain (_metadata,LANDLOCK_SCOPE_SYSV_MSG_QUEUE ); + +/* Waits for the child to be ready. */ +ASSERT_EQ (1 ,read (pipe_child[0 ], &buf,1 )); +EXPECT_EQ (0 ,close (pipe_child[0 ])); + + msqid =msgget (key,IPC_CREAT |IPC_EXCL |0600 ); +ASSERT_LE (0 , msqid); + +/* Releases the child. */ +ASSERT_EQ (1 ,write (pipe_parent[1 ],"." ,1 )); +EXPECT_EQ (0 ,close (pipe_parent[1 ])); + +ASSERT_EQ (child,waitpid (child, &status,0 )); +cleanup_msg_queue (msqid); + +if (WIFSIGNALED (status) || !WIFEXITED (status) || +WEXITSTATUS (status) !=EXIT_SUCCESS ) + _metadata->exit_code =KSFT_FAIL ; +} + +/* +* The msg_queue_associate hook (exercised by msgget(2)) is covered by the +* scoped_domains fixture above. The remaining hooks all funnel through the +* same scope check, so it suffices to verify that each operation is denied +* when the child is scoped relative to the queue's creator. +* +* To attribute a denial to the operation under test (and not to a preceding +* msgget(2) call), the parent creates the queue and the child inherits the +* msqid across fork(2), bypassing msg_queue_associate. +*/ +enum msg_op { +MSG_OP_SND , +MSG_OP_RCV , +MSG_OP_CTL , +}; + +/* clang-format off */ +FIXTURE (scoping_msg_ops) {}; +/* clang-format on */ + +FIXTURE_VARIANT (scoping_msg_ops) +{ +enum msg_op op; +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(scoping_msg_ops, msgsnd) { +/* clang-format on */ + .op =MSG_OP_SND , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(scoping_msg_ops, msgrcv) { +/* clang-format on */ + .op =MSG_OP_RCV , +}; + +/* clang-format off */ +FIXTURE_VARIANT_ADD(scoping_msg_ops, msgctl) { +/* clang-format on */ + .op = MSG_OP_CTL, +}; + +FIXTURE_SETUP (scoping_msg_ops) +{ +drop_caps (_metadata); +} + +FIXTURE_TEARDOWN (scoping_msg_ops) +{ +} + +TEST_F(scoping_msg_ops, deny_op) +{ +struct msgbuf { +long mtype; +char mtext[1 ]; + } msg = { .mtype =1 }; +struct msqid_ds ds; +pid_t child; +int status; +int msqid, ret =0 ; +key_t key; + + key = (key_t)(getpid () &0x7fffffff ); +cleanup_msg_queue (msgget (key,0 )); + + msqid =msgget (key,IPC_CREAT |IPC_EXCL |0600 ); +ASSERT_LE (0 , msqid); + +/* Preloads a message so msgrcv(2) would otherwise succeed. */ +ASSERT_EQ (0 ,msgsnd (msqid, &msg,sizeof (msg.mtext),0 )); + + child =fork (); +ASSERT_LE (0 , child); +if (child ==0 ) { +create_scoped_domain (_metadata,LANDLOCK_SCOPE_SYSV_MSG_QUEUE ); + +switch (variant->op) { +case MSG_OP_SND : + ret =msgsnd (msqid, &msg,sizeof (msg.mtext),0 ); +break ; +case MSG_OP_RCV : + ret =msgrcv (msqid, &msg,sizeof (msg.mtext),0 , +IPC_NOWAIT ); +break ; +case MSG_OP_CTL : + ret =msgctl (msqid,IPC_STAT , &ds); +break ; + } +ASSERT_EQ (-1 , ret); +/* +* msgsnd, msgrcv and msgctl(IPC_STAT) all reach the +* Landlock scope check via ipcperms(), whose callers map +* any non-zero return into -EACCES before propagating it +* to user space. +*/ +ASSERT_EQ (EACCES , errno); + +_exit (_metadata->exit_code); +return ; + } + +ASSERT_EQ (child,waitpid (child, &status,0 )); +cleanup_msg_queue (msqid); + +if (WIFSIGNALED (status) || !WIFEXITED (status) || +WEXITSTATUS (status) !=EXIT_SUCCESS ) + _metadata->exit_code =KSFT_FAIL ; +} + +TEST_HARNESS_MAIN
Signature · 1 line
2.53.0
PATCH 5/6 samples/landlock: Support LANDLOCK_SCOPE_SYSV_MSG_QUEUE in sandboxer
In reply to Justin SuessAdd sandboxer support for the new LANDLOCK_SCOPE_SYSV_MSG_QUEUE access right.
--- samples/landlock/sandboxer.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
samples/landlock/sandboxer.c +16 -4
@@ -235,10 +235,12 @@ static bool check_ruleset_scope(const char *const env_var,bool error = false;bool abstract_scoping = false;bool signal_scoping = false; +bool sysv_msg_queue_scoping = false;/* Scoping is not supported by Landlock ABI */ if (!(ruleset_attr->scoped & - (LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET |LANDLOCK_SCOPE_SIGNAL ))) + (LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET |LANDLOCK_SCOPE_SIGNAL | +LANDLOCK_SCOPE_SYSV_MSG_QUEUE ))) goto out_unset; env_type_scope =getenv (env_var);
@@ -255,6 +257,9 @@ static bool check_ruleset_scope(const char *const env_var, }else if (strcmp ("s" , ipc_scoping_name) ==0 && !signal_scoping) { signal_scoping = true; + }else if (strcmp ("m" , ipc_scoping_name) ==0 && + !sysv_msg_queue_scoping) { + sysv_msg_queue_scoping = true; }else {fprintf (stderr,"Unknown or duplicate scope \"%s\"\n" , ipc_scoping_name);
@@ -271,6 +276,8 @@ static bool check_ruleset_scope(const char *const env_var, ruleset_attr->scoped &= ~LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET ;if (!signal_scoping) ruleset_attr->scoped &= ~LANDLOCK_SCOPE_SIGNAL ; +if (!sysv_msg_queue_scoping) + ruleset_attr->scoped &= ~LANDLOCK_SCOPE_SYSV_MSG_QUEUE ;unsetenv (env_var);return error;
@@ -301,7 +308,7 @@ static bool check_ruleset_scope(const char *const env_var,/* clang-format on */ -#define LANDLOCK_ABI_LAST 9 +#define LANDLOCK_ABI_LAST 10#define XSTR (s) #s#define STR (s) XSTR(s)
@@ -327,6 +334,7 @@ static const char help[] ="* " ENV_SCOPED_NAME ": actions denied on the outside of the landlock domain\n" " - \"a\" to restrict opening abstract unix sockets\n" " - \"s\" to restrict sending signals\n" +" - \"m\" to restrict associating with message queues\n" "\n" "A sandboxer should not log denied access requests to avoid spamming logs, " "but to test audit we can set " ENV_FORCE_LOG_NAME "=1\n"
@@ -336,7 +344,7 @@ static const char help[] =ENV_FS_RW_NAME "=\"/dev/null:/dev/full:/dev/zero:/dev/pts:/tmp\" " ENV_TCP_BIND_NAME "=\"9418\" " ENV_TCP_CONNECT_NAME "=\"80:443\" " -ENV_SCOPED_NAME "=\"a:s\" " +ENV_SCOPED_NAME "=\"a:s:m\" " "%1$s bash -i\n" "\n" "This sandboxer can use Landlock features up to ABI version "
@@ -358,7 +366,7 @@ int main(const int argc, char *const argv[], char *const *const envp) .handled_access_net = LANDLOCK_ACCESS_NET_BIND_TCP | LANDLOCK_ACCESS_NET_CONNECT_TCP, .scoped = LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET | - LANDLOCK_SCOPE_SIGNAL, + LANDLOCK_SCOPE_SIGNAL | LANDLOCK_SCOPE_SYSV_MSG_QUEUE, };int supported_restrict_flags =LANDLOCK_RESTRICT_SELF_LOG_NEW_EXEC_ON ;int set_restrict_flags =0 ;
@@ -444,6 +452,10 @@ int main(const int argc, char *const argv[], char *const *const envp)/* Removes LANDLOCK_ACCESS_FS_RESOLVE_UNIX for ABI < 9 */ ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_RESOLVE_UNIX ; + __attribute__((fallthrough)); +case 9 : +/* Removes LANDLOCK_SCOPE_SYSV_MSG_QUEUE for ABI < 10 */ + ruleset_attr.scoped &= ~LANDLOCK_SCOPE_SYSV_MSG_QUEUE ;/* Must be printed for any ABI < LANDLOCK_ABI_LAST. */ fprintf (stderr, "Hint: You should update the running kernel "
Signature · 1 line
2.53.0
PATCH 6/6 landlock: Document LANDLOCK_SCOPE_SYSV_MESSAGE_QUEUE
In reply to Justin SuessDocument the new SysV message queue scope restriction. Make clear that because these queues do not use persistent handles, subsequent operations on a queue already obtained via msgget (or any other means) may be restricted once this right is enforced. Also note that denials surface as -EACCES rather than -EPERM, since the generic SysV IPC permission path maps every LSM denial to -EACCES.
--- Documentation/admin-guide/LSM/landlock.rst | 1 + Documentation/userspace-api/landlock.rst | 30 +++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-)
Documentation/admin-guide/LSM/landlock.rst +1 -0
@@ -58,6 +58,7 @@ AUDIT_LANDLOCK_ACCESS **scope.*** - IPC scoping restrictions (ABI 6+): - scope.abstract_unix_socket - Abstract UNIX socket connection denied - scope.signal - Signal sending denied + - scope.sysv_msg_queue - SysV message queue operation denied (ABI 10+) Multiple blockers can appear in a single event (comma-separated) when multiple access rights are missing. For example, creating a regular file
Documentation/userspace-api/landlock.rst +29 -1
@@ -84,7 +84,8 @@ to be explicit about the denied-by-default access rights. LANDLOCK_ACCESS_NET_CONNECT_TCP, .scoped = LANDLOCK_SCOPE_ABSTRACT_UNIX_SOCKET | - LANDLOCK_SCOPE_SIGNAL, + LANDLOCK_SCOPE_SIGNAL | + LANDLOCK_SCOPE_SYSV_MSG_QUEUE, }; Because we may not know which kernel version an application will be executed
@@ -132,6 +133,10 @@ version, and only use the available subset of access rights: case 6 ... 8: /* Removes LANDLOCK_ACCESS_FS_RESOLVE_UNIX for ABI < 9 */ ruleset_attr.handled_access_fs &= ~LANDLOCK_ACCESS_FS_RESOLVE_UNIX; + __attribute__((fallthrough)); + case 9: + /* Removes LANDLOCK_SCOPE_SYSV_MSG_QUEUE for ABI < 10 */ + ruleset_attr.scoped &= ~LANDLOCK_SCOPE_SYSV_MSG_QUEUE; } This enables the creation of an inclusive ruleset that will contain our rules.
@@ -380,6 +385,22 @@ The operations which can be scoped are: A :manpage:`sendto(2)` on a socket which was previously connected will not be restricted. This works for both datagram and stream sockets. +``LANDLOCK_SCOPE_SYSV_MSG_QUEUE`` + This limits the set of System V message queues to which we can perform + :manpage:`msgget(2)`, :manpage:`msgrcv(2)`, :manpage:`msgsnd(2)`, and + :manpage:`msgctl(2)` calls to only message queues which were created by a + process in the same or a nested Landlock domain. + + Since System V message queues are IPC namespace global constructs and do + not use file descriptors, enforcement of a ruleset with this scoping may + cause subsequent operations on an msqid that were allowed prior to + enforcement to be denied. + + Denials are reported as ``EACCES``. Unlike other Landlock scopes, + the check shares the generic SysV IPC permission path + (``ipcperms(3)``), which maps every denial to ``EACCES`` before it + reaches user space. + IPC scoping does not support exceptions via :manpage:`landlock_add_rule(2)`. If an operation is scoped within a domain, no rules can be added to allow access to resources or processes outside of the scope.
@@ -722,6 +743,13 @@ Starting with the Landlock ABI version 9, it is possible to restrict connections to pathname UNIX domain sockets (:manpage:`unix(7)`) using the new ``LANDLOCK_ACCESS_FS_RESOLVE_UNIX`` right. +System V message queue (ABI < 10) +--------------------------------- + +Starting with the Landlock ABI version 10, it is possible to restrict +operations on System V message queues by setting +``LANDLOCK_SCOPE_SYSV_MSG_QUEUE`` to the ``scoped`` ruleset attribute. + .. _kernel_support: Kernel support
Signature · 1 line
2.53.0