Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block, bfq: fix uaf for bfqq in bfq_exit_icq_bfqq

Commit 64dc8c732f5c ("block, bfq: fix possible uaf for 'bfqq->bic'")
will access 'bic->bfqq' in bic_set_bfqq(), however, bfq_exit_icq_bfqq()
can free bfqq first, and then call bic_set_bfqq(), which will cause uaf.

Fix the problem by moving bfq_exit_bfqq() behind bic_set_bfqq().

Fixes: 64dc8c732f5c ("block, bfq: fix possible uaf for 'bfqq->bic'")
Reported-by: Yi Zhang <yi.zhang@redhat.com>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20221226030605.1437081-1-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Yu Kuai and committed by
Jens Axboe
246cf66e fb857b0b

+1 -1
+1 -1
block/bfq-iosched.c
··· 5317 5317 unsigned long flags; 5318 5318 5319 5319 spin_lock_irqsave(&bfqd->lock, flags); 5320 - bfq_exit_bfqq(bfqd, bfqq); 5321 5320 bic_set_bfqq(bic, NULL, is_sync); 5321 + bfq_exit_bfqq(bfqd, bfqq); 5322 5322 spin_unlock_irqrestore(&bfqd->lock, flags); 5323 5323 } 5324 5324 }