video: fbdev: via: refactor strcpy and viafb_name
PATCH v2 1/1 video: fbdev: via: refactor strcpy and viafb_name
Replace the deprecated and unbounded strcpy() function with the safer strscpy() alternative when setting up the framebuffer fixed screen information [1][2].
It aligns this driver with the ongoing kernel-wide security initiative to eliminate unbounded string copies, hardening the code against future modifications.
Additionally, convert the file-scope viafb_name pointer into a static const char[] array and update its value to "viafb". This permits the compiler to execute compile-time bounds checking and aggressively optimize the runtime string copy operation out entirely.
This is a proactive API cleanup and there is no functional performance or truncation risk.
---
v2:
- Keep variable static but change it to a const array
'static const char viafb_name[] = "viafb"' as suggested by Helge Deller to let the compiler leverage compile-time checks.
drivers/video/fbdev/via/viafbdev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/video/fbdev/via/viafbdev.c +2 -2
@@ -16,7 +16,7 @@#define _MASTER_FILE#include "global.h" -static char *viafb_name ="Via" ; +static const char viafb_name[] ="viafb" ;static u32 pseudo_pal[17 ];/* video mode */
@@ -144,7 +144,7 @@ static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, struct viafb_par *viaparinfo) {memset (fix,0 ,sizeof (struct fb_fix_screeninfo )); -strcpy (fix->id, viafb_name); +strscpy (fix->id, viafb_name,sizeof (fix->id)); fix->smem_start = viaparinfo->fbmem; fix->smem_len = viaparinfo->fbmem_free;
Signature · 1 line
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Critical] Changing the driver identification string exposed in the fb_fix_screeninfo structure from…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Changing the driver identification string exposed in the fb_fix_screeninfo structure from "Via" to "viafb" breaks userspace ABI backward compatibility. --
--- Patch [1]: [PATCH v2] video: fbdev: via: refactor strcpy and viafb_name --- commit 31193988a75e693bb97d9723171d248ff11a2f17
Author: Ajith P V <[email protected]>
video: fbdev: via: refactor strcpy and viafb_name
This commit replaces unbounded strcpy() calls with strscpy() to harden the framebuffer screen info initialization. It also converts the viafb_name pointer into a static const char array and changes its string value.
drivers/video/fbdev/via/viafbdev.c line 19
Quoted 10 lines
drivers/video/fbdev/via/viafbdev.c +1
-1@@ -16,7 +16,7 @@#define _MASTER_FILE#include "global.h" -static char *viafb_name ="Via" ; +static const char viafb_name[] ="viafb" ;
[Severity: Critical]
Does changing this string from "Via" to "viafb" cause a userspace ABI regression?
Userspace tools and display servers, such as Xorg's via driver, often rely on the exact identification string returned in the id field of fb_fix_screeninfo by the framebuffer ioctl to detect hardware and apply specific quirks.
Could the compile-time bounds checking and optimization benefits still be achieved without modifying the exposed string value, perhaps by defining it as 'static const char viafb_name[] = "Via";' instead?
Quoted 3 lines
drivers/video/fbdev/via/viafbdev.c +0
-0static u32 pseudo_pal[17 ];/* video mode */
[ ... ]
Quoted 9 lines
drivers/video/fbdev/via/viafbdev.c +1
-1@@ -144,7 +144,7 @@ static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix, struct viafb_par *viaparinfo) {memset (fix,0 ,sizeof (struct fb_fix_screeninfo )); -strcpy (fix->id, viafb_name); +strscpy (fix->id, viafb_name,sizeof (fix->id)); fix->smem_start = viaparinfo->fbmem; fix->smem_len = viaparinfo->fbmem_free;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1