Skip to content

Commit 70a3015

Browse files
yunxialigregkh
authored andcommitted
drm/ttm: fix bulk_move corruption when adding a entry
commit 4481913 upstream. 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: fee2ede ("drm/ttm: rework bulk move handling v5") Signed-off-by: Yunxiang Li <[email protected]> Reviewed-by: Christian König <[email protected]> CC: [email protected] Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Christian König <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 61622fa commit 70a3015

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/gpu/drm/ttm/ttm_resource.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ static void ttm_lru_bulk_move_pos_tail(struct ttm_lru_bulk_move_pos *pos,
8585
struct ttm_resource *res)
8686
{
8787
if (pos->last != res) {
88+
if (pos->first == res)
89+
pos->first = list_next_entry(res, lru);
8890
list_move(&res->lru, &pos->last->lru);
8991
pos->last = res;
9092
}
@@ -110,7 +112,8 @@ static void ttm_lru_bulk_move_del(struct ttm_lru_bulk_move *bulk,
110112
{
111113
struct ttm_lru_bulk_move_pos *pos = ttm_lru_bulk_move_pos(bulk, res);
112114

113-
if (unlikely(pos->first == res && pos->last == res)) {
115+
if (unlikely(WARN_ON(!pos->first || !pos->last) ||
116+
(pos->first == res && pos->last == res))) {
114117
pos->first = NULL;
115118
pos->last = NULL;
116119
} else if (pos->first == res) {

0 commit comments

Comments
 (0)