Skip to contentSkip to conversation

drm/i915: Fix a VMA UAF for multi-gt platform

PATCH In review Nirmoy Das 3 participants 4 messages Jun 7, 2023 – Jun 8, 2023

Subsystems (2)
lore
Share & tools
lore

Nirmoy Das

author
#0 lore raw

PATCH v3 1/1 drm/i915: Fix a VMA UAF for multi-gt platform

Ensure correct handling of closed VMAs on multi-gt platforms to prevent Use-After-Free. Currently, when GT0 goes idle, closed VMAs that are exclusively added to GT0's closed_vma link (gt->closed_vma) and subsequently freed by i915_vma_parked(), which assumes the entire GPU is idle. However, on platforms with multiple GTs, such as MTL, GT1 may remain active while GT0 is idle. This causes GT0 to mistakenly consider the closed VMAs in its closed_vma list as unnecessary, potentially leading to Use-After-Free issues if a job for GT1 attempts to access a freed VMA.

Although we do take a wakeref for GT0 but it happens later, after evaluating VMAs. To mitigate this, it is necessary to hold a GT0 wakeref early.

v2: Use gt id to detect multi-tile(Andi)
Fix the incorrect error path.
v3: Add more comment(Andi)
Use the new gt var when possible(Andrzej)

Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Andi Shyti <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Sushma Venkatesh Reddy <[email protected]>
---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 21 +++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +19 -2
index 5fb459ea4294..1de9de1e4782 100644
@@ -2692,6 +2692,7 @@ static int
 eb_select_engine(struct i915_execbuffer *eb)
 {
 	struct intel_context *ce, *child;
+	struct intel_gt *gt;
 	unsigned int idx;
 	int err;
 
@@ -2715,10 +2716,17 @@ eb_select_engine(struct i915_execbuffer *eb)
 		}
 	}
 	eb->num_batches = ce->parallel.number_children + 1;
+	gt = ce->engine->gt;
 
 	for_each_child(ce, child)
 		intel_context_get(child);
-	intel_gt_pm_get(ce->engine->gt);
+	intel_gt_pm_get(gt);
+	/*
+	 * Keep GT0 active on MTL so that i915_vma_parked() doesn't
+	 * free VMAs while execbuf ioctl is validating VMAs.
+	 */
+	if (gt->info.id)
+		intel_gt_pm_get(to_gt(gt->i915));
 
 	if (!test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) {
 		err = intel_context_alloc_state(ce);
@@ -2757,7 +2765,10 @@ eb_select_engine(struct i915_execbuffer *eb)
 	return err;
 
 err:
-	intel_gt_pm_put(ce->engine->gt);
+	if (gt->info.id)
+		intel_gt_pm_put(to_gt(gt->i915));
+
+	intel_gt_pm_put(gt);
 	for_each_child(ce, child)
 		intel_context_put(child);
 	intel_context_put(ce);
@@ -2770,6 +2781,12 @@ eb_put_engine(struct i915_execbuffer *eb)
 	struct intel_context *child;
 
 	i915_vm_put(eb->context->vm);
+	/*
+	 * This works in conjunction with eb_select_engine() to prevent
+	 * i915_vma_parked() from interfering while execbuf validates vmas.
+	 */
+	if (eb->gt->info.id)
+		intel_gt_pm_put(to_gt(eb->gt->i915));
 	intel_gt_pm_put(eb->gt);
 	for_each_child(eb->context, child)
 		intel_context_put(child);
Signature · 1 line
2.39.0
#1 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for drm/i915: Fix a VMA UAF for multi-gt platform (rev3)

== Series Details ==

== Series Details ==

Series: drm/i915: Fix a VMA UAF for multi-gt platform (rev3)
URL : https://patchwork.freedesktop.org/series/118887/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_13240 -> Patchwork_118887v3
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/index.html

Participating hosts (40 -> 39)
------------------------------

Missing (1): fi-snb-2520m

Known issues
------------

Here are the changes found in Patchwork_118887v3 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@i915_selftest@live@migrate:
- bat-dg2-11: [PASS][1] -> [DMESG-WARN][2] ([i915#7699])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-dg2-11/igt@i915_selftest@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-dg2-11/igt@i915_selftest@[email protected]

* igt@kms_psr@primary_mmap_gtt:
- bat-rplp-1: NOTRUN -> [SKIP][3] ([i915#1072])
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-rplp-1/igt@kms_psr@primary_mmap_gtt.html

* igt@kms_setmode@basic-clone-single-crtc:
- bat-rplp-1: NOTRUN -> [ABORT][4] ([i915#4579] / [i915#8260])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-rplp-1/igt@[email protected]

#### Possible fixes ####

* igt@kms_cursor_legacy@basic-flip-before-cursor-legacy:
- {bat-adlp-11}: [DMESG-WARN][5] ([i915#6868]) -> [PASS][6] +2 similar issues
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-adlp-11/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-adlp-11/igt@[email protected]

* igt@kms_cursor_legacy@basic-flip-before-cursor-varying-size:
- {bat-adlp-11}: [SKIP][7] ([i915#3546]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-adlp-11/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-adlp-11/igt@[email protected]

* igt@kms_flip@basic-flip-vs-wf_vblank@a-dp6:
- {bat-adlp-11}: [FAIL][9] ([i915#6121]) -> [PASS][10] +3 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-adlp-11/igt@kms_flip@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-adlp-11/igt@kms_flip@[email protected]

* igt@kms_frontbuffer_tracking@basic:
- {bat-adlp-11}: [SKIP][11] ([i915#4342]) -> [PASS][12]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-adlp-11/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-adlp-11/igt@[email protected]

* igt@kms_pipe_crc_basic@nonblocking-crc@pipe-d-dp-1:
- bat-dg2-8: [FAIL][13] ([i915#7932]) -> [PASS][14]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-dg2-8/igt@kms_pipe_crc_basic@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-dg2-8/igt@kms_pipe_crc_basic@[email protected]

#### Warnings ####

* igt@kms_psr@sprite_plane_onoff:
- bat-rplp-1: [ABORT][15] -> [SKIP][16] ([i915#1072])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_13240/bat-rplp-1/igt@kms_psr@sprite_plane_onoff.html
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/bat-rplp-1/igt@kms_psr@sprite_plane_onoff.html

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#3546]: https://gitlab.freedesktop.org/drm/intel/issues/3546
[i915#4342]: https://gitlab.freedesktop.org/drm/intel/issues/4342
[i915#4423]: https://gitlab.freedesktop.org/drm/intel/issues/4423
[i915#4579]: https://gitlab.freedesktop.org/drm/intel/issues/4579
[i915#6121]: https://gitlab.freedesktop.org/drm/intel/issues/6121
[i915#6367]: https://gitlab.freedesktop.org/drm/intel/issues/6367
[i915#6868]: https://gitlab.freedesktop.org/drm/intel/issues/6868
[i915#7699]: https://gitlab.freedesktop.org/drm/intel/issues/7699
[i915#7932]: https://gitlab.freedesktop.org/drm/intel/issues/7932
[i915#8260]: https://gitlab.freedesktop.org/drm/intel/issues/8260

Build changes
-------------

* Linux: CI_DRM_13240 -> Patchwork_118887v3

CI-20190529: 20190529
CI_DRM_13240: 8dd18bdcb174684283eab5362117acc6628d6259 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7320: 1c96b08a4cde6f2d49824a8cc3303bd860617b52 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_118887v3: 8dd18bdcb174684283eab5362117acc6628d6259 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

d2b6ad154f9f drm/i915: Fix a VMA UAF for multi-gt platform

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_118887v3/index.html

Tested-by Tested-by Andi Shyti Reviewed-by Andi Shyti Reviewed-by Andrzej Hajda on v3 1/1
#2 lore raw
In reply to Nirmoy Das

Thank you, Nirmoy. We have verified it on Chrome.

-----Original Message-----
From: Das, Nirmoy <[email protected]>
Sent: Wednesday, June 7, 2023 1:11 AM
To: [email protected]
Cc: [email protected]; Das, Nirmoy <[email protected]>; Joonas Lahtinen <[email protected]>; Vivi, Rodrigo <[email protected]>; Tvrtko Ursulin <[email protected]>; Thomas Hellström <[email protected]>; Wilson, Chris P <[email protected]>; Andi Shyti <[email protected]>; Hajda, Andrzej <[email protected]>; Venkatesh Reddy, Sushma <[email protected]>
Subject: [PATCH v3] drm/i915: Fix a VMA UAF for multi-gt platform

Ensure correct handling of closed VMAs on multi-gt platforms to prevent Use-After-Free. Currently, when GT0 goes idle, closed VMAs that are exclusively added to GT0's closed_vma link (gt->closed_vma) and subsequently freed by i915_vma_parked(), which assumes the entire GPU is idle. However, on platforms with multiple GTs, such as MTL, GT1 may remain active while GT0 is idle. This causes GT0 to mistakenly consider the closed VMAs in its closed_vma list as unnecessary, potentially leading to Use-After-Free issues if a job for GT1 attempts to access a freed VMA.

Although we do take a wakeref for GT0 but it happens later, after evaluating VMAs. To mitigate this, it is necessary to hold a GT0 wakeref early.

v2: Use gt id to detect multi-tile(Andi)
Fix the incorrect error path.
v3: Add more comment(Andi)
Use the new gt var when possible(Andrzej)

Cc Joonas Lahtinen <[email protected]>
Cc Rodrigo Vivi <[email protected]>
Cc Tvrtko Ursulin <[email protected]>
Cc Thomas Hellström <[email protected]>
Cc Chris Wilson <[email protected]>
Cc Andi Shyti <[email protected]>
Cc Andrzej Hajda <[email protected]>
Cc Sushma Venkatesh Reddy <[email protected]>
---
 .../gpu/drm/i915/gem/i915_gem_execbuffer.c    | 21 +++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_execbuffer.c +19 -2
index 5fb459ea4294..1de9de1e4782 100644
@@ -2692,6 +2692,7 @@ static int
 eb_select_engine(struct i915_execbuffer *eb)  {
 	struct intel_context *ce, *child;
+	struct intel_gt *gt;
 	unsigned int idx;
 	int err;
 
@@ -2715,10 +2716,17 @@ eb_select_engine(struct i915_execbuffer *eb)
 		}
 	}
 	eb->num_batches = ce->parallel.number_children + 1;
+	gt = ce->engine->gt;
 
 	for_each_child(ce, child)
 		intel_context_get(child);
-	intel_gt_pm_get(ce->engine->gt);
+	intel_gt_pm_get(gt);
+	/*
+	 * Keep GT0 active on MTL so that i915_vma_parked() doesn't
+	 * free VMAs while execbuf ioctl is validating VMAs.
+	 */
+	if (gt->info.id)
+		intel_gt_pm_get(to_gt(gt->i915));
 
 	if (!test_bit(CONTEXT_ALLOC_BIT, &ce->flags)) {
 		err = intel_context_alloc_state(ce);
@@ -2757,7 +2765,10 @@ eb_select_engine(struct i915_execbuffer *eb)
 	return err;
 
 err:
-	intel_gt_pm_put(ce->engine->gt);
+	if (gt->info.id)
+		intel_gt_pm_put(to_gt(gt->i915));
+
+	intel_gt_pm_put(gt);
 	for_each_child(ce, child)
 		intel_context_put(child);
 	intel_context_put(ce);
@@ -2770,6 +2781,12 @@ eb_put_engine(struct i915_execbuffer *eb)
 	struct intel_context *child;
 
 	i915_vm_put(eb->context->vm);
+	/*
+	 * This works in conjunction with eb_select_engine() to prevent
+	 * i915_vma_parked() from interfering while execbuf validates vmas.
+	 */
+	if (eb->gt->info.id)
+		intel_gt_pm_put(to_gt(eb->gt->i915));
 	intel_gt_pm_put(eb->gt);
 	for_each_child(eb->context, child)
 		intel_context_put(child);

--
2.39.0

#3 lore raw

[Intel-gfx] ✗ Fi.CI.BUILD: failure for drm/i915: Fix a VMA UAF for multi-gt platform (rev5)

In reply to Nirmoy Das
== Series Details ==

== Series Details ==

Series: drm/i915: Fix a VMA UAF for multi-gt platform (rev5)
URL : https://patchwork.freedesktop.org/series/118887/
State : failure

== Summary ==

Error: patch https://patchwork.freedesktop.org/api/1.0/series/118887/revisions/5/mbox/ not applied
warning: quoted CRLF detected
Applying: drm/i915: Fix a VMA UAF for multi-gt platform
error: patch fragment without header at line 23: @@ -2757,7 +2765,10 @@ eb_select_engine(struct i915_execbuffer *eb)?
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 drm/i915: Fix a VMA UAF for multi-gt platform
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Build failed, no error log produced