i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak)
Subsystems (3)
v2 cover i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak)
Two independent small fixes found by static analysis:
1/2: gen6_ppgtt_create() stored the result of gen6_alloc_top_pd()
directly into ppgtt->base.pd; on failure the ERR_PTR stayed in the field and the async release worker crashed dereferencing it in gen6_ppgtt_free_pd(). v2 follows the local-variable pattern suggested by Ville: assign to the field only after validation, so it can only ever be NULL or a valid pointer, and gen6_ppgtt_free_pd() now bails out on a NULL pd.
2/2: i915_perf_add_config_ioctl() creates the dynamic sysfs entry
before idr_alloc(); if idr_alloc() fails the error path frees the config without removing the sysfs entry, leaving attributes that point into freed memory (UAF read via the embedded show() callback). Remove the group on that path, mirroring the remove ioctl's ordering. Unchanged since v1.
---
v2:
- 1/2: don't assign the error pointer into ppgtt->base.pd at all
- 2/2: unchanged
v1: https://lore.kernel.org/r/[email protected]
Chengyu Liu (2):
i915/gt: don't store ERR_PTR into ppgtt->base.pd on allocation failure i915/perf: remove sysfs entry if idr_alloc() fails in add_config
drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 11 ++++++++--- drivers/gpu/drm/i915/i915_perf.c | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 i915/gt: don't store ERR_PTR into ppgtt->base.pd on allocation failure
gen6_ppgtt_create() stores the result of gen6_alloc_top_pd() directly into ppgtt->base.pd, and on failure the ERR_PTR stays in the field. i915_vm_put() runs vm->cleanup = gen6_ppgtt_cleanup(), where gen6_ppgtt_free_pd() dereferences pd via gen6_for_all_pdes() - with an ERR_PTR that is an invalid dereference and a crash (in the async release worker).
Assign to a local first and store into the field only after it is validated, so the field never holds an error pointer; on the failure path it stays NULL, and gen6_ppgtt_free_pd() now bails out on a NULL pd.
Found by static analysis.
--- drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gt/gen6_ppgtt.c +8 -3
@@ -259,6 +259,9 @@ static void gen6_ppgtt_free_pd(struct gen6_ppgtt *ppgtt)struct i915_page_table *pt;u32 pde; +if (!pd) +return ; + gen6_for_all_pdes(pt, pd, pde)if (pt)free_pt (&ppgtt->base.vm, pt);
@@ -427,6 +430,7 @@ void gen6_ppgtt_unpin(struct i915_ppgtt *base)struct i915_ppgtt *gen6_ppgtt_create (struct intel_gt *gt) { +struct i915_page_directory *pd;struct i915_ggtt *const ggtt = gt->ggtt;struct gen6_ppgtt *ppgtt;int err;
@@ -455,11 +459,12 @@ struct i915_ppgtt *gen6_ppgtt_create(struct intel_gt *gt)if (err) goto err_put; - ppgtt->base.pd =gen6_alloc_top_pd (ppgtt); -if (IS_ERR (ppgtt->base.pd)) { - err =PTR_ERR (ppgtt->base.pd); + pd =gen6_alloc_top_pd (ppgtt); +if (IS_ERR (pd)) { + err =PTR_ERR (pd); goto err_put; } + ppgtt->base.pd = pd;return &ppgtt->base;
Signature · 1 line
2.25.1
PATCH v2 2/2 i915/perf: remove sysfs entry if idr_alloc() fails in add_config
In reply to Chengyu Liui915_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.
--- drivers/gpu/drm/i915/i915_perf.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/i915_perf.c +1 -0
@@ -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;
Signature · 1 line
2.25.1
Patchwork
CI✗ LGCI.VerificationFailed: failure for i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak) (rev3)
In reply to Chengyu Liu== Series Details ==
== Series Details ==
Series: i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak) (rev3)
URL : https://patchwork.freedesktop.org/series/177748/
State : failure
== Summary ==
Series author address '[email protected]' is not on the allowlist, which prevents CI from being automatically triggered. If you want CI to run for this series, ask Patchwork project owners to click 'retest' on the series in Patchwork. Exception occurred during validation, bailing out!
Build URL: http://gfx-ci.igk.intel.com:8080/job/CI_PW_kernel/192116/ (on built-in)