linux/security/landlock
Mickaël Salaün d9818b3e90
landlock: Fix asymmetric private inodes referring
When linking or renaming a file, if only one of the source or
destination directory is backed by an S_PRIVATE inode, then the related
set of layer masks would be used as uninitialized by
is_access_to_paths_allowed().  This would result to indeterministic
access for one side instead of always being allowed.

This bug could only be triggered with a mounted filesystem containing
both S_PRIVATE and !S_PRIVATE inodes, which doesn't seem possible.

The collect_domain_accesses() calls return early if
is_nouser_or_private() returns false, which means that the directory's
superblock has SB_NOUSER or its inode has S_PRIVATE.  Because rename or
link actions are only allowed on the same mounted filesystem, the
superblock is always the same for both source and destination
directories.  However, it might be possible in theory to have an
S_PRIVATE parent source inode with an !S_PRIVATE parent destination
inode, or vice versa.

To make sure this case is not an issue, explicitly initialized both set
of layer masks to 0, which means to allow all actions on the related
side.  If at least on side has !S_PRIVATE, then
collect_domain_accesses() and is_access_to_paths_allowed() check for the
required access rights.

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Günther Noack <gnoack@google.com>
Cc: Jann Horn <jannh@google.com>
Cc: Shervin Oloumi <enlightened@chromium.org>
Cc: stable@vger.kernel.org
Fixes: b91c3e4ea7 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER")
Link: https://lore.kernel.org/r/20240219190345.2928627-1-mic@digikod.net
Signed-off-by: Mickaël Salaün <mic@digikod.net>
2024-02-26 18:23:53 +01:00
..
common.h landlock: Set up the security framework and manage credentials 2021-04-22 12:22:10 -07:00
cred.c LSM: Identify modules by more than name 2023-11-12 22:54:42 -05:00
cred.h landlock: Format with clang-format 2022-05-09 12:31:10 +02:00
fs.c landlock: Fix asymmetric private inodes referring 2024-02-26 18:23:53 +01:00
fs.h landlock: Support file truncation 2022-10-19 09:01:44 +02:00
Kconfig landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00
limits.h landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00
Makefile landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00
net.c LSM: Identify modules by more than name 2023-11-12 22:54:42 -05:00
net.h landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00
object.c landlock: Format with clang-format 2022-05-09 12:31:10 +02:00
object.h landlock: Format with clang-format 2022-05-09 12:31:10 +02:00
ptrace.c LSM: Identify modules by more than name 2023-11-12 22:54:42 -05:00
ptrace.h landlock: Add ptrace restrictions 2021-04-22 12:22:10 -07:00
ruleset.c landlock: Optimize the number of calls to get_access_mask slightly 2024-01-03 12:43:17 +01:00
ruleset.h landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00
setup.c LSM: Identify modules by more than name 2023-11-12 22:54:42 -05:00
setup.h LSM: Identify modules by more than name 2023-11-12 22:54:42 -05:00
syscalls.c landlock: Support network rules with TCP bind and connect 2023-10-26 21:07:15 +02:00