All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/drv: Add buffer bounds check in drm_dev_wedged_event()
@ 2026-07-24  6:30 Mallesh Koujalagi
  2026-07-24  6:45 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Mallesh Koujalagi @ 2026-07-24  6:30 UTC (permalink / raw)
  To: dri-devel, rodrigo.vivi
  Cc: andrealmeid, christian.koenig, airlied, simona.vetter, mripard,
	maarten.lankhorst, tzimmermann, anshuman.gupta, badal.nilawar,
	riana.tauro, karthik.poosa, sk.anirban, raag.jadav,
	Mallesh Koujalagi

event_string[] has a fixed size of WEDGE_STR_LEN (32) bytes.
scnprintf(buf, size, "%s,", recovery) writes strlen(recovery)+1
content bytes (token + comma) and requires one additional byte
for the NUL terminator within 'size'.

Without a bounds check, if the remaining space is insufficient,
scnprintf() silently truncates the recovery token mid-name,
producing a malformed uevent payload (e.g. "WEDGED=bus-reset,vendor-spe").

Add a pre-flight drm_WARN_ON() guard:

  len + strlen(recovery) + 1 >= WEDGE_STR_LEN

Fixes: b7cf9f4ac1b8 ("drm: Introduce device wedged event")
Signed-off-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
---
v2:
- Add proper logic to handle recovery string. (Raag)
---
 drivers/gpu/drm/drm_drv.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
index e51ed959da89..e48b22ca38bd 100644
--- a/drivers/gpu/drm/drm_drv.c
+++ b/drivers/gpu/drm/drm_drv.c
@@ -586,6 +586,20 @@ 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;
 
+		/*
+		 * scnprintf(buf, size, "%s,", recovery) writes strlen(recovery)+1
+		 * content bytes (token + comma) and reserves 1 byte for NUL within
+		 * 'size'.  It fits without truncation when:
+		 *   len + strlen(recovery) + 1 <= WEDGE_STR_LEN - 1  (safe)
+		 * so warn and bail when:
+		 *   len + strlen(recovery) + 1 >= WEDGE_STR_LEN       (would truncate)
+		 * Note: ">= WEDGE_STR_LEN - 1" would be off-by-one — it would
+		 * incorrectly reject the exact-fit case where NUL lands on the last
+		 * valid byte (index WEDGE_STR_LEN - 1).
+		 */
+		if (drm_WARN_ON(dev, len + strlen(recovery) + 1 >= WEDGE_STR_LEN))
+			break;
+
 		len += scnprintf(event_string + len, sizeof(event_string) - len, "%s,", recovery);
 	}
 
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-07-28 11:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-24  6:30 [PATCH v2] drm/drv: Add buffer bounds check in drm_dev_wedged_event() Mallesh Koujalagi
2026-07-24  6:45 ` sashiko-bot
2026-07-28  6:14 ` Raag Jadav
2026-07-28 10:59 ` Jani Nikula
2026-07-28 11:22   ` Raag Jadav

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.