Skip to contentSkip to conversation

landlock: Add counted_by and fix comment in landlock_ruleset

PATCH In review Tingmao Wang 3 participants 3 messages Feb 8 – Feb 9

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

PATCH 1/1 landlock: Add counted_by and fix comment in landlock_ruleset

For a domain, this array stores the access masks for each layer (of which there are num_layers of them). For an unmerged ruleset, we have one "layer", and one element in this array. This annotation serves as useful documentation.

This also removes a comment saying that num_layers = 0 for unmerged rulesets, which is incorrect (it is 1).

---

I'm not sure if I should add a Fixes tag, but if I should had, it would be ae271c1b14 ("landlock: Add ruleset and domain management").

 security/landlock/ruleset.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
security/landlock/ruleset.h +3 -3
index 9d6dc632684c..7005840ac641 100644
@@ -168,8 +168,7 @@ struct landlock_ruleset {
 			/**
 			 * @num_layers: Number of layers that are used in this
 			 * ruleset.  This enables to check that all the layers
-			 * allow an access request.  A value of 0 identifies a
-			 * non-merged ruleset (i.e. not a domain).
+			 * allow an access request.
 			 */
 			u32 num_layers;
 			/**
@@ -184,7 +183,8 @@ struct landlock_ruleset {
 			 * layers are set once and never changed for the
 			 * lifetime of the ruleset.
 			 */
-			struct access_masks access_masks[];
+			struct access_masks
+				access_masks[] __counted_by(num_layers);
 		};
 	};
 };

base-commit: f179e1859c711214412876c57f56f9b0cfb13264

Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Tingmao Wang

For a domain, this array stores the access masks for each layer (of which there are num_layers of them). For an unmerged ruleset, we have one "layer", and one element in this array. This annotation serves as useful documentation.

This also removes a comment saying that num_layers = 0 for unmerged rulesets, which is incorrect (it is 1).

Thank you for fixing this! We should use these bounds check macros wherever we can, IMHO. Removing the remark about num_layers=0 is also correct.

—Günther

maintainer
#2 lore raw
In reply to Tingmao Wang

Thanks!

Quoted 46 lines · Tingmao Wang

For a domain, this array stores the access masks for each layer (of which there are num_layers of them). For an unmerged ruleset, we have one "layer", and one element in this array. This annotation serves as useful documentation.

This also removes a comment saying that num_layers = 0 for unmerged rulesets, which is incorrect (it is 1).

---

I'm not sure if I should add a Fixes tag, but if I should had, it would be ae271c1b14 ("landlock: Add ruleset and domain management").

 security/landlock/ruleset.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
security/landlock/ruleset.h +3 -3
index 9d6dc632684c..7005840ac641 100644
@@ -168,8 +168,7 @@ struct landlock_ruleset {
 			/**
 			 * @num_layers: Number of layers that are used in this
 			 * ruleset.  This enables to check that all the layers
-			 * allow an access request.  A value of 0 identifies a
-			 * non-merged ruleset (i.e. not a domain).
+			 * allow an access request.
 			 */
 			u32 num_layers;
 			/**
@@ -184,7 +183,8 @@ struct landlock_ruleset {
 			 * layers are set once and never changed for the
 			 * lifetime of the ruleset.
 			 */
-			struct access_masks access_masks[];
+			struct access_masks
+				access_masks[] __counted_by(num_layers);
 		};
 	};
 };

base-commit: f179e1859c711214412876c57f56f9b0cfb13264

Signature · 1 line
2.53.0