[PATCH v2 2/4] Landlock: Enforce MAKE_REG for POSIX message queue creation

sashiko-bot at kernel.org sashiko-bot at kernel.org
Mon Nov 2 15:06:25 UTC 2026


Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] landlock: incompatible hook_inode_create() signature omits mnt_idmap
- [High] landlock: user-triggerable WARN_ON_ONCE() in hook_inode_create()
- [High] landlock: hook_inode_create() breaks VFS create on mounted mqueuefs
- [Low] landlock: unnamed parameter in hook_inode_create() breaks gnu11 build
--

commit 8666d4a55fba496ff4bfd048b949b769a8d57ec6
Author: Oxana Kharitonova <webprosto at gmail.com>

Landlock: Enforce MAKE_REG for POSIX message queue creation

This commit adds an inode_create LSM hook in Landlock to enforce
LANDLOCK_ACCESS_FS_MAKE_REG when creating POSIX message queues before the
queue is created in the mqueue filesystem. It also documents the behavior and
adds selftests for POSIX message queue creation and opening.

> diff --git a/security/landlock/fs.c b/security/landlock/fs.c
> index 2ab67bcad1983..d5dcb19d5eb19 100644
> --- a/security/landlock/fs.c
> +++ b/security/landlock/fs.c
[ ... ]
> @@ -1676,6 +1677,35 @@ static int hook_path_truncate(const struct path *const path)
>  	return current_check_access_path(path, LANDLOCK_ACCESS_FS_TRUNCATE);
>  }
>  
> +/*
> + * Unlike regular file creation, mq_open(2) calls vfs_mkobj() directly and
> + * therefore does not trigger the path_mknod hook.  Use the mqueuefs mount
> + * associated with the current IPC namespace to recover the parent path.
> + */
> +static int hook_inode_create(struct inode *const dir,
> +			     struct dentry *const dentry, const umode_t)

[Severity: High]
Does hook_inode_create() in security/landlock/fs.c have the wrong function
signature for the inode_create LSM hook?

In include/linux/lsm_hook_defs.h, inode_create is declared with four
parameters, starting with const struct mnt_idmap *idmap:

    LSM_HOOK(int, 0, inode_create, const struct mnt_idmap *idmap,
             struct inode *dir, struct dentry *dentry, umode_t mode)

Because hook_inode_create() omits the leading idmap parameter, registering it
via LSM_HOOK_INIT(inode_create, hook_inode_create) in landlock_hooks fails to
build with -Werror=incompatible-pointer-types when CONFIG_SECURITY_LANDLOCK is
enabled (and would cause the mnt_idmap pointer to be passed as dir at
runtime).

[Severity: Low]
Also in hook_inode_create() in security/landlock/fs.c, the trailing
const umode_t parameter omits the parameter name.

Because the kernel builds with -std=gnu11 and supports GCC 8.1 and later,
while unnamed parameters in function definitions are a C23 feature only
supported starting in GCC 11, won't this fail to compile on GCC 8 through 10
with a "parameter name omitted" error?

> +{
> +	struct ipc_namespace *ipc_ns;
> +	struct vfsmount *mnt;
> +	struct path parent;
> +
> +	if (!landlock_is_posix_mqueue_fs(dir))
> +		return 0;
> +
> +	if (!current->nsproxy)
> +		return 0;
> +	ipc_ns = current->nsproxy->ipc_ns;
> +	if (!ipc_ns)
> +		return 0;
> +	mnt = ipc_ns->mq_mnt;
> +	if (WARN_ON_ONCE(!mnt || mnt->mnt_sb != dir->i_sb))
> +		return 0;

[Severity: High]
Can an unprivileged user trigger this WARN_ON_ONCE() in hook_inode_create()
(and bypass the check) by creating a file on a mounted mqueue filesystem from
another IPC namespace?

Although mq_open(2) calls vfs_mkobj(), mqueue_dir_inode_operations in
ipc/mqueue.c also defines .create = mqueue_create:

    static const struct inode_operations mqueue_dir_inode_operations = {
        .lookup = simple_lookup,
        .create = mqueue_create,
        .unlink = mqueue_unlink,
    };

This means VFS creation paths on a mounted mqueue filesystem also reach
security_inode_create() -> hook_inode_create():

    openat(O_CREAT) -> do_filp_open() -> path_openat() -> lookup_open()
      -> may_o_create() -> security_inode_create()

    mknodat(S_IFREG) -> filename_mknodat() -> vfs_create()
      -> security_inode_create()

If a process unshares into a new IPC namespace (for example via
unshare(CLONE_NEWUSER | CLONE_NEWIPC)) while retaining access to a mounted
mqueue filesystem from a previous IPC namespace (such as /dev/mqueue or an
open directory fd), dir->i_sb belongs to the mount's IPC namespace whereas
current->nsproxy->ipc_ns->mq_mnt->mnt_sb belongs to the new IPC namespace.
Calling open() with O_CREAT or mknod() with S_IFREG on that mount will then
cause mnt->mnt_sb != dir->i_sb and fire WARN_ON_ONCE().

> +
> +	parent.mnt = mnt;
> +	parent.dentry = dentry->d_parent;
> +	return current_check_access_path(&parent, LANDLOCK_ACCESS_FS_MAKE_REG);
> +}

[Severity: High]
When a Landlock-restricted task creates a queue via open(O_CREAT) or
mknod(S_IFREG) on a mounted mqueue filesystem (such as /dev/mqueue), does
constructing parent with ipc_ns->mq_mnt in hook_inode_create() break rules
attached to ancestor directories like /dev or /?

During open(O_CREAT) or mknod(S_IFREG) on /dev/mqueue/q, the VFS first checks
security_path_mknod() with the real user mount path, which walks up across the
/dev/mqueue mountpoint to /dev and / via follow_up() in
is_access_to_paths_allowed():

    jump_up:
        if (walker_path.dentry == walker_path.mnt->mnt_root) {
            if (follow_up(&walker_path)) {
                /* Ignores hidden mount points. */
                goto jump_up;
            } else {
                break;
            }
        }

However, may_o_create() and vfs_create() then call security_inode_create() ->
hook_inode_create(), which replaces the mount with the internal kernel mount
ipc_ns->mq_mnt. Because ipc_ns->mq_mnt is unattached, follow_up() returns
false at mnt_root and stops the walk before reaching /dev or /, causing
current_check_access_path() to deny the creation with -EACCES unless a rule
was added directly on /dev/mqueue itself.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261102144708.920232-1-webprosto@gmail.com?part=2



More information about the Linux-security-module-archive mailing list