[PATCH -next 3/9] lockdown: bound the status string with scnprintf
Cai Xinchen
caixinchen1 at huawei.com
Tue Nov 3 08:24:15 UTC 2026
Use scnprintf() instead of sprintf() when composing the lockdown status
string in lockdown_read(). The current set of levels fits well within the
80 byte buffer, but sprintf() provides no protection if more or longer
labels are added later. scnprintf() makes the buffer bounds explicit.
Signed-off-by: Cai Xinchen <caixinchen1 at huawei.com>
---
security/lockdown/lockdown.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/security/lockdown/lockdown.c b/security/lockdown/lockdown.c
index 8648508d49b2..b6f99b9179b9 100644
--- a/security/lockdown/lockdown.c
+++ b/security/lockdown/lockdown.c
@@ -106,9 +106,13 @@ static ssize_t lockdown_read(struct file *filp, char __user *buf, size_t count,
const char *label = lockdown_reasons[level];
if (kernel_locked_down == level)
- offset += sprintf(temp+offset, "[%s] ", label);
+ offset += scnprintf(temp + offset,
+ sizeof(temp) - offset,
+ "[%s] ", label);
else
- offset += sprintf(temp+offset, "%s ", label);
+ offset += scnprintf(temp + offset,
+ sizeof(temp) - offset,
+ "%s ", label);
}
}
--
2.18.0.huawei.25
More information about the Linux-security-module-archive
mailing list