[PATCH -next -v2 6/8] lockdown: bound the status string with scnprintf

Nicolas Bouchinet nicolas.bouchinet at oss.cyber.gouv.fr
Tue Nov 24 15:34:52 UTC 2026


On Tue, 10 Nov 2026 21:28:16 +0800, Cai Xinchen <caixinchen1 at huawei.com> wrote:
> 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.
> 
> Store the level label strings in named arrays and point the matching
> lockdown_reasons[] entries at them.  Their sizes are compile-time
> constants, so a BUILD_BUG_ON() can verify that the status buffer is large
> enough for all level labels, their trailing spaces, and the brackets
> around the active one.
> 
> [...]

Reviewed-by: Nicolas Bouchinet <nicolas.bouchinet at oss.cyber.gouv.fr>

-- 
Nicolas Bouchinet <nicolas.bouchinet at oss.cyber.gouv.fr>



More information about the Linux-security-module-archive mailing list