[PATCH v4 1/8] lockdown: Add break in lockdown_write
From: Cai Xinchen
Date: Mon Nov 30 2026 - 02:58:21 EST
After the label is matched successfully, no other iteration can match,
so comparing the state against the remaining levels is meaningless.
Leave the loop as soon as the level is matched.
The level labels are distinct, so at most one iteration can match and
the behaviour is unchanged.
Tested-by: Guicai Ma <maguicai@xxxxxxxxxx>
Reviewed-by: Nicolas Bouchinet <nicolas.bouchinet@xxxxxxxxxxxxxxxxx>
Signed-off-by: Cai Xinchen <caixinchen1@xxxxxxxxxx>
---
security/lockdown/lockdown.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c
index 8d46886d2cca..263dcc80d839 100644
--- a/security/lockdown/lockdown.c
+++ b/security/lockdown/lockdown.c
@@ -139,8 +139,10 @@ static ssize_t lockdown_write(struct file *file, const char __user *buf,
enum lockdown_reason level = lockdown_levels[i];
const char *label = lockdown_reasons[level];
- if (label && !strcmp(state, label))
+ if (label && !strcmp(state, label)) {
err = lock_kernel_down("securityfs", level);
+ break;
+ }
}
kfree(state);
--
2.18.0.huawei.25