[PATCH] drm/i915/gt: Fix rq use-after-free in perf_mi_noop()

Wentao Liang posted 1 patch 1 week, 1 day ago
drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
[PATCH] drm/i915/gt: Fix rq use-after-free in perf_mi_noop()
Posted by Wentao Liang 1 week, 1 day ago
The i915_request_put() after the wait may drop the final reference and
free the request, yet the following cycle counting still reads
rq->hwsp_seqno. Compute the cycles[] entry while the reference taken
before i915_request_add() is still held.

Fixes: 3c7a44bbbfa7 ("drm/i915/selftests: Perform some basic cycle counting of MI ops")
Cc: stable@vger.kernel.org
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
 drivers/gpu/drm/i915/gt/selftest_engine_cs.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/i915/gt/selftest_engine_cs.c b/drivers/gpu/drm/i915/gt/selftest_engine_cs.c
index 5ffa5e30f419..7503763136b2 100644
--- a/drivers/gpu/drm/i915/gt/selftest_engine_cs.c
+++ b/drivers/gpu/drm/i915/gt/selftest_engine_cs.c
@@ -351,13 +351,14 @@ static int perf_mi_noop(void *arg)
 
 			if (i915_request_wait(rq, 0, HZ / 5) < 0)
 				err = -EIO;
+			if (err == 0)
+				cycles[i] =
+					(rq->hwsp_seqno[4] - rq->hwsp_seqno[3]) -
+					(rq->hwsp_seqno[3] - rq->hwsp_seqno[2]);
+
 			i915_request_put(rq);
 			if (err)
 				break;
-
-			cycles[i] =
-				(rq->hwsp_seqno[4] - rq->hwsp_seqno[3]) -
-				(rq->hwsp_seqno[3] - rq->hwsp_seqno[2]);
 		}
 		i915_vma_put(nop);
 		i915_vma_put(base);
-- 
2.34.1