aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
authorGünther Noack <gnoack3000@gmail.com>2026-03-27 17:48:30 +0100
committerMickaël Salaün <mic@digikod.net>2026-04-07 18:51:07 +0200
commita46e32db1fb7acac49a35773345d4bcf343847f5 (patch)
tree57c2371e0f8cc6614a5df559188691764d1c51e3 /security
parentae97330d1bd6a97646c2842d117577236cb40913 (diff)
downloadlinux-next-history-a46e32db1fb7acac49a35773345d4bcf343847f5.tar.gz
landlock: Clarify BUILD_BUG_ON check in scoping logic
The BUILD_BUG_ON check in domain_is_scoped() and unmask_scoped_access() should check that the loop that counts down client_layer finishes. We therefore check that the numbers LANDLOCK_MAX_NUM_LAYERS-1 and -1 are both representable by that integer. If they are representable, the numbers in between are representable too, and the loop finishes. Signed-off-by: Günther Noack <gnoack3000@gmail.com> Link: https://lore.kernel.org/r/20260327164838.38231-6-gnoack3000@gmail.com Signed-off-by: Mickaël Salaün <mic@digikod.net>
Diffstat (limited to 'security')
-rw-r--r--security/landlock/fs.c9
-rw-r--r--security/landlock/task.c9
2 files changed, 12 insertions, 6 deletions
diff --git a/security/landlock/fs.c b/security/landlock/fs.c
index fcf69b3d734d6..c1ecfe2390326 100644
--- a/security/landlock/fs.c
+++ b/security/landlock/fs.c
@@ -1595,10 +1595,13 @@ static void unmask_scoped_access(const struct landlock_ruleset *const client,
return;
/*
- * client_layer must be a signed integer with greater capacity
- * than client->num_layers to ensure the following loop stops.
+ * client_layer must be able to represent all numbers from
+ * LANDLOCK_MAX_NUM_LAYERS - 1 to -1 for the loop below to terminate.
+ * (It must be large enough, and it must be signed.)
*/
- BUILD_BUG_ON(sizeof(client_layer) > sizeof(client->num_layers));
+ BUILD_BUG_ON(!is_signed_type(typeof(client_layer)));
+ BUILD_BUG_ON(LANDLOCK_MAX_NUM_LAYERS - 1 >
+ type_max(typeof(client_layer)));
client_layer = client->num_layers - 1;
client_walker = client->hierarchy;
diff --git a/security/landlock/task.c b/security/landlock/task.c
index f2dbdebf2770a..6d46042132ce1 100644
--- a/security/landlock/task.c
+++ b/security/landlock/task.c
@@ -191,10 +191,13 @@ static bool domain_is_scoped(const struct landlock_ruleset *const client,
client_layer = client->num_layers - 1;
client_walker = client->hierarchy;
/*
- * client_layer must be a signed integer with greater capacity
- * than client->num_layers to ensure the following loop stops.
+ * client_layer must be able to represent all numbers from
+ * LANDLOCK_MAX_NUM_LAYERS - 1 to -1 for the loop below to terminate.
+ * (It must be large enough, and it must be signed.)
*/
- BUILD_BUG_ON(sizeof(client_layer) > sizeof(client->num_layers));
+ BUILD_BUG_ON(!is_signed_type(typeof(client_layer)));
+ BUILD_BUG_ON(LANDLOCK_MAX_NUM_LAYERS - 1 >
+ type_max(typeof(client_layer)));
server_layer = server ? (server->num_layers - 1) : -1;
server_walker = server ? server->hierarchy : NULL;