Coverity: drm_mode_parse_cmdline_named_mode(): Security best practices violations

From: coverity-bot
Date: Thu Nov 17 2022 - 17:20:00 EST


Hello!

This is an experimental semi-automated report about issues detected by
Coverity from a scan of next-20221117 as part of the linux-next scan project:
https://scan.coverity.com/projects/linux-next-weekly-scan

You're getting this email because you were associated with the identified
lines of code (noted below) that were touched by commits:

Tue Nov 15 10:09:44 2022 +0100
a7ab155397dd ("drm/modes: Switch to named mode descriptors")

Coverity reported the following:

*** CID 1527354: Security best practices violations (STRING_OVERFLOW)
drivers/gpu/drm/drm_modes.c:1812 in drm_mode_parse_cmdline_named_mode()
1806 int ret;
1807
1808 ret = str_has_prefix(name, mode->name);
1809 if (ret != name_end)
1810 continue;
1811
vvv CID 1527354: Security best practices violations (STRING_OVERFLOW)
vvv You might overrun the 32-character fixed-size string "cmdline_mode->name" by copying "mode->name" without checking the length.
1812 strcpy(cmdline_mode->name, mode->name);
1813 cmdline_mode->pixel_clock = mode->pixel_clock_khz;
1814 cmdline_mode->xres = mode->xres;
1815 cmdline_mode->yres = mode->yres;
1816 cmdline_mode->interlace = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
1817 cmdline_mode->specified = true;

If this is a false positive, please let us know so we can mark it as
such, or teach the Coverity rules to be smarter. If not, please make
sure fixes get into linux-next. :) For patches fixing this, please
include these lines (but double-check the "Fixes" first):

Reported-by: coverity-bot <keescook+coverity-bot@xxxxxxxxxxxx>
Addresses-Coverity-ID: 1527354 ("Security best practices violations")
Fixes: a7ab155397dd ("drm/modes: Switch to named mode descriptors")

Since mode->name is unbounded, this may overrun cmdline_mode->name
without CONFIG_FORTIFY_SOURCE=y. Please use strscpy().

Thanks for your attention!

--
Coverity-bot