* [PATCH v2 1/4] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER
2026-11-08 20:23 [PATCH v2 0/4] landlock: Fix REFER in layered domains Günther Noack
@ 2026-11-08 20:23 ` Günther Noack
2026-11-08 20:34 ` sashiko-bot
2026-11-08 20:23 ` [PATCH v2 2/4] selftests/landlock: Test that layering does not break refer Günther Noack
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Günther Noack @ 2026-11-08 20:23 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Paul Moore, James Morris, Serge E. Hallyn, Konstantin Meskhidze,
Shuah Khan, Dwi Siswanto, linux-security-module, linux-kernel,
linux-kselftest, stable, Günther Noack
In landlock_get_fs_access_mask(), only add the
LANDLOCK_ACCESS_FS_REFER right if any filesystem access rights are
handled at all. This prevents us from accidentally treating
non-filesystem layers as if they handled LANDLOCK_ACCESS_FS_REFER.
landlock_get_fs_access_mask() is used when initializing the layer
masks for doing access right checks, so this bug meant that we
unintentionally denied "refer" (e.g., link, rename) operations in
layered cases, where the same operation would have been accepted if
only either one of the two layers had been enforced. If the rulesets
individually allow an operation, the composition of these rulesets
should also allow it.
The bug only manifests as soon as one other layer handles filesystem
access rights. Otherwise, Landlock filesystem path walk is guarded by
an early exit for the case that no filesystem-enforcing layer exists.
Reported-by: Dwi Siswanto <me@dw1.io>
Link: https://github.com/landlock-lsm/linux/issues/67
Link: https://github.com/landlock-lsm/go-landlock/issues/66
Fixes: fff69fb03dde ("landlock: Support network rules with TCP bind and connect")
Cc: stable@vger.kernel.org
Signed-off-by: Günther Noack <gnoack3000@gmail.com>
---
security/landlock/domain.h | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/security/landlock/domain.h b/security/landlock/domain.h
index 935e18b12b3c..d9ebf4857fce 100644
--- a/security/landlock/domain.h
+++ b/security/landlock/domain.h
@@ -262,9 +262,16 @@ static inline access_mask_t
landlock_get_fs_access_mask(const struct landlock_domain *const domain,
const u16 layer_level)
{
- /* Handles all initially denied by default access rights. */
- return domain->layers[layer_level].handled.fs |
- _LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
+ access_mask_t handled = domain->layers[layer_level].handled.fs;
+
+ /*
+ * Handles all initially denied by default access rights, but only for
+ * layers handling filesystem accesses.
+ */
+ if (handled)
+ handled |= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
+
+ return handled;
}
static inline access_mask_t
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 2/4] selftests/landlock: Test that layering does not break refer
2026-11-08 20:23 [PATCH v2 0/4] landlock: Fix REFER in layered domains Günther Noack
2026-11-08 20:23 ` [PATCH v2 1/4] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
@ 2026-11-08 20:23 ` Günther Noack
2026-11-08 20:31 ` sashiko-bot
2026-11-08 20:23 ` [PATCH v2 3/4] landlock: Simplify landlock_get_fs_access_mask() Günther Noack
2026-11-08 20:23 ` [PATCH v2 4/4] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER Günther Noack
3 siblings, 1 reply; 9+ messages in thread
From: Günther Noack @ 2026-11-08 20:23 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Paul Moore, James Morris, Serge E. Hallyn, Konstantin Meskhidze,
Shuah Khan, Dwi Siswanto, linux-security-module, linux-kernel,
linux-kselftest, Günther Noack
Regression test to exercise that layered Landlock domains do not
accidentally deny the LANDLOCK_ACCESS_FS_REFER access right. This
used to be the case when layering a non-filesystem ruleset with a
filesystem-enforcing ruleset. In that case, REFER operations that
would have been allowed for the individual rulesets would get denied
when layering the same rulesets.
Link: https://github.com/landlock-lsm/linux/issues/67
Link: https://github.com/landlock-lsm/go-landlock/issues/66
Signed-off-by: Günther Noack <gnoack3000@gmail.com>
---
tools/testing/selftests/landlock/fs_test.c | 39 ++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index f725882fa4a7..b92cb988a39f 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -2612,6 +2612,45 @@ TEST_F_FORK(layout1, refer_denied_by_default4)
layer_dir_s1d1_refer);
}
+/*
+ * Regression test for layered domains: The two enforced Landlock layers both do
+ * not restrict the tested "refer" operations on their own, so they should also
+ * not restrict them when they are layered.
+ */
+static void test_layering_does_not_break_refer(
+ struct __test_metadata *const _metadata,
+ const struct landlock_ruleset_attr *const non_fs_attr)
+{
+ ASSERT_EQ(0, unlink(file1_s1d2));
+
+ enforce_fs(_metadata, LANDLOCK_ACCESS_FS_REFER, layer_dir_s1d1_refer);
+
+ drop_access_rights(_metadata, non_fs_attr);
+
+ EXPECT_EQ(0, test_rename(file1_s1d1, file1_s1d2));
+ EXPECT_EQ(0, test_rename(file1_s1d2, file1_s1d1));
+ EXPECT_EQ(0, test_exchange(file2_s1d1, file2_s1d2));
+ EXPECT_EQ(0, test_exchange(file2_s1d2, file2_s1d1));
+}
+
+TEST_F_FORK(layout1, layering_with_net_does_not_break_refer)
+{
+ const struct landlock_ruleset_attr attr = {
+ .handled_access_net = LANDLOCK_ACCESS_NET_BIND_TCP,
+ };
+
+ test_layering_does_not_break_refer(_metadata, &attr);
+}
+
+TEST_F_FORK(layout1, layering_with_scoped_does_not_break_refer)
+{
+ const struct landlock_ruleset_attr attr = {
+ .scoped = LANDLOCK_SCOPE_SIGNAL,
+ };
+
+ test_layering_does_not_break_refer(_metadata, &attr);
+}
+
/*
* Tests walking through a denied root mount.
*/
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 3/4] landlock: Simplify landlock_get_fs_access_mask()
2026-11-08 20:23 [PATCH v2 0/4] landlock: Fix REFER in layered domains Günther Noack
2026-11-08 20:23 ` [PATCH v2 1/4] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
2026-11-08 20:23 ` [PATCH v2 2/4] selftests/landlock: Test that layering does not break refer Günther Noack
@ 2026-11-08 20:23 ` Günther Noack
2026-11-08 20:29 ` sashiko-bot
2026-11-08 20:23 ` [PATCH v2 4/4] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER Günther Noack
3 siblings, 1 reply; 9+ messages in thread
From: Günther Noack @ 2026-11-08 20:23 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Paul Moore, James Morris, Serge E. Hallyn, Konstantin Meskhidze,
Shuah Khan, Dwi Siswanto, linux-security-module, linux-kernel,
linux-kselftest, Günther Noack
Return the handled FS access mask as it is, instead of artificially
adding LANDLOCK_ACCESS_FS_REFER to it.
Since commit d6c7cf84a24f ("landlock: Simplify initially denied access
rights"), the merge operation already bakes the initially denied
access rights (LANDLOCK_ACCESS_FS_REFER) into the a layer's handled FS
access rights. -- They don't need to be added explicitly any more.
No functional change.
Signed-off-by: Günther Noack <gnoack3000@gmail.com>
---
security/landlock/domain.h | 12 ++++--------
1 file changed, 4 insertions(+), 8 deletions(-)
diff --git a/security/landlock/domain.h b/security/landlock/domain.h
index d9ebf4857fce..812c324cb6ef 100644
--- a/security/landlock/domain.h
+++ b/security/landlock/domain.h
@@ -262,16 +262,12 @@ static inline access_mask_t
landlock_get_fs_access_mask(const struct landlock_domain *const domain,
const u16 layer_level)
{
- access_mask_t handled = domain->layers[layer_level].handled.fs;
-
/*
- * Handles all initially denied by default access rights, but only for
- * layers handling filesystem accesses.
+ * Initially denied by default access rights are already included for
+ * layers handling filesystem accesses, see
+ * landlock_upgrade_handled_layer_config().
*/
- if (handled)
- handled |= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
-
- return handled;
+ return domain->layers[layer_level].handled.fs;
}
static inline access_mask_t
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH v2 4/4] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER
2026-11-08 20:23 [PATCH v2 0/4] landlock: Fix REFER in layered domains Günther Noack
` (2 preceding siblings ...)
2026-11-08 20:23 ` [PATCH v2 3/4] landlock: Simplify landlock_get_fs_access_mask() Günther Noack
@ 2026-11-08 20:23 ` Günther Noack
2026-11-08 20:32 ` sashiko-bot
3 siblings, 1 reply; 9+ messages in thread
From: Günther Noack @ 2026-11-08 20:23 UTC (permalink / raw)
To: Mickaël Salaün
Cc: Paul Moore, James Morris, Serge E. Hallyn, Konstantin Meskhidze,
Shuah Khan, Dwi Siswanto, linux-security-module, linux-kernel,
linux-kselftest, Günther Noack
The LANDLOCK_ACCESS_FS_REFER right is handled implicitly in a ruleset,
but only if any other filesystem access right is declared as handled
in the given ruleset.
The old documentation was still a remnant from the times when
filesystem access rights were the only access rights that existed in
Landlock, but it became misleading when we introduced additional types
of access rights.
Fixes: fff69fb03dde ("landlock: Support network rules with TCP bind and connect")
Signed-off-by: Günther Noack <gnoack3000@gmail.com>
---
include/uapi/linux/landlock.h | 17 +++++++++--------
security/landlock/access.h | 9 +++++----
2 files changed, 14 insertions(+), 12 deletions(-)
diff --git a/include/uapi/linux/landlock.h b/include/uapi/linux/landlock.h
index 24510e5d8479..7e38b9d1bf12 100644
--- a/include/uapi/linux/landlock.h
+++ b/include/uapi/linux/landlock.h
@@ -22,10 +22,10 @@
* enacted. Vice versa, access rights that are not specifically listed here are
* not going to be denied by this ruleset when it is enacted.
*
- * For historical reasons, the %LANDLOCK_ACCESS_FS_REFER right is always denied
- * by default, even when its bit is not set in @handled_access_fs. In order to
- * add new rules with this access right, the bit must still be set explicitly
- * (cf. `Filesystem flags`_).
+ * For historical reasons, as soon as any filesystem access right is handled in
+ * @handled_access_fs, the %LANDLOCK_ACCESS_FS_REFER right is always denied as
+ * well. In order to add new rules with this access right, the bit must still
+ * be set explicitly (cf. `Filesystem flags`_).
*
* The explicit listing of *handled access rights* is required for backwards
* compatibility reasons. In most use cases, processes that use Landlock will
@@ -462,10 +462,11 @@ struct landlock_capability_attr {
* This access right is available since the second version of the Landlock
* ABI.
*
- * This is the only access right which is denied by default by any ruleset,
- * even if the right is not specified as handled at ruleset creation time.
- * The only way to make a ruleset grant this right is to explicitly allow it
- * for a specific directory by adding a matching rule to the ruleset.
+ * This is the only access right which is denied by default by any ruleset
+ * that handles filesystem access rights, even if the right is not specified
+ * as handled at ruleset creation time. The only way to make a ruleset grant
+ * this right is to explicitly allow it for a specific directory by adding a
+ * matching rule to the ruleset.
*
* In particular, when using the first Landlock ABI version, Landlock will
* always deny attempts to reparent files between different directories.
diff --git a/security/landlock/access.h b/security/landlock/access.h
index f9eaa2f53686..c4a81f7dadeb 100644
--- a/security/landlock/access.h
+++ b/security/landlock/access.h
@@ -18,10 +18,11 @@
#include "limits.h"
/*
- * All access rights that are denied by default whether they are handled or not
- * by a ruleset/layer. This must be ORed with the .handled field of all
- * domain->layers[] entries when we need to get the absolute handled access
- * masks, see landlock_upgrade_handled_layer_config().
+ * All filesystem access rights that are denied by default as soon as any other
+ * filesystem access right is handled, even if the access right is not
+ * explicitly declared to be handled itself. This must be ORed with the
+ * .handled field of all domain->layers[] entries when we need to get the
+ * absolute handled access masks, see landlock_upgrade_handled_layer_config().
*/
/* clang-format off */
#define _LANDLOCK_ACCESS_FS_INITIALLY_DENIED ( \
--
2.56.0
^ permalink raw reply related [flat|nested] 9+ messages in thread