Linux Security Modules development
 help / color / mirror / Atom feed
From: "Günther Noack" <gnoack3000@gmail.com>
To: Oxana Kharitonova <oxana@cloudflare.com>
Cc: mic@digikod.net, gnoack@google.com, paul@paul-moore.com,
	jmorris@namei.or, serge@hallyn.com, wangyan01@kylinos.cn,
	linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org, landlock@lists.linux.dev,
	webprosto@gmail.com
Subject: Re: [PATCH 0/6] landlock: Add POSIX message queue scoping
Date: Fri, 21 Aug 2026 10:46:37 +0200	[thread overview]
Message-ID: <20260821.d42cd4b82f91@gnoack.org> (raw)
In-Reply-To: <20260722122952.42149-1-oxana@cloudflare.com>

Hello Oxana!

On Wed, Jul 22, 2026 at 01:29:36PM +0100, Oxana Kharitonova wrote:
> This series adds landlock support for scoping POSIX message queuesi [1].
>  
> Landlock already supports scoped IPC restrictions for signals and abstract
> UNIX sockets. These restrictions make it possible to prevent a sandboxed
> task from interacting with IPC objects outside of its Landlock domain,
> while still allowing communication within the same domain or with nested
> domains.
>  
> This series extends the same model to POSIX message queues with a new
> LANDLOCK_SCOPE_POSIX_MSG_QUEUE scope. When this scope is enforced, a task
> can only open POSIX message queues that were created by a task in the same
> landlock domain or in a nested domain.
>  
> The implementation tags mqueuefs inodes at creation time with the creator's
> landlock domain. This domain is kept alive for the lifetime of the inode
> and is checked when the queue is opened.
>  
> The series also exposes the mqueuefs magic number through the shared UAPI
> magic header, bumps the Landlock ABI, updates documentation, adds sandboxer
> support, and adds selftests.
>  
> The new behavior is:
>  
> - a task restricted with LANDLOCK_SCOPE_POSIX_MSG_QUEUE cannot open a queue
>   created outside of its Landlock scope;
> - a task can still open a queue created within its own Landlock domain;
> - queues created outside of any Landlock domain are treated as outside the
>   scope for a scoped opener.

Thank you for sending this!

I have a high level question about this patch set:

You are adding a check to hook_file_open(), but the existing
hook_file_open() can already prevent mq_open().

The following experiment illustrates this:
* Restrict LANDLOCK_ACCESS_FS_READ_FILE and LANDLOCK_ACCESS_FS_WRITE_FILE
* Try to run mq_open("/foobar", O_CREAT...)

Depending on the installed PATH_BENEATH rules, you now see differing behaviour:

* If we allow READ_FILE and WRITE_FILE on nothing, mq_open() is *DENIED*.
* If we allow READ_FILE and WRITE_FILE on /, mq_open() is *DENIED*.
* If we allow READ_FILE and WRITE_FILE on a mounted /dev/mqueue, mq_open() is *ALLOWED*.

So it seems that the existing file system restrictions are already
preventing POSIX message queues from being opened?  And not only that
-- since such Landlock policies are already quite common, it seems
likely that many existing landlocked programs are already restricting
opening of POSIX message queues today.

So, to clarify:

* What your patch set is adding is only that we are now additionally
  taking the Landlock domain scope into account?
* This distinction only makes a difference for landlocked programs
  that do not restrict READ_FILE/WRITE_FILE or that do restrict it and
  then allow-list READ_FILE/WRITE_FILE on a previously mounted
  /dev/mqueue.

Maybe this would be interesting to clarify a bit more prominently in
the cover letter, because it reduces the applicability of this
patchset?

Attached below is a LLM-generated (but double checked) test program
which you can use to try out the creation of mqueues.  (As first
argument, use "-", "/" or "/dev/mqueue".)

What *might* still be interesting to restrict though: While mq_open()
checks the READ_FILE and WRITE_FILE rights, it checks none of the
LANDLOCK_ACCESS_FS_MAKE_* rights -- the message queue gets still
created, even when the mq_open() is denied and returns with an error.

To expand on Justin's comment in [1] -- it feels that there are maybe
still some gaps in the "lifecycle management" of these message queues
that might be worth thinking systematically about, because both
mq_unlink() and the creation of the message queue entries are
currently apparently not restrictable yet?  It makes me wonder whether
hijacking of message queue names (creating same-named queues in other
Landlock domains) is a problem then?  Do you have thoughts on this?

Thanks,
–Günther

[1] https://lore.kernel.org/all/amKDYoOSvHMzVbKX@suesslenovo/


--- llmq.c
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <linux/landlock.h>
#include <mqueue.h>
#include <stdio.h>
#include <string.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <unistd.h>

static int ll_create(const struct landlock_ruleset_attr *a, size_t s, __u32 f)
{ return syscall(__NR_landlock_create_ruleset, a, s, f); }
static int ll_add(int fd, enum landlock_rule_type t, const void *a, __u32 f)
{ return syscall(__NR_landlock_add_rule, fd, t, a, f); }
static int ll_self(int fd, __u32 f)
{ return syscall(__NR_landlock_restrict_self, fd, f); }

#define RW (LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_WRITE_FILE)

int main(int argc, char **argv)
{
	const char *grant = argv[1];		/* path to allow, or "-" for none */
	struct landlock_ruleset_attr rsa = { .handled_access_fs = RW };
	int rs = ll_create(&rsa, sizeof(rsa), 0);
	mqd_t mq;
	int f;

	if (rs < 0) { perror("create_ruleset"); return 1; }

	if (strcmp(grant, "-") != 0) {
		struct landlock_path_beneath_attr pb = { .allowed_access = RW };
		pb.parent_fd = open(grant, O_PATH | O_CLOEXEC);
		if (pb.parent_fd < 0) { perror(grant); return 1; }
		if (ll_add(rs, LANDLOCK_RULE_PATH_BENEATH, &pb, 0)) {
			perror("add_rule"); return 1;
		}
		close(pb.parent_fd);
	}

	if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { perror("nnp"); return 1; }
	if (ll_self(rs, 0)) { perror("restrict_self"); return 1; }

	printf("granted=%-12s ", grant);

	/* sanity: a normal file open, to prove the rule itself works */
	f = open("/etc/hostname", O_RDONLY);
	printf("open(/etc/hostname)=%-14s ",
	       f >= 0 ? "OK" : strerror(errno));
	if (f >= 0) close(f);

	mq = mq_open("/foobar", O_CREAT | O_RDWR, 0600, NULL);
	printf("mq_open()=%s\n", mq != (mqd_t)-1 ? "OK" : strerror(errno));
	if (mq != (mqd_t)-1) mq_close(mq);
	return 0;
}
---

      parent reply	other threads:[~2026-08-21  8:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22 12:29 [PATCH 0/6] landlock: Add POSIX message queue scoping Oxana Kharitonova
2026-07-22 12:29 ` [PATCH 1/6] ipc: Move mqueue fs magic to uapi magic header Oxana Kharitonova
2026-07-22 12:43   ` Günther Noack
2026-07-22 15:14     ` Oxana Kharitonova
2026-07-22 12:29 ` [PATCH 2/6] landlock: Scope POSIX message queue opens Oxana Kharitonova
2026-07-23 21:59   ` Justin Suess
2026-07-28 11:03   ` Mickaël Salaün
2026-07-22 12:29 ` [PATCH 3/6] landlock: Bump ABI for LANDLOCK_SCOPE_POSIX_MSG_QUEUE Oxana Kharitonova
2026-07-28 11:03   ` Mickaël Salaün
2026-07-22 12:29 ` [PATCH 4/6] selftests/landlock: Test POSIX message queue scoping Oxana Kharitonova
2026-07-28 11:04   ` Mickaël Salaün
2026-07-22 12:29 ` [PATCH 5/6] samples/landlock: Support " Oxana Kharitonova
2026-07-28 11:04   ` Mickaël Salaün
2026-07-22 12:29 ` [PATCH 6/6] landlock: Document " Oxana Kharitonova
2026-07-28 11:02 ` [PATCH 0/6] landlock: Add " Mickaël Salaün
2026-07-29 12:43   ` Oxana Kharitonova
2026-08-21  8:46 ` Günther Noack [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260821.d42cd4b82f91@gnoack.org \
    --to=gnoack3000@gmail.com \
    --cc=gnoack@google.com \
    --cc=jmorris@namei.or \
    --cc=landlock@lists.linux.dev \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=oxana@cloudflare.com \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    --cc=wangyan01@kylinos.cn \
    --cc=webprosto@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox