[PATCH v4 6/8] lockdown: bound the status string with scnprintf

Nicolas Bouchinet nicolas.bouchinet at oss.cyber.gouv.fr
Mon Nov 30 14:53:11 UTC 2026


On Mon, 30 Nov 2026 16:29:12 +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
> 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 at oss.cyber.gouv.fr>

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



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