Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: yaolu@kylinos.cn
Cc: dri-devel@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH] drm/xe/oa: Remove sysfs entry on idr_alloc failure in xe_oa_add_config_ioctl()
Date: Fri, 28 Aug 2026 06:18:17 +0000	[thread overview]
Message-ID: <20260828061817.7E23D1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828060812.163548-1-yaolu@kylinos.cn>

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

Pre-existing issues:
- [High] The resource leak and use-after-free vulnerability fixed by this patch in `xe_oa.c` also exists in the closely related `i915_perf.c` code, but the patch does not fix it there.
--

commit d832610ac618deeb81c1662fcf62f5c12fbe835e
Author: Lu Yao <yaolu@kylinos.cn>
drm/xe/oa: Remove sysfs entry on idr_alloc failure in xe_oa_add_config_ioctl()

If idr_alloc() fails after create_dynamic_oa_sysfs_entry() has succeeded,
the error path frees the OA config without removing the metrics sysfs
group. This commit fixes the bug in xe_oa.c by removing the sysfs group
before releasing the config.

> diff --git a/drivers/gpu/drm/xe/xe_oa.c b/drivers/gpu/drm/xe/xe_oa.c
> index b460fcdfca15c..d0625fb7111d9 100644
> --- a/drivers/gpu/drm/xe/xe_oa.c
> +++ b/drivers/gpu/drm/xe/xe_oa.c
> @@ -2435,8 +2435,9 @@ int xe_oa_add_config_ioctl(struct drm_device *dev, u64 data, struct drm_file *fi
>  
>  	oa_config->id = idr_alloc(&oa->metrics_idr, oa_config, 1, 0, GFP_KERNEL);
>  	if (oa_config->id < 0) {
> -		drm_dbg(&oa->xe->drm, "Failed to create sysfs entry for OA config\n");
> +		drm_dbg(&oa->xe->drm, "Failed to allocate id for OA config\n");
>  		err = oa_config->id;
> +		sysfs_remove_group(oa->metrics_kobj, &oa_config->sysfs_metric);

[Severity: High]
This is a pre-existing issue, but does this same resource leak and 
use-after-free vulnerability exist in the closely related i915 driver code?

It looks like the bug fixed by this patch in xe_oa.c might also be present
in drivers/gpu/drm/i915/i915_perf.c:i915_perf_add_config_ioctl():

	oa_config->id = idr_alloc(&perf->metrics_idr,
				  oa_config, 2,
				  0, GFP_KERNEL);
	if (oa_config->id < 0) {
		drm_dbg(&perf->i915->drm,
			"Failed to create sysfs entry for OA config\n");
		err = oa_config->id;
		goto sysfs_err;
	}

If idr_alloc() fails in i915_perf_add_config_ioctl() (for example, due to
IDR exhaustion or out of memory), the error path jumps to sysfs_err and
calls i915_oa_config_put(). This frees the oa_config structure without first
removing the sysfs group created by create_dynamic_oa_sysfs_entry().

A local user with sufficient privileges could trigger this by adding configs
until the IDR is exhausted, then read the dangling sysfs id attribute. This
would trigger a UAF when show_dynamic_id() accesses the freed oa_config
memory.

Should a similar fix be applied to i915_perf.c?

>  		goto sysfs_err;
>  	}
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260828060812.163548-1-yaolu@kylinos.cn?part=1

  reply	other threads:[~2026-08-28  6:18 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28  6:08 [PATCH] drm/xe/oa: Remove sysfs entry on idr_alloc failure in xe_oa_add_config_ioctl() yaolu
2026-08-28  6:18 ` sashiko-bot [this message]
2026-08-28 12:55 ` ✓ CI.KUnit: success for " Patchwork
2026-08-28 13:35 ` ✓ Xe.CI.BAT: " Patchwork
2026-08-28 14:42 ` ✓ Xe.CI.FULL: " Patchwork
2026-08-28 15:50 ` [PATCH] " Rodrigo Vivi

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=20260828061817.7E23D1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=yaolu@kylinos.cn \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox