All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Raag Jadav" <raag.jadav@intel.com>
Cc: intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v6 1/5] drm/ras: Cancel and free message on get counter failure
Date: Wed, 19 Aug 2026 13:54:53 +0000	[thread overview]
Message-ID: <20260819135453.8EAAD1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260818135304.497098-2-raag.jadav@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [Critical] Concurrent device teardown causes Use-After-Free and potential Control-Flow Hijack due to unprotected `drm_ras_node` access via XArray.
- [High] Uninitialized variable `ret` is returned if the node iteration loops do not execute, corrupting netlink dump responses.
--

--- Patch [1]: [PATCH v6 1/5] drm/ras: Cancel and free message on get counter failure ---
commit 967dffc71497d8878a77ecf0c72775277b0ce183
Author: Raag Jadav <raag.jadav@intel.com>

drm/ras: Cancel and free message on get counter failure
    
doit_reply_value() directly returns on get counter failure, which results
in stale sk_buff and genetlink header that aren't cleaned up. Fix it and
while at it, consolidate error handling using goto.

> diff --git a/drivers/gpu/drm/drm_ras.c b/drivers/gpu/drm/drm_ras.c
> index 39155fb514de3..4fa1a257b0ed1 100644
> --- a/drivers/gpu/drm/drm_ras.c
> +++ b/drivers/gpu/drm/drm_ras.c
> @@ -234,25 +234,28 @@ static int doit_reply_value(struct genl_info *info, u32 node_id,
>  
>  	hdr = genlmsg_iput(msg, info);
>  	if (!hdr) {
> -		nlmsg_free(msg);
> -		return -EMSGSIZE;
> +		ret = -EMSGSIZE;
> +		goto free_msg;
>  	}
>  
>  	ret = get_node_error_counter(node_id, error_id,
>  				     &error_name, &value);
>  	if (ret)
> -		return ret;
> +		goto cancel_msg;
>  
>  	ret = msg_reply_value(msg, error_id, error_name, value);
> -	if (ret) {
> -		genlmsg_cancel(msg, hdr);
> -		nlmsg_free(msg);
> -		return ret;
> -	}
> +	if (ret)
> +		goto cancel_msg;
>  
>  	genlmsg_end(msg, hdr);
>  
>  	return genlmsg_reply(msg, info);
> +
> +cancel_msg:
> +	genlmsg_cancel(msg, hdr);
> +free_msg:
> +	nlmsg_free(msg);
> +	return ret;
>  }

[Severity: Critical]
This is a pre-existing issue, but does get_node_error_counter() have a
use-after-free risk during concurrent device teardown?

Since drm_ras_nl_family is configured with parallel_ops = true, these handlers
run concurrently without genl_mutex. If the device is concurrently unregistered
(e.g., driver unbind or hot-unplug), drm_ras_node_unregister() removes the node
from the xarray and the driver frees its memory while the netlink handler is
still executing.

This can happen in get_node_error_counter():

drivers/gpu/drm/drm_ras.c:get_node_error_counter() {
	...
	node = xa_load(&drm_ras_xa, node_id);
	if (!node || !node->query_error_counter)
		return -ENOENT;

	if (error_id < node->error_counter_range.first ||
	...
}

Here xa_load() retrieves the node pointer locklessly, but it is dereferenced
without holding an RCU read lock or taking a reference count. Could this result
in a use-after-free and potential control-flow hijack when executing
node->query_error_counter()?

This same pattern appears in drm_ras_nl_list_nodes_dumpit():

drivers/gpu/drm/drm_ras.c:drm_ras_nl_list_nodes_dumpit() {
	...
	xa_for_each_start(&drm_ras_xa, id, node, ctx->restart) {
		hdr = genlmsg_iput(skb, info);
	...
}

And in drm_ras_nl_clear_error_counter_doit():

drivers/gpu/drm/drm_ras.c:drm_ras_nl_clear_error_counter_doit() {
	...
	node = xa_load(&drm_ras_xa, node_id);
	if (!node || !node->clear_error_counter)
		return -ENOENT;
	...
}

[Severity: High]
This is also a pre-existing issue, but can drm_ras_nl_list_nodes_dumpit()
return an uninitialized value?

drivers/gpu/drm/drm_ras.c:drm_ras_nl_list_nodes_dumpit() {
	...
	int ret;

	xa_for_each_start(&drm_ras_xa, id, node, ctx->restart) {
		...
		ret = nla_put_u32(skb, DRM_RAS_A_NODE_ATTRS_NODE_ID, node->id);
		...
	}

	if (ret == -EMSGSIZE)
		ctx->restart = id;

	return ret;
}

If the xarray is empty, or on the final recvmsg() call where ctx->restart is
past the end of the items (signifying EOF), the iteration loop will not execute.
This leaves ret uninitialized. The function then checks if (ret == -EMSGSIZE),
which reads uninitialized stack memory, and then returns ret. This could cause
the dump to fail sporadically with arbitrary error codes.

A similar issue appears in drm_ras_nl_get_error_counter_dumpit():

drivers/gpu/drm/drm_ras.c:drm_ras_nl_get_error_counter_dumpit() {
	...
	int ret;

	if (!info->attrs || GENL_REQ_ATTR_CHECK(info, DRM_RAS_A_ERROR_COUNTER_ATTRS_NODE_ID))
		return -EINVAL;
	...
	for (error_id = max(node->error_counter_range.first, ctx->restart);
	     error_id <= node->error_counter_range.last;
	     error_id++) {
		ret = get_node_error_counter(...);
		...
	}

	if (ret == -EMSGSIZE)
		ctx->restart = error_id;

	return ret;
}

If the requested error range iteration does not execute, ret remains
uninitialized here as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260818135304.497098-1-raag.jadav@intel.com?part=1

  reply	other threads:[~2026-08-19 13:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18 13:52 [PATCH v6 0/5] Introduce error threshold to drm_ras Raag Jadav
2026-08-18 13:52 ` [PATCH v6 1/5] drm/ras: Cancel and free message on get counter failure Raag Jadav
2026-08-19 13:54   ` sashiko-bot [this message]
2026-08-18 13:52 ` [PATCH v6 2/5] drm/ras: Introduce error threshold Raag Jadav
2026-08-19 13:54   ` sashiko-bot
2026-08-18 13:52 ` [PATCH v6 3/5] drm/xe/ras: Add support for " Raag Jadav
2026-08-18 13:52 ` [PATCH v6 4/5] drm/xe/drm_ras: Wire up error threshold callbacks Raag Jadav
2026-08-19 13:54   ` sashiko-bot
2026-08-18 13:52 ` [PATCH v6 5/5] drm/xe/sysctrl: Reuse xe_sysctrl_create_command() Raag Jadav
2026-08-18 15:15 ` ✗ CI.checkpatch: warning for Introduce error threshold to drm_ras (rev6) Patchwork
2026-08-18 15:17 ` ✓ CI.KUnit: success " Patchwork
2026-08-18 16:04 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-18 19:27 ` ✗ Xe.CI.FULL: failure " Patchwork

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=20260819135453.8EAAD1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=raag.jadav@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.