video: fbdev: via: refactor strcpy and viafb_name
PATCH v4 1/1 video: fbdev: via: refactor strcpy and viafb_name
Eliminate the single-use file-scope variable viafb_name and pass the "Via" string literal directly to strcpy().
Since "Via" is a literal constant, the compiler safely executes compile-time bounds checking during fortify verification. This satisfies the security initiative requirements while minimizing code complexity.
---
v4:
- Drop the variable entirely and use the literal string directly in strcpy() as suggested by Helge Deller.
v3:
- Restore the original "Via" string value to prevent userspace ABI regressions, while keeping the 'static const char[]' optimization as suggested by Sashiko AI.
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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/video/fbdev/via/viafbdev.c +1 -2
@@ -16,7 +16,6 @@#define _MASTER_FILE#include "global.h" -static char *viafb_name ="Via" ;static u32 pseudo_pal[17 ];/* video mode */
@@ -144,7 +143,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); +strcpy (fix->id,"Via" ); 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:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [Critical] Struct memory copy corrupts bl_curve_mutex state inside the allocated secondary framebuffer structure. --
--- Patch [1]: [PATCH v4] video: fbdev: via: refactor strcpy and viafb_name --- commit 89ff079954842cbfcf9a3daa9bead9f4e5a2902d
Author: Ajith P V <[email protected]>
video: fbdev: via: refactor strcpy and viafb_name
Eliminate the single-use file-scope variable viafb_name and pass the "Via" string literal directly to strcpy().
drivers/video/fbdev/via/viafbdev.c line 21
Quoted 12 lines
drivers/video/fbdev/via/viafbdev.c +0
-1@@ -16,7 +16,6 @@#define _MASTER_FILE#include "global.h" -static char *viafb_name ="Via" ;static u32 pseudo_pal[17 ];/* video mode */
[ ... ]
[Severity: Critical]
This is a pre-existing issue, but does this struct memory copy cause a regression by corrupting the bl_curve_mutex state inside the allocated secondary framebuffer structure?
drivers/video/fbdev/via/viafbdev.c:via_fb_pci_probe() {
...
viaparinfo->iga_path = IGA1;
viaparinfo1->iga_path = IGA2;
memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
viafbinfo1->par = viaparinfo1;
...
}During dual framebuffer initialization, viafbinfo1 is allocated using framebuffer_alloc(), which properly initializes bl_curve_mutex.
This memcpy() performs a bitwise copy of a struct fb_info over another, which blindly overwrites the initialized mutex with the bitwise state of viafbinfo's mutex.
Because a mutex contains a self-referencing list head for its wait list, would viafbinfo1's wait list pointers now incorrectly point to viafbinfo's wait list?
When backlight support is enabled, an unprivileged user space program can trigger concurrent reads or writes to /sys/class/graphics/fb1/bl_curve, which attempts to take viafbinfo1->bl_curve_mutex.
Could modifying this corrupted wait list cause severe list corruption across both framebuffers or a kernel panic?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 11 lines · Ajith P V
Eliminate the single-use file-scope variable
viafb_nameand pass the "Via" string literal directly tostrcpy().Since "Via" is a literal constant, the compiler safely executes compile-time bounds checking during fortify verification. This satisfies the security initiative requirements while minimizing code complexity.
Signed-off-by Ajith P V <[email protected]>...
drivers/video/fbdev/via/viafbdev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
applied.
Thanks!
Helge