]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
drm/msm: Replace unsafe snprintf usage with scnprintf
authorEvan Lambert <veyga@veygax.dev>
Wed, 24 Dec 2025 12:44:22 +0000 (12:44 +0000)
committerDmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Wed, 24 Dec 2025 15:55:29 +0000 (17:55 +0200)
commit66691e272e40c91305f1704695e0cb340cd162ff
treeeb00c7e5811d62ec6e44a61d8eea3a66abdb36c7
parent88733a0b64872357e5ecd82b7488121503cb9cc6
drm/msm: Replace unsafe snprintf usage with scnprintf

The refill_buf function uses snprintf to append to a fixed-size buffer.
snprintf returns the length that would have been written, which can
exceed the remaining buffer size. If this happens, ptr advances beyond
the buffer and rem becomes negative. In the 2nd iteration, rem is
treated as a large unsigned integer, causing snprintf to write oob.

While this behavior is technically mitigated by num_perfcntrs being
locked at 5, it's still unsafe if num_perfcntrs were ever to change/a
second source was added.

Signed-off-by: Evan Lambert <veyga@veygax.dev>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
Patchwork: https://patchwork.freedesktop.org/patch/696358/
Link: https://lore.kernel.org/r/20251224124254.17920-3-veyga@veygax.dev
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@oss.qualcomm.com>
drivers/gpu/drm/msm/msm_perf.c