Re: [PATCH v4 6/8] lockdown: bound the status string with scnprintf
From: Nicolas Bouchinet
Date: Mon Nov 30 2026 - 09:53:46 EST
On Mon, 30 Nov 2026 16:29:12 +0800, Cai Xinchen <caixinchen1@xxxxxxxxxx> wrote:
> Use scnprintf() instead of sprintf() when composing the lockdown status
> string in lockdown_read(). The current set of levels fits well within the
> status 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 the status buffer itself can be sized for the string it
> holds: all three level labels with their trailing spaces, the
> brackets around the active one, and the terminating NUL. Whichever
> level is active, the string has the same length. The label sizeof()
> values include their own NULs, so only three more bytes are needed.
>
> [...]
Reviewed-by: Nicolas Bouchinet <nicolas.bouchinet@xxxxxxxxxxxxxxxxx>
--
Nicolas Bouchinet <nicolas.bouchinet@xxxxxxxxxxxxxxxxx>