Skip to content

Commit 478de33

Browse files
Algodev-githubaxboe
authored andcommitted
block, bfq: deschedule empty bfq_queues not referred by any process
Since commit 3726112 ("block, bfq: re-schedule empty queues if they deserve I/O plugging"), to prevent the service guarantees of a bfq_queue from being violated, the bfq_queue may be left busy, i.e., scheduled for service, even if empty (see comments in __bfq_bfqq_expire() for details). But, if no process will send requests to the bfq_queue any longer, then there is no point in keeping the bfq_queue scheduled for service. In addition, keeping the bfq_queue scheduled for service, but with no process reference any longer, may cause the bfq_queue to be freed when descheduled from service. But this is assumed to never happen, and causes a UAF if it happens. This, in turn, caused crashes [1, 2]. This commit fixes this issue by descheduling an empty bfq_queue when it remains with not process reference. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1767539 [2] https://bugzilla.kernel.org/show_bug.cgi?id=205447 Fixes: 3726112 ("block, bfq: re-schedule empty queues if they deserve I/O plugging") Reported-by: Chris Evich <[email protected]> Reported-by: Patrick Dung <[email protected]> Reported-by: Thorsten Schubert <[email protected]> Tested-by: Thorsten Schubert <[email protected]> Tested-by: Oleksandr Natalenko <[email protected]> Signed-off-by: Paolo Valente <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5e55956 commit 478de33

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

block/bfq-iosched.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,6 +2713,28 @@ static void bfq_bfqq_save_state(struct bfq_queue *bfqq)
27132713
}
27142714
}
27152715

2716+
2717+
static
2718+
void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq)
2719+
{
2720+
/*
2721+
* To prevent bfqq's service guarantees from being violated,
2722+
* bfqq may be left busy, i.e., queued for service, even if
2723+
* empty (see comments in __bfq_bfqq_expire() for
2724+
* details). But, if no process will send requests to bfqq any
2725+
* longer, then there is no point in keeping bfqq queued for
2726+
* service. In addition, keeping bfqq queued for service, but
2727+
* with no process ref any longer, may have caused bfqq to be
2728+
* freed when dequeued from service. But this is assumed to
2729+
* never happen.
2730+
*/
2731+
if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list) &&
2732+
bfqq != bfqd->in_service_queue)
2733+
bfq_del_bfqq_busy(bfqd, bfqq, false);
2734+
2735+
bfq_put_queue(bfqq);
2736+
}
2737+
27162738
static void
27172739
bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic,
27182740
struct bfq_queue *bfqq, struct bfq_queue *new_bfqq)
@@ -2783,8 +2805,7 @@ bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic,
27832805
*/
27842806
new_bfqq->pid = -1;
27852807
bfqq->bic = NULL;
2786-
/* release process reference to bfqq */
2787-
bfq_put_queue(bfqq);
2808+
bfq_release_process_ref(bfqd, bfqq);
27882809
}
27892810

27902811
static bool bfq_allow_bio_merge(struct request_queue *q, struct request *rq,
@@ -4899,7 +4920,7 @@ static void bfq_exit_bfqq(struct bfq_data *bfqd, struct bfq_queue *bfqq)
48994920

49004921
bfq_put_cooperator(bfqq);
49014922

4902-
bfq_put_queue(bfqq); /* release process reference */
4923+
bfq_release_process_ref(bfqd, bfqq);
49034924
}
49044925

49054926
static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, bool is_sync)
@@ -5001,8 +5022,7 @@ static void bfq_check_ioprio_change(struct bfq_io_cq *bic, struct bio *bio)
50015022

50025023
bfqq = bic_to_bfqq(bic, false);
50035024
if (bfqq) {
5004-
/* release process reference on this queue */
5005-
bfq_put_queue(bfqq);
5025+
bfq_release_process_ref(bfqd, bfqq);
50065026
bfqq = bfq_get_queue(bfqd, bio, BLK_RW_ASYNC, bic);
50075027
bic_set_bfqq(bic, bfqq, false);
50085028
}
@@ -5963,7 +5983,7 @@ bfq_split_bfqq(struct bfq_io_cq *bic, struct bfq_queue *bfqq)
59635983

59645984
bfq_put_cooperator(bfqq);
59655985

5966-
bfq_put_queue(bfqq);
5986+
bfq_release_process_ref(bfqq->bfqd, bfqq);
59675987
return NULL;
59685988
}
59695989

0 commit comments

Comments
 (0)