All of lore.kernel.org
 help / color / mirror / Atom feed
From: Raag Jadav <raag.jadav@intel.com>
To: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
Cc: dri-devel@lists.freedesktop.org, rodrigo.vivi@intel.com,
	andrealmeid@igalia.com, christian.koenig@amd.com,
	airlied@gmail.com, simona.vetter@ffwll.ch, mripard@kernel.org,
	maarten.lankhorst@linux.intel.com, tzimmermann@suse.de,
	anshuman.gupta@intel.com, badal.nilawar@intel.com,
	riana.tauro@intel.com, karthik.poosa@intel.com,
	sk.anirban@intel.com
Subject: Re: [PATCH v2] drm/drv: Add buffer bounds check in drm_dev_wedged_event()
Date: Tue, 28 Jul 2026 08:14:31 +0200	[thread overview]
Message-ID: <amhIx1KpRV1bn3Xd@black.igk.intel.com> (raw)
In-Reply-To: <20260724063005.703631-2-mallesh.koujalagi@intel.com>

On Fri, Jul 24, 2026 at 12:00:06PM +0530, Mallesh Koujalagi wrote:
> 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).

This looks a bit verbose, can we shorten it up a bit?

> +		 */
> +		if (drm_WARN_ON(dev, len + strlen(recovery) + 1 >= WEDGE_STR_LEN))

I'd use drm_WARN_ON_ONCE() and avoid spamming logs.

Raag

> +			break;
> +
>  		len += scnprintf(event_string + len, sizeof(event_string) - len, "%s,", recovery);
>  	}
>  
> -- 
> 2.48.1
> 

  parent reply	other threads:[~2026-07-28  6:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2026-07-28 10:59 ` Jani Nikula
2026-07-28 11:22   ` Raag Jadav

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=amhIx1KpRV1bn3Xd@black.igk.intel.com \
    --to=raag.jadav@intel.com \
    --cc=airlied@gmail.com \
    --cc=andrealmeid@igalia.com \
    --cc=anshuman.gupta@intel.com \
    --cc=badal.nilawar@intel.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karthik.poosa@intel.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mallesh.koujalagi@intel.com \
    --cc=mripard@kernel.org \
    --cc=riana.tauro@intel.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona.vetter@ffwll.ch \
    --cc=sk.anirban@intel.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.