Skip to contentSkip to conversation

drm: Fix potential overflow issue in event_string array

PATCH Applied [email protected] 4 participants 5 messages Apr 9, 2025 – May 2, 2025

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

PATCH v3 1/1 drm: Fix potential overflow issue in event_string array

From: Feng Jiang <[email protected]>

When calling scnprintf() to append recovery method to event_string, the second argument should be sizeof(event_string) - len, otherwise there is a potential overflow problem.

Fixes b7cf9f4ac1b8 ("drm: Introduce device wedged event")

---
v3:
- update the subject

v2:
- update commit message
- keep scnprintf() as a single line

---
 drivers/gpu/drm/drm_drv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_drv.c +1 -1
index 17fc5dc708f4..60e5ac179c15 100644
@@ -549,7 +549,7 @@ int drm_dev_wedged_event(struct drm_device *dev, unsigned long method)
 		if (drm_WARN_ONCE(dev, !recovery, "invalid recovery method %u\n", opt))
 			break;
 
-		len += scnprintf(event_string + len, sizeof(event_string), "%s,", recovery);
+		len += scnprintf(event_string + len, sizeof(event_string) - len, "%s,", recovery);
 	}
 
 	if (recovery)
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#2 lore raw
In reply to [email protected]
Quoted 8 lines · On Wed, Apr 09, 2025 at 09:46:33AM +0800, [email protected] wrote:

From: Feng Jiang <[email protected]>

When calling scnprintf() to append recovery method to event_string, the second argument should be sizeof(event_string) - len, otherwise there is a potential overflow problem.

Fixes b7cf9f4ac1b8 ("drm: Introduce device wedged event")

Thanks for the fix.

#3 lore raw
Quoted 7 lines · Raag Jadav
Quoted 6 lines · On Wed, Apr 09, 2025 at 09:46:33AM +0800, [email protected] wrote:

From: Feng Jiang <[email protected]>

When calling scnprintf() to append recovery method to event_string, the second argument should be sizeof(event_string) - len, otherwise there is a potential overflow problem.

Quoted 6 lines
Quoted 2 lines
Fixes b7cf9f4ac1b8 ("drm: Introduce device wedged event")

Thanks for the fix.

This one seems got lost in the noise but important for 6.15. Any takers?

Raag

Applied
#4 lore raw
Quoted 11 lines · Raag Jadav
Quoted 10 lines · Raag Jadav
Quoted 8 lines · On Wed, Apr 09, 2025 at 09:46:33AM +0800, [email protected] wrote:

From: Feng Jiang <[email protected]>

When calling scnprintf() to append recovery method to event_string, the second argument should be sizeof(event_string) - len, otherwise there is a potential overflow problem.

Fixes b7cf9f4ac1b8 ("drm: Introduce device wedged event")
Quoted 6 lines
Quoted 3 lines

Thanks for the fix.

This one seems got lost in the noise but important for 6.15. Any takers?

pushed to drm-misc-fixes

Quoted 2 lines

Raag