landlock: Clean up ruleset validation checks
Subsystems (2)
Mickaël Salaün
maintainerPATCH 1/1 landlock: Clean up ruleset validation checks
landlock_merge_ruleset() checks for a NULL ruleset after dereferencing it in lockdep_assert_held(). Move the assertion after the check so the defensive path remains effective.
The mask-validation comment originated in landlock_add_fs_access_mask() to explain that its WARN_ON_ONCE() checked a caller invariant. It became self-referential when this helper and its network and scope counterparts were inlined into landlock_create_ruleset(). Restate the invariant without naming the caller.
Keep both as defensive callee checks. Moving the assertion preserves the NULL check's ability to warn and return -EINVAL, while invalid masks remain warned about and masked.
--- security/landlock/domain.c | 3 ++- security/landlock/ruleset.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)
security/landlock/domain.c +2 -1
@@ -439,10 +439,11 @@ landlock_merge_ruleset(struct landlock_domain *const parent,int err;might_sleep (); -lockdep_assert_held (&ruleset->lock);if (WARN_ON_ONCE (!ruleset))return ERR_PTR (-EINVAL ); +lockdep_assert_held (&ruleset->lock); +if (parent) {if (parent->num_layers >=LANDLOCK_MAX_NUM_LAYERS )return ERR_PTR (-E2BIG );
security/landlock/ruleset.c +1 -1
@@ -58,7 +58,7 @@ landlock_create_ruleset(const access_mask_t fs_access_mask, new_ruleset->id =landlock_get_id_range (1 );#endif /* CONFIG_TRACEPOINTS */ -/* Should already be checked in landlock_create_ruleset(). */ +/* The caller must only pass supported access rights and scopes. */ if (fs_access_mask) {const access_mask_t mask = fs_access_mask &LANDLOCK_MASK_ACCESS_FS ;
Signature · 1 line
2.55.0
Quoted 56 lines · Mickaël Salaün
landlock_merge_ruleset()checks for a NULL ruleset after dereferencing it inlockdep_assert_held(). Move the assertion after the check so the defensive path remains effective.The mask-validation comment originated in
landlock_add_fs_access_mask()to explain that itsWARN_ON_ONCE()checked a caller invariant. It became self-referential when this helper and its network and scope counterparts were inlined intolandlock_create_ruleset(). Restate the invariant without naming the caller.Keep both as defensive callee checks. Moving the assertion preserves the NULL check's ability to warn and return
-EINVAL, while invalid masks remain warned about and masked.Reported-by Günther Noack <[email protected]>Signed-off-by Mickaël Salaün <[email protected]>--- security/landlock/domain.c | 3 ++- security/landlock/ruleset.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-)security/landlock/domain.c +2
-1@@ -439,10 +439,11 @@ landlock_merge_ruleset(struct landlock_domain *const parent,int err;might_sleep (); -lockdep_assert_held (&ruleset->lock);if (WARN_ON_ONCE (!ruleset))return ERR_PTR (-EINVAL ); +lockdep_assert_held (&ruleset->lock); +if (parent) {if (parent->num_layers >=LANDLOCK_MAX_NUM_LAYERS )return ERR_PTR (-E2BIG );security/landlock/ruleset.c +1
-1@@ -58,7 +58,7 @@ landlock_create_ruleset(const access_mask_t fs_access_mask, new_ruleset->id =landlock_get_id_range (1 );#endif /* CONFIG_TRACEPOINTS */ -/* Should already be checked in landlock_create_ruleset(). */ +/* The caller must only pass supported access rights and scopes. */ if (fs_access_mask) {const access_mask_t mask = fs_access_mask &LANDLOCK_MASK_ACCESS_FS ;Signature · 1 line
2.55.0
Thanks!
—Günther