public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
From: Yunxiang Li <Yunxiang.Li@amd.com>
To: <stable@vger.kernel.org>
Cc: "Yunxiang Li" <Yunxiang.Li@amd.com>,
	"Christian König" <christian.koenig@amd.com>
Subject: [PATCH 6.1.y] drm/ttm: fix bulk_move corruption when adding a entry
Date: Sun, 23 Jul 2023 20:44:57 -0400	[thread overview]
Message-ID: <20230724004508.1519-1-Yunxiang.Li@amd.com> (raw)
In-Reply-To: <2023072146-sports-deluge-22a1@gregkh>

When the resource is the first in the bulk_move range, adding it again
(thus moving it to the tail) will corrupt the list since the first
pointer is not moved. This eventually lead to null pointer deref in
ttm_lru_bulk_move_del()

Fixes: fee2ede15542 ("drm/ttm: rework bulk move handling v5")
Signed-off-by: Yunxiang Li <Yunxiang.Li@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
CC: stable@vger.kernel.org
Link: https://patchwork.freedesktop.org/patch/msgid/20230622141902.28718-3-Yunxiang.Li@amd.com
Signed-off-by: Christian König <christian.koenig@amd.com>
(cherry picked from commit 4481913607e58196c48a4fef5e6f45350684ec3c)
---
 drivers/gpu/drm/ttm/ttm_resource.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index a729c32a1e48..3287032a2f8e 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -85,6 +85,8 @@ static void ttm_lru_bulk_move_pos_tail(struct ttm_lru_bulk_move_pos *pos,
 				       struct ttm_resource *res)
 {
 	if (pos->last != res) {
+		if (pos->first == res)
+			pos->first = list_next_entry(res, lru);
 		list_move(&res->lru, &pos->last->lru);
 		pos->last = res;
 	}
@@ -110,7 +112,8 @@ static void ttm_lru_bulk_move_del(struct ttm_lru_bulk_move *bulk,
 {
 	struct ttm_lru_bulk_move_pos *pos = ttm_lru_bulk_move_pos(bulk, res);
 
-	if (unlikely(pos->first == res && pos->last == res)) {
+	if (unlikely(WARN_ON(!pos->first || !pos->last) ||
+		     (pos->first == res && pos->last == res))) {
 		pos->first = NULL;
 		pos->last = NULL;
 	} else if (pos->first == res) {
-- 
2.41.0


      parent reply	other threads:[~2023-07-24  0:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 12:20 FAILED: patch "[PATCH] drm/ttm: fix bulk_move corruption when adding a entry" failed to apply to 6.4-stable tree gregkh
2023-07-21 12:51 ` Li, Yunxiang (Teddy)
2023-07-21 13:27   ` gregkh
2023-07-21 20:01     ` Li, Yunxiang (Teddy)
2023-07-22 11:48       ` gregkh
2023-07-24  0:43 ` [PATCH 6.4.y] drm/ttm: fix bulk_move corruption when adding a entry Yunxiang Li
2023-07-24  6:29   ` Greg KH
2023-07-24  0:44 ` Yunxiang Li [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=20230724004508.1519-1-Yunxiang.Li@amd.com \
    --to=yunxiang.li@amd.com \
    --cc=christian.koenig@amd.com \
    --cc=stable@vger.kernel.org \
    /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