Linux Security Modules development
 help / color / mirror / Atom feed
* [PATCH v3 0/5] landlock: Fix REFER in layered domains
@ 2026-11-13 20:23 Günther Noack
  2026-11-13 20:23 ` [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Günther Noack @ 2026-11-13 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

This patchset fixes a bug in Landlock layering,
reported by Dwi Siswanto in [1] and [2].  (Thanks!)

The bug
=======

When Landlock initializes layer masks for path walk based checks, it
unconditionally adds the LANDLOCK_ACCESS_FS_REFER access right to the
handled access rights.

This leads to a wrong layer composition, in cases where the following
layers are stacked:

1. A FS layer restricting REFER, but also allowing REFER in a rule
   (e.g., handle REFER, but allow REFER on /)
2. A non-FS layer (e.g., networking-only layer)

When these rulesets are enforced **individually**, there are REFER
operations that are allowed in both rulesets -- the ones that 1
allows.

When these rulesets are enforced **on top of each other**, the non-FS
layer starts enforcing REFER implicitly as well, and all REFER
operations are denied.

This patchset
=============

This patchset fixes the issue in five commits:

1) The fix, which should be backportable to older kernels
   and which is CC'd to stable@.
2) KUnit test.
3) Regression selftests.
4) A more elegant fix for newer kernels,
   which is intentionally *not* CC'd to stable@,
   because it would break on older kernels.

   In newer kernels, we already add the "REFER" access right to the
   handled access rights when we merge the ruleset into the new
   domain, so there is no additional calculation to do for it.
5) A documentation update to clarify the situations where the *_REFER
   right is implicit.

Both the selftest and the KUnit test are built to fail before commit
1, work after commit 1 and continue working after commit 4.

Please let me know what you think!

–Günther

[1] https://github.com/landlock-lsm/go-landlock/issues/66
[2] https://github.com/landlock-lsm/linux/issues/67

---
Changes in v3:
- Add erratum 5 describing the issue
- Add KUnit test
- Selftests: Test the scenarios where layers are enforced in the other order
- access.h, fs_test.c: Update some remaining misdocumentation of the REFER right
- Link to v2: https://patch.msgid.link/20261108-b4-landlock-refer-nonfs-layer-v2-0-2b405fc1b3aa@gmail.com

Changes in v2:
- Rebase on master and resolve conflicts
- Fixed documentation as pointed out by Dwi Siswanto in
  https://lore.kernel.org/all/20261101125114.19009-1-me@dw1.io/
- Link to v1: https://patch.msgid.link/20261030102411.12985-1-gnoack3000@gmail.com

---
Günther Noack (5):
      landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER
      landlock: Add KUnit test for landlock_get_fs_access_mask()
      selftests/landlock: Test that layering does not break refer
      landlock: Simplify landlock_get_fs_access_mask()
      landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER

 include/uapi/linux/landlock.h              | 17 +++++----
 security/landlock/access.h                 | 13 ++++---
 security/landlock/domain.c                 | 44 +++++++++++++++++++++
 security/landlock/domain.h                 |  9 +++--
 security/landlock/errata/abi-4.h           | 21 ++++++++++
 tools/testing/selftests/landlock/fs_test.c | 61 ++++++++++++++++++++++++++++--
 6 files changed, 145 insertions(+), 20 deletions(-)
---
base-commit: fa4ad798f6f681031775266044ba1b0cf3c670bd
change-id: 20261108-b4-landlock-refer-nonfs-layer-fda8bcbe0b44

Best regards,
--  
Günther Noack <gnoack3000@gmail.com>


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER
  2026-11-13 20:23 [PATCH v3 0/5] landlock: Fix REFER in layered domains Günther Noack
@ 2026-11-13 20:23 ` Günther Noack
  2026-11-13 20:32   ` sashiko-bot
  2026-11-13 20:23 ` [PATCH v3 2/5] landlock: Add KUnit test for landlock_get_fs_access_mask() Günther Noack
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Günther Noack @ 2026-11-13 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 ++++++++++---
 security/landlock/errata/abi-4.h | 21 +++++++++++++++++++++
 2 files changed, 31 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
diff --git a/security/landlock/errata/abi-4.h b/security/landlock/errata/abi-4.h
index fe11ec7d7ddf..9784ca645073 100644
--- a/security/landlock/errata/abi-4.h
+++ b/security/landlock/errata/abi-4.h
@@ -20,3 +20,24 @@
  * that rely on these protocols while using Landlock network restrictions.
  */
 LANDLOCK_ERRATUM(1)
+
+/**
+ * DOC: erratum_5
+ *
+ * Erratum 5: Denial of ``LANDLOCK_ACCESS_FS_REFER`` in layered domains
+ * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ *
+ * This fix addresses an issue where ``LANDLOCK_ACCESS_FS_REFER`` was implicitly
+ * handled in domain layers that handle no filesystem access rights.
+ *
+ * With this fix, a reparenting operation is allowed in a layered Landlock
+ * domain if and only if each layer, enforced on its own, would allow it.
+ *
+ * Impact:
+ *
+ * In kernels without this fix, if a domain combined a layer that handles
+ * filesystem access rights with a layer that doesn't, the resulting layered
+ * domain would deny all ``LANDLOCK_ACCESS_FS_REFER`` operations, even when the
+ * filesystem layer granted these operations with a rule.
+ */
+LANDLOCK_ERRATUM(5)

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 2/5] landlock: Add KUnit test for landlock_get_fs_access_mask()
  2026-11-13 20:23 [PATCH v3 0/5] landlock: Fix REFER in layered domains Günther Noack
  2026-11-13 20:23 ` [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
@ 2026-11-13 20:23 ` Günther Noack
  2026-11-13 20:37   ` sashiko-bot
  2026-11-13 20:23 ` [PATCH v3 3/5] selftests/landlock: Test that layering does not break refer Günther Noack
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 11+ messages in thread
From: Günther Noack @ 2026-11-13 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

This checks that landlock_upgrade_handled_layer_config() and
landlock_get_fs_access_mask() together result in the right handled
access rights being reported by landlock_get_fs_access_mask():
LANDLOCK_ACCESS_FS_REFER is only implicit if any of the other
filesystem access rights are handled.

Signed-off-by: Günther Noack <gnoack3000@gmail.com>
---
 security/landlock/domain.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

diff --git a/security/landlock/domain.c b/security/landlock/domain.c
index 4c0b1f0e1db5..71756c68d08e 100644
--- a/security/landlock/domain.c
+++ b/security/landlock/domain.c
@@ -753,6 +753,49 @@ static void test_landlock_get_deny_masks(struct kunit *const test)
 					&layers1));
 }
 
+static void test_get_fs_access_mask(struct kunit *const test)
+{
+	static const struct {
+		struct layer_config config;
+		access_mask_t expected_fs;
+	} layers[] = {
+		{
+			.config.handled.net = LANDLOCK_ACCESS_NET_BIND_TCP,
+			.expected_fs = 0,
+		},
+		{
+			.config.handled.scope = LANDLOCK_SCOPE_SIGNAL,
+			.expected_fs = 0,
+		},
+		{
+			.config.handled.fs = LANDLOCK_ACCESS_FS_EXECUTE,
+			.expected_fs = LANDLOCK_ACCESS_FS_EXECUTE |
+				       LANDLOCK_ACCESS_FS_REFER,
+		},
+		{
+			.config.handled.fs = LANDLOCK_ACCESS_FS_REFER,
+			.expected_fs = LANDLOCK_ACCESS_FS_REFER,
+		},
+	};
+	struct landlock_domain *domain;
+	size_t i;
+
+	domain = kunit_kzalloc(test,
+			       struct_size(domain, layers, ARRAY_SIZE(layers)),
+			       GFP_KERNEL);
+	KUNIT_ASSERT_NOT_NULL(test, domain);
+	domain->num_layers = ARRAY_SIZE(layers);
+
+	for (i = 0; i < ARRAY_SIZE(layers); i++)
+		domain->layers[i] =
+			landlock_upgrade_handled_layer_config(layers[i].config);
+
+	for (i = 0; i < ARRAY_SIZE(layers); i++)
+		KUNIT_EXPECT_EQ_MSG(test, layers[i].expected_fs,
+				    landlock_get_fs_access_mask(domain, i),
+				    "layer %zu", i);
+}
+
 #endif /* CONFIG_SECURITY_LANDLOCK_KUNIT_TEST */
 
 #ifdef CONFIG_SECURITY_LANDLOCK_KUNIT_TEST
@@ -761,6 +804,7 @@ static struct kunit_case test_cases[] = {
 	/* clang-format off */
 	KUNIT_CASE(test_get_layer_deny_mask),
 	KUNIT_CASE(test_landlock_get_deny_masks),
+	KUNIT_CASE(test_get_fs_access_mask),
 	{}
 	/* clang-format on */
 };

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 3/5] selftests/landlock: Test that layering does not break refer
  2026-11-13 20:23 [PATCH v3 0/5] landlock: Fix REFER in layered domains Günther Noack
  2026-11-13 20:23 ` [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
  2026-11-13 20:23 ` [PATCH v3 2/5] landlock: Add KUnit test for landlock_get_fs_access_mask() Günther Noack
@ 2026-11-13 20:23 ` Günther Noack
  2026-11-13 20:44   ` sashiko-bot
  2026-11-13 20:23 ` [PATCH v3 4/5] landlock: Simplify landlock_get_fs_access_mask() Günther Noack
  2026-11-13 20:23 ` [PATCH v3 5/5] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER Günther Noack
  4 siblings, 1 reply; 11+ messages in thread
From: Günther Noack @ 2026-11-13 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

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
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>
---
 tools/testing/selftests/landlock/fs_test.c | 54 ++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index f725882fa4a7..6d9baab0fae8 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -2612,6 +2612,60 @@ 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, regardless of the layer order.
+ */
+static void test_layering_does_not_break_refer(
+	struct __test_metadata *const _metadata,
+	const struct landlock_ruleset_attr *const non_fs_attr,
+	const bool non_fs_first)
+{
+	ASSERT_EQ(0, unlink(file1_s1d2));
+
+	if (non_fs_first)
+		drop_access_rights(_metadata, non_fs_attr);
+
+	enforce_fs(_metadata, LANDLOCK_ACCESS_FS_REFER, layer_dir_s1d1_refer);
+
+	if (!non_fs_first)
+		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));
+}
+
+static const struct landlock_ruleset_attr net_attr = {
+	.handled_access_net = LANDLOCK_ACCESS_NET_BIND_TCP,
+};
+
+static const struct landlock_ruleset_attr scoped_attr = {
+	.scoped = LANDLOCK_SCOPE_SIGNAL,
+};
+
+TEST_F_FORK(layout1, layering_fs_then_net_does_not_break_refer)
+{
+	test_layering_does_not_break_refer(_metadata, &net_attr, false);
+}
+
+TEST_F_FORK(layout1, layering_net_then_fs_does_not_break_refer)
+{
+	test_layering_does_not_break_refer(_metadata, &net_attr, true);
+}
+
+TEST_F_FORK(layout1, layering_fs_then_scoped_does_not_break_refer)
+{
+	test_layering_does_not_break_refer(_metadata, &scoped_attr, false);
+}
+
+TEST_F_FORK(layout1, layering_scoped_then_fs_does_not_break_refer)
+{
+	test_layering_does_not_break_refer(_metadata, &scoped_attr, true);
+}
+
 /*
  * Tests walking through a denied root mount.
  */

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 4/5] landlock: Simplify landlock_get_fs_access_mask()
  2026-11-13 20:23 [PATCH v3 0/5] landlock: Fix REFER in layered domains Günther Noack
                   ` (2 preceding siblings ...)
  2026-11-13 20:23 ` [PATCH v3 3/5] selftests/landlock: Test that layering does not break refer Günther Noack
@ 2026-11-13 20:23 ` Günther Noack
  2026-11-13 20:47   ` sashiko-bot
  2026-11-13 20:23 ` [PATCH v3 5/5] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER Günther Noack
  4 siblings, 1 reply; 11+ messages in thread
From: Günther Noack @ 2026-11-13 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.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v3 5/5] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER
  2026-11-13 20:23 [PATCH v3 0/5] landlock: Fix REFER in layered domains Günther Noack
                   ` (3 preceding siblings ...)
  2026-11-13 20:23 ` [PATCH v3 4/5] landlock: Simplify landlock_get_fs_access_mask() Günther Noack
@ 2026-11-13 20:23 ` Günther Noack
  2026-11-13 20:49   ` sashiko-bot
  4 siblings, 1 reply; 11+ messages in thread
From: Günther Noack @ 2026-11-13 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                 | 13 +++++++------
 tools/testing/selftests/landlock/fs_test.c |  7 ++++---
 3 files changed, 20 insertions(+), 17 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..789ccfd9f669 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 ( \
@@ -178,8 +179,8 @@ static inline struct layer_config
 landlock_upgrade_handled_layer_config(struct layer_config layer_config)
 {
 	/*
-	 * All access rights that are denied by default whether they are
-	 * explicitly handled or not.
+	 * All filesystem access rights that are denied by default
+	 * as soon as any other filesystem access right is handled.
 	 */
 	if (layer_config.handled.fs)
 		layer_config.handled.fs |= _LANDLOCK_ACCESS_FS_INITIALLY_DENIED;
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 6d9baab0fae8..48c1f896dc9a 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -3034,8 +3034,8 @@ TEST_F_FORK(layout1, reparent_exdev_layers_rename1)
 
 	/*
 	 * Moving the file2_s1d3 file below dir_s2d3 is denied because the
-	 * second layer does not handle REFER, which is always denied by
-	 * default.
+	 * second layer does not handle REFER, which is always denied as soon as
+	 * any other filesystem access right is handled.
 	 */
 	ASSERT_EQ(-1, rename(file2_s1d3, file1_s2d3));
 	ASSERT_EQ(EXDEV, errno);
@@ -3073,7 +3073,8 @@ TEST_F_FORK(layout1, reparent_exdev_layers_rename2)
 	ASSERT_EQ(EXDEV, errno);
 	/*
 	 * Modifying the layout is now denied because the second layer does not
-	 * handle REFER, which is always denied by default.
+	 * handle REFER, which is always denied as soon as any other filesystem
+	 * access right is handled.
 	 */
 	ASSERT_EQ(-1, rename(file2_s1d2, file1_s2d3));
 	ASSERT_EQ(EXDEV, errno);

-- 
2.56.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER
  2026-11-13 20:23 ` [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
@ 2026-11-13 20:32   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-13 20:32 UTC (permalink / raw)
  Cc: linux-security-module

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-b4-landlock-refer-nonfs-layer-v3-0-02d7e42bcdfd@gmail.com?part=1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 2/5] landlock: Add KUnit test for landlock_get_fs_access_mask()
  2026-11-13 20:23 ` [PATCH v3 2/5] landlock: Add KUnit test for landlock_get_fs_access_mask() Günther Noack
@ 2026-11-13 20:37   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-13 20:37 UTC (permalink / raw)
  Cc: linux-security-module

> This checks that landlock_upgrade_handled_layer_config() and
> landlock_get_fs_access_mask() together result in the right handled
> access rights being reported by landlock_get_fs_access_mask():
> LANDLOCK_ACCESS_FS_REFER is only implicit if any of the other
> filesystem access rights are handled.
> 
> Signed-off-by: Günther Noack <gnoack3000@gmail.com>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-b4-landlock-refer-nonfs-layer-v3-0-02d7e42bcdfd@gmail.com?part=2


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 3/5] selftests/landlock: Test that layering does not break refer
  2026-11-13 20:23 ` [PATCH v3 3/5] selftests/landlock: Test that layering does not break refer Günther Noack
@ 2026-11-13 20:44   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-13 20:44 UTC (permalink / raw)
  Cc: linux-security-module

> 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
> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-b4-landlock-refer-nonfs-layer-v3-0-02d7e42bcdfd@gmail.com?part=3


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 4/5] landlock: Simplify landlock_get_fs_access_mask()
  2026-11-13 20:23 ` [PATCH v3 4/5] landlock: Simplify landlock_get_fs_access_mask() Günther Noack
@ 2026-11-13 20:47   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-13 20:47 UTC (permalink / raw)
  Cc: linux-security-module

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-b4-landlock-refer-nonfs-layer-v3-0-02d7e42bcdfd@gmail.com?part=4


^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v3 5/5] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER
  2026-11-13 20:23 ` [PATCH v3 5/5] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER Günther Noack
@ 2026-11-13 20:49   ` sashiko-bot
  0 siblings, 0 replies; 11+ messages in thread
From: sashiko-bot @ 2026-11-13 20:49 UTC (permalink / raw)
  Cc: linux-security-module

> 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>

Sashiko has reviewed this patch and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261113-b4-landlock-refer-nonfs-layer-v3-0-02d7e42bcdfd@gmail.com?part=5


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-13 20:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-13 20:23 [PATCH v3 0/5] landlock: Fix REFER in layered domains Günther Noack
2026-11-13 20:23 ` [PATCH v3 1/5] landlock: Fix layer composition of LANDLOCK_ACCESS_FS_REFER Günther Noack
2026-11-13 20:32   ` sashiko-bot
2026-11-13 20:23 ` [PATCH v3 2/5] landlock: Add KUnit test for landlock_get_fs_access_mask() Günther Noack
2026-11-13 20:37   ` sashiko-bot
2026-11-13 20:23 ` [PATCH v3 3/5] selftests/landlock: Test that layering does not break refer Günther Noack
2026-11-13 20:44   ` sashiko-bot
2026-11-13 20:23 ` [PATCH v3 4/5] landlock: Simplify landlock_get_fs_access_mask() Günther Noack
2026-11-13 20:47   ` sashiko-bot
2026-11-13 20:23 ` [PATCH v3 5/5] landlock: Clarify implicit handling of LANDLOCK_ACCESS_FS_REFER Günther Noack
2026-11-13 20:49   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox