linux/security/landlock
Mickaël Salaün cadb28f8b3 landlock: Fix handling of disconnected directories
[ Upstream commit 49c9e09d96 ]

Disconnected files or directories can appear when they are visible and
opened from a bind mount, but have been renamed or moved from the source
of the bind mount in a way that makes them inaccessible from the mount
point (i.e. out of scope).

Previously, access rights tied to files or directories opened through a
disconnected directory were collected by walking the related hierarchy
down to the root of the filesystem, without taking into account the
mount point because it couldn't be found. This could lead to
inconsistent access results, potential access right widening, and
hard-to-debug renames, especially since such paths cannot be printed.

For a sandboxed task to create a disconnected directory, it needs to
have write access (i.e. FS_MAKE_REG, FS_REMOVE_FILE, and FS_REFER) to
the underlying source of the bind mount, and read access to the related
mount point.   Because a sandboxed task cannot acquire more access
rights than those defined by its Landlock domain, this could lead to
inconsistent access rights due to missing permissions that should be
inherited from the mount point hierarchy, while inheriting permissions
from the filesystem hierarchy hidden by this mount point instead.

Landlock now handles files and directories opened from disconnected
directories by taking into account the filesystem hierarchy when the
mount point is not found in the hierarchy walk, and also always taking
into account the mount point from which these disconnected directories
were opened.  This ensures that a rename is not allowed if it would
widen access rights [1].

The rationale is that, even if disconnected hierarchies might not be
visible or accessible to a sandboxed task, relying on the collected
access rights from them improves the guarantee that access rights will
not be widened during a rename because of the access right comparison
between the source and the destination (see LANDLOCK_ACCESS_FS_REFER).
It may look like this would grant more access on disconnected files and
directories, but the security policies are always enforced for all the
evaluated hierarchies.  This new behavior should be less surprising to
users and safer from an access control perspective.

Remove a wrong WARN_ON_ONCE() canary in collect_domain_accesses() and
fix the related comment.

Because opened files have their access rights stored in the related file
security properties, there is no impact for disconnected or unlinked
files.

Cc: Christian Brauner <brauner@kernel.org>
Cc: Günther Noack <gnoack@google.com>
Cc: Song Liu <song@kernel.org>
Reported-by: Tingmao Wang <m@maowtm.org>
Closes: https://lore.kernel.org/r/027d5190-b37a-40a8-84e9-4ccbc352bcdf@maowtm.org
Closes: https://lore.kernel.org/r/09b24128f86973a6022e6aa8338945fcfb9a33e4.1749925391.git.m@maowtm.org
Fixes: b91c3e4ea7 ("landlock: Add support for file reparenting with LANDLOCK_ACCESS_FS_REFER")
Fixes: cb2c7d1a17 ("landlock: Support filesystem access-control")
Link: https://lore.kernel.org/r/b0f46246-f2c5-42ca-93ce-0d629702a987@maowtm.org [1]
Reviewed-by: Tingmao Wang <m@maowtm.org>
Link: https://lore.kernel.org/r/20251128172200.760753-2-mic@digikod.net
Signed-off-by: Mickaël Salaün <mic@digikod.net>
Signed-off-by: Sasha Levin <sashal@kernel.org>
History 2025-12-18 14:03:27 +01:00
..
errata landlock: Fix handling of disconnected directories 2025-12-18 14:03:27 +01:00
.kunitconfig landlock: Add unique ID generator 2025-03-26 13:59:34 +01:00
access.h landlock: Log truncate and IOCTL denials 2025-03-26 13:59:41 +01:00
audit.c landlock: Improve bit operations in audit code 2025-05-12 11:38:53 +02:00
audit.h landlock: Log scoped denials 2025-03-26 13:59:42 +01:00
common.h landlock: Add support for KUnit tests 2024-02-27 11:21:45 +01:00
cred.c landlock: Identify domain execution crossing 2025-03-26 13:59:37 +01:00
cred.h landlock: Add LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF 2025-03-26 13:59:43 +01:00
domain.c landlock: Log the TGID of the domain creator 2025-04-11 12:53:17 +02:00
domain.h landlock: Remove incorrect warning 2025-04-08 19:18:20 +02:00
errata.h landlock: Prepare to add second errata 2025-03-21 12:12:21 +01:00
fs.c landlock: Fix handling of disconnected directories 2025-12-18 14:03:27 +01:00
fs.h landlock: Log scoped denials 2025-03-26 13:59:42 +01:00
id.c landlock: Fix warning from KUnit tests 2025-06-27 10:10:37 +02:00
id.h landlock: Add unique ID generator 2025-03-26 13:59:34 +01:00
Kconfig landlock: Add support for KUnit tests 2024-02-27 11:21:45 +01:00
limits.h landlock: Add LANDLOCK_RESTRICT_SELF_LOG_SUBDOMAINS_OFF 2025-03-26 13:59:43 +01:00
Makefile landlock: Add AUDIT_LANDLOCK_ACCESS and log ptrace denials 2025-03-26 13:59:38 +01:00
net.c landlock: Log TCP bind and connect denials 2025-03-26 13:59:41 +01: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
ruleset.c landlock: Add AUDIT_LANDLOCK_DOMAIN and log domain status 2025-03-26 13:59:38 +01:00
ruleset.h landlock: Log mount-related denials 2025-03-26 13:59:39 +01:00
setup.c landlock: Add unique ID generator 2025-03-26 13:59:34 +01:00
setup.h landlock: Add the errata interface 2025-03-21 12:12:19 +01:00
syscalls.c landlock: opened file never has a negative dentry 2025-06-17 18:03:57 -04:00
task.c landlock: Log scoped denials 2025-03-26 13:59:42 +01:00
task.h landlock: Rename "ptrace" files to "task" 2024-03-08 18:22:16 +01:00