Skip to contentSkip to conversation

landlock/ruleset: Minor comments improvements

PATCH In review Tingmao Wang 2 participants 5 messages May 27, 2025 – Jul 22, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 landlock/ruleset: Minor comments improvements

Hi Mickaël,

This patch contains some small comment changes. The first three I sort of made along the way while working on / trying to understand landlock, and the last one was from the hashtable patch but extracted here.

---
 security/landlock/ruleset.c | 11 ++++++++++-
 security/landlock/ruleset.h |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)
security/landlock/ruleset.c +10 -1
index ce7940efea51..2ed7043ed2f2 100644
@@ -83,6 +83,10 @@ static void build_check_rule(void)
 		.num_layers = ~0,
 	};
 
+	/*
+	 * Check that .num_layers is large enough for at least
+	 * LANDLOCK_MAX_NUM_LAYERS layers
+	 */
 	BUILD_BUG_ON(rule.num_layers < LANDLOCK_MAX_NUM_LAYERS);
 }
 
@@ -290,6 +294,10 @@ static void build_check_layer(void)
 		.access = ~0,
 	};
 
+	/*
+	 * Check that .level and .access are large enough to contain their
+	 * expected max values.
+	 */
 	BUILD_BUG_ON(layer.level < LANDLOCK_MAX_NUM_LAYERS);
 	BUILD_BUG_ON(layer.access < LANDLOCK_MASK_ACCESS_FS);
 }
@@ -645,7 +653,8 @@ bool landlock_unmask_layers(const struct landlock_rule *const rule,
 
 		/*
 		 * Records in @layer_masks which layer grants access to each
-		 * requested access.
+		 * requested access (bit in layer mask cleared if layer grants
+		 * access).
 		 */
 		is_empty = true;
 		for_each_set_bit(access_bit, &access_req, masks_array_size) {
security/landlock/ruleset.h +1 -1
index 5da9a64f5af7..dfd883a9a52a 100644
@@ -27,7 +27,7 @@ struct landlock_hierarchy;
  */
 struct landlock_layer {
 	/**
-	 * @level: Position of this layer in the layer stack.
+	 * @level: Position of this layer in the layer stack. Starts from 1.
 	 */
 	u16 level;
 	/**

base-commit: a5806cd506af5a7c19bcd596e4708b5c464bfd21

Signature · 1 line
2.49.0
#1 lore raw

PATCH 1/1 Another one

Hi Mickaël, here is another one which I found would have been helpful to me when reading this. You can squash this with the earlier patch.

---
 security/landlock/fs.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
security/landlock/fs.c +2 -1
index 6fee7c20f64d..9396d2d9df40 100644
@@ -714,7 +714,8 @@ static void test_is_eacces_with_write(struct kunit *const test)
  * is_access_to_paths_allowed - Check accesses for requests with a common path
  *
  * @domain: Domain to check against.
- * @path: File hierarchy to walk through.
+ * @path: File hierarchy to walk through.  For refer checks, this would be
+ *     the common mountpoint.
  * @access_request_parent1: Accesses to check, once @layer_masks_parent1 is
  *     equal to @layer_masks_parent2 (if any).  This is tied to the unique
  *     requested path for most actions, or the source in case of a refer action
Signature · 1 line
2.49.0
#2 lore raw
In reply to Tingmao Wang

As discussed in chat, here is another one for you to consider and squash :)

Current comment here is IMO a bit confusing - it says "Only allow ... internal filesystems" but that's not the case.

---
 security/landlock/fs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
security/landlock/fs.c +4 -3
index 9396d2d9df40..11b469002c03 100644
@@ -911,9 +911,10 @@ static bool is_access_to_paths_allowed(
 		}
 		if (unlikely(IS_ROOT(walker_path.dentry))) {
 			/*
-			 * Stops at disconnected root directories.  Only allows
-			 * access to internal filesystems (e.g. nsfs, which is
-			 * reachable through /proc/<pid>/ns/<namespace>).
+			 * Stops at disconnected root directories.  Allows access to
+			 * internal filesystems (e.g. nsfs, which is reachable through
+			 * /proc/<pid>/ns/<namespace>), in addition to what's already
+			 * allowed.
 			 */
 			if (walker_path.mnt->mnt_flags & MNT_INTERNAL) {
 				allowed_parent1 = true;

--
2.49.0

maintainer
#3 lore raw

I updated the comments with the disconnected directory patch series, and I took this patch into account. Thanks!

Quoted 31 lines · Tingmao Wang

As discussed in chat, here is another one for you to consider and squash :)

Current comment here is IMO a bit confusing - it says "Only allow ... internal filesystems" but that's not the case.

---
 security/landlock/fs.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
security/landlock/fs.c +4 -4
index 9396d2d9df40..11b469002c03 100644
@@ -911,9 +911,10 @@ static bool is_access_to_paths_allowed(
 		}
 		if (unlikely(IS_ROOT(walker_path.dentry))) {
 			/*
-			 * Stops at disconnected root directories.  Only allows
-			 * access to internal filesystems (e.g. nsfs, which is
-			 * reachable through /proc/<pid>/ns/<namespace>).
+			 * Stops at disconnected root directories.  Allows access to
+			 * internal filesystems (e.g. nsfs, which is reachable through
+			 * /proc/<pid>/ns/<namespace>), in addition to what's already
+			 * allowed.
 			 */
 			if (walker_path.mnt->mnt_flags & MNT_INTERNAL) {
 				allowed_parent1 = true;
--

2.49.0

maintainer
#4 lore raw
In reply to Tingmao Wang

I squash with patch with the fs.c one. They are now in my -next tree. Thanks!

Quoted 67 lines · Tingmao Wang

Hi Mickaël,

This patch contains some small comment changes. The first three I sort of made along the way while working on / trying to understand landlock, and the last one was from the hashtable patch but extracted here.

---
 security/landlock/ruleset.c | 11 ++++++++++-
 security/landlock/ruleset.h |  2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)
security/landlock/ruleset.c +10 -1
index ce7940efea51..2ed7043ed2f2 100644
@@ -83,6 +83,10 @@ static void build_check_rule(void)
 		.num_layers = ~0,
 	};
 
+	/*
+	 * Check that .num_layers is large enough for at least
+	 * LANDLOCK_MAX_NUM_LAYERS layers
+	 */
 	BUILD_BUG_ON(rule.num_layers < LANDLOCK_MAX_NUM_LAYERS);
 }
 
@@ -290,6 +294,10 @@ static void build_check_layer(void)
 		.access = ~0,
 	};
 
+	/*
+	 * Check that .level and .access are large enough to contain their
+	 * expected max values.
+	 */
 	BUILD_BUG_ON(layer.level < LANDLOCK_MAX_NUM_LAYERS);
 	BUILD_BUG_ON(layer.access < LANDLOCK_MASK_ACCESS_FS);
 }
@@ -645,7 +653,8 @@ bool landlock_unmask_layers(const struct landlock_rule *const rule,
 
 		/*
 		 * Records in @layer_masks which layer grants access to each
-		 * requested access.
+		 * requested access (bit in layer mask cleared if layer grants
+		 * access).
 		 */
 		is_empty = true;
 		for_each_set_bit(access_bit, &access_req, masks_array_size) {
security/landlock/ruleset.h +1 -1
index 5da9a64f5af7..dfd883a9a52a 100644
@@ -27,7 +27,7 @@ struct landlock_hierarchy;
  */
 struct landlock_layer {
 	/**
-	 * @level: Position of this layer in the layer stack.
+	 * @level: Position of this layer in the layer stack. Starts from 1.
 	 */
 	u16 level;
 	/**

base-commit: a5806cd506af5a7c19bcd596e4708b5c464bfd21

Signature · 1 line
2.49.0