From: Greg Kroah-Hartman Date: Thu, 21 Nov 2019 17:54:03 +0000 (+0100) Subject: 5.3-stable patches X-Git-Tag: v5.3.13~23 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d0bd4f93cd776aeb9f0dc81a87aae1e9cb972aa8;p=thirdparty%2Fkernel%2Fstable-queue.git 5.3-stable patches added patches: block-bfq-deschedule-empty-bfq_queues-not-referred-by-any-process.patch net-cdc_ncm-signedness-bug-in-cdc_ncm_set_dgram_size.patch --- diff --git a/queue-5.3/block-bfq-deschedule-empty-bfq_queues-not-referred-by-any-process.patch b/queue-5.3/block-bfq-deschedule-empty-bfq_queues-not-referred-by-any-process.patch new file mode 100644 index 00000000000..7bcd3eb4002 --- /dev/null +++ b/queue-5.3/block-bfq-deschedule-empty-bfq_queues-not-referred-by-any-process.patch @@ -0,0 +1,112 @@ +From 478de3380c1c7dbb0f65f545ee0185848413f3fe Mon Sep 17 00:00:00 2001 +From: Paolo Valente +Date: Thu, 14 Nov 2019 10:33:11 +0100 +Subject: block, bfq: deschedule empty bfq_queues not referred by any process + +From: Paolo Valente + +commit 478de3380c1c7dbb0f65f545ee0185848413f3fe upstream. + +Since commit 3726112ec731 ("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: 3726112ec731 ("block, bfq: re-schedule empty queues if they deserve I/O plugging") +Reported-by: Chris Evich +Reported-by: Patrick Dung +Reported-by: Thorsten Schubert +Tested-by: Thorsten Schubert +Tested-by: Oleksandr Natalenko +Signed-off-by: Paolo Valente +Signed-off-by: Jens Axboe +Cc: Laura Abbott +Signed-off-by: Greg Kroah-Hartman + +--- + block/bfq-iosched.c | 32 ++++++++++++++++++++++++++------ + 1 file changed, 26 insertions(+), 6 deletions(-) + +--- a/block/bfq-iosched.c ++++ b/block/bfq-iosched.c +@@ -2699,6 +2699,28 @@ static void bfq_bfqq_save_state(struct b + } + } + ++ ++static ++void bfq_release_process_ref(struct bfq_data *bfqd, struct bfq_queue *bfqq) ++{ ++ /* ++ * To prevent bfqq's service guarantees from being violated, ++ * bfqq may be left busy, i.e., queued for service, even if ++ * empty (see comments in __bfq_bfqq_expire() for ++ * details). But, if no process will send requests to bfqq any ++ * longer, then there is no point in keeping bfqq queued for ++ * service. In addition, keeping bfqq queued for service, but ++ * with no process ref any longer, may have caused bfqq to be ++ * freed when dequeued from service. But this is assumed to ++ * never happen. ++ */ ++ if (bfq_bfqq_busy(bfqq) && RB_EMPTY_ROOT(&bfqq->sort_list) && ++ bfqq != bfqd->in_service_queue) ++ bfq_del_bfqq_busy(bfqd, bfqq, false); ++ ++ bfq_put_queue(bfqq); ++} ++ + static void + bfq_merge_bfqqs(struct bfq_data *bfqd, struct bfq_io_cq *bic, + struct bfq_queue *bfqq, struct bfq_queue *new_bfqq) +@@ -2769,8 +2791,7 @@ bfq_merge_bfqqs(struct bfq_data *bfqd, s + */ + new_bfqq->pid = -1; + bfqq->bic = NULL; +- /* release process reference to bfqq */ +- bfq_put_queue(bfqq); ++ bfq_release_process_ref(bfqd, bfqq); + } + + static bool bfq_allow_bio_merge(struct request_queue *q, struct request *rq, +@@ -4885,7 +4906,7 @@ static void bfq_exit_bfqq(struct bfq_dat + + bfq_put_cooperator(bfqq); + +- bfq_put_queue(bfqq); /* release process reference */ ++ bfq_release_process_ref(bfqd, bfqq); + } + + static void bfq_exit_icq_bfqq(struct bfq_io_cq *bic, bool is_sync) +@@ -4987,8 +5008,7 @@ static void bfq_check_ioprio_change(stru + + bfqq = bic_to_bfqq(bic, false); + if (bfqq) { +- /* release process reference on this queue */ +- bfq_put_queue(bfqq); ++ bfq_release_process_ref(bfqd, bfqq); + bfqq = bfq_get_queue(bfqd, bio, BLK_RW_ASYNC, bic); + bic_set_bfqq(bic, bfqq, false); + } +@@ -5948,7 +5968,7 @@ bfq_split_bfqq(struct bfq_io_cq *bic, st + + bfq_put_cooperator(bfqq); + +- bfq_put_queue(bfqq); ++ bfq_release_process_ref(bfqq->bfqd, bfqq); + return NULL; + } + diff --git a/queue-5.3/net-cdc_ncm-signedness-bug-in-cdc_ncm_set_dgram_size.patch b/queue-5.3/net-cdc_ncm-signedness-bug-in-cdc_ncm_set_dgram_size.patch new file mode 100644 index 00000000000..1b776f53825 --- /dev/null +++ b/queue-5.3/net-cdc_ncm-signedness-bug-in-cdc_ncm_set_dgram_size.patch @@ -0,0 +1,35 @@ +From a56dcc6b455830776899ce3686735f1172e12243 Mon Sep 17 00:00:00 2001 +From: Dan Carpenter +Date: Wed, 13 Nov 2019 21:28:31 +0300 +Subject: net: cdc_ncm: Signedness bug in cdc_ncm_set_dgram_size() + +From: Dan Carpenter + +commit a56dcc6b455830776899ce3686735f1172e12243 upstream. + +This code is supposed to test for negative error codes and partial +reads, but because sizeof() is size_t (unsigned) type then negative +error codes are type promoted to high positive values and the condition +doesn't work as expected. + +Fixes: 332f989a3b00 ("CDC-NCM: handle incomplete transfer of MTU") +Signed-off-by: Dan Carpenter +Signed-off-by: David S. Miller +Signed-off-by: Nobuhiro Iwamatsu +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/net/usb/cdc_ncm.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/net/usb/cdc_ncm.c ++++ b/drivers/net/usb/cdc_ncm.c +@@ -579,7 +579,7 @@ static void cdc_ncm_set_dgram_size(struc + err = usbnet_read_cmd(dev, USB_CDC_GET_MAX_DATAGRAM_SIZE, + USB_TYPE_CLASS | USB_DIR_IN | USB_RECIP_INTERFACE, + 0, iface_no, &max_datagram_size, sizeof(max_datagram_size)); +- if (err < sizeof(max_datagram_size)) { ++ if (err != sizeof(max_datagram_size)) { + dev_dbg(&dev->intf->dev, "GET_MAX_DATAGRAM_SIZE failed\n"); + goto out; + } diff --git a/queue-5.3/series b/queue-5.3/series new file mode 100644 index 00000000000..5311cd390f8 --- /dev/null +++ b/queue-5.3/series @@ -0,0 +1,2 @@ +net-cdc_ncm-signedness-bug-in-cdc_ncm_set_dgram_size.patch +block-bfq-deschedule-empty-bfq_queues-not-referred-by-any-process.patch