Skip to contentSkip to conversation

drm/fb: replace strcpy() with strscpy() for fb->comm

PATCH In review Madhur Kumar 2 participants 2 messages Sep 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/fb: replace strcpy() with strscpy() for fb->comm

Use strscpy() instead of strcpy() to copy "[fbcon]" into fb->comm. This prevents possible buffer overflows and ensures proper NUL termination.

v2: Fixed typo in commit message

---
 drivers/gpu/drm/drm_fb_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +1 -1
index 11a5b60cb9ce..0cd7c3280243 100644
@@ -1651,7 +1651,7 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper)
 	if (ret < 0)
 		return ret;
 
-	strcpy(fb_helper->fb->comm, "[fbcon]");
+	strscpy(fb_helper->fb->comm, "[fbcon]", sizeof(fb_helper->fb->comm));
 
 	info = fb_helper->info;
 
Signature · 1 line
2.51.0
#1 lore raw

Hi

Am 23.09.25 um 10:27 schrieb Madhur Kumar:

Quoted 15 lines

Use strscpy() instead of strcpy() to copy "[fbcon]" into fb->comm. This prevents possible buffer overflows and ensures proper NUL termination.

v2: Fixed typo in commit message

---
  drivers/gpu/drm/drm_fb_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_fb_helper.c +0 -0
index 11a5b60cb9ce..0cd7c3280243 100644

drivers/gpu/drm/drm_fb_helper.c static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper) · line 1654

Quoted 5 lines
drivers/gpu/drm/drm_fb_helper.c +1 -1
@@ -1651,7 +1651,7 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper)
  	if (ret < 0)
  		return ret;
 
-	strcpy(fb_helper->fb->comm, "[fbcon]");
+	strscpy(fb_helper->fb->comm, "[fbcon]", sizeof(fb_helper->fb->comm));

If anyone ever makes comm a pointer, this code will fail.

It's therefore better to leave out the size argument. strscpy() will then detect the size and verify that dst is an array. See the docs and define of strscpy() [1] for details.

Best regards
Thomas

Quoted 3 lines
drivers/gpu/drm/drm_fb_helper.c +0 -0
  	info = fb_helper->info;
 
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)