From: Chengyu Liu <lui2012qwq@gmail.com>
To: intel-gfx@lists.freedesktop.org
Cc: dri-devel@lists.freedesktop.org, jani.nikula@linux.intel.com,
joonas.lahtinen@linux.intel.com, rodrigo.vivi@intel.com,
tursulin@ursulin.net, Chengyu Liu <lui2012qwq@gmail.com>,
stable@vger.kernel.org
Subject: [PATCH 2/2] i915/perf: remove sysfs entry if idr_alloc() fails in add_config
Date: Wed, 4 Nov 2026 15:33:11 +0800 [thread overview]
Message-ID: <20261104073311.1617823-3-lui2012qwq@gmail.com> (raw)
In-Reply-To: <20261104073311.1617823-1-lui2012qwq@gmail.com>
i915_perf_add_config_ioctl() creates the dynamic sysfs entry for the OA
config before allocating its id. If idr_alloc() fails, the error path
drops the config reference via reg_err: without removing the sysfs
entry - unlike the normal remove path, which does sysfs_remove_group()
first. The leftover attributes point into the freed oa_config; kernfs
only stores the attribute pointer, and show_dynamic_id() reaches the
freed object via container_of (including the show() callback itself),
so reading /sys/class/drm/cardX/metrics/<uuid>/id afterwards is a
use-after-free.
Remove the sysfs group on the idr_alloc() failure path, mirroring the
remove ioctl's ordering (under metrics_lock).
Found by static analysis.
Cc: stable@vger.kernel.org
Signed-off-by: Chengyu Liu <lui2012qwq@gmail.com>
---
drivers/gpu/drm/i915/i915_perf.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 19b82427aa..40385f991a 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -4716,6 +4716,7 @@ int i915_perf_add_config_ioctl(struct drm_device *dev, void *data,
drm_dbg(&perf->i915->drm,
"Failed to create sysfs entry for OA config\n");
err = oa_config->id;
+ sysfs_remove_group(perf->metrics_kobj, &oa_config->sysfs_metric);
goto sysfs_err;
}
id = oa_config->id;
--
2.25.1
prev parent reply other threads:[~2026-11-04 7:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20261104073311.1617823-1-lui2012qwq@gmail.com>
2026-11-04 7:33 ` [PATCH 1/2] i915/gt: tolerate ERR_PTR pd in gen6_ppgtt teardown Chengyu Liu
2026-11-04 15:18 ` Ville Syrjälä
2026-11-05 6:04 ` Chengyu Liu
2026-11-04 7:33 ` Chengyu Liu [this message]
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=20261104073311.1617823-3-lui2012qwq@gmail.com \
--to=lui2012qwq@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=stable@vger.kernel.org \
--cc=tursulin@ursulin.net \
/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