--- /dev/null
+From 478de3380c1c7dbb0f65f545ee0185848413f3fe Mon Sep 17 00:00:00 2001
+From: Paolo Valente <paolo.valente@linaro.org>
+Date: Thu, 14 Nov 2019 10:33:11 +0100
+Subject: block, bfq: deschedule empty bfq_queues not referred by any process
+
+From: Paolo Valente <paolo.valente@linaro.org>
+
+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 <cevich@redhat.com>
+Reported-by: Patrick Dung <patdung100@gmail.com>
+Reported-by: Thorsten Schubert <tschubert@bafh.org>
+Tested-by: Thorsten Schubert <tschubert@bafh.org>
+Tested-by: Oleksandr Natalenko <oleksandr@natalenko.name>
+Signed-off-by: Paolo Valente <paolo.valente@linaro.org>
+Signed-off-by: Jens Axboe <axboe@kernel.dk>
+Cc: Laura Abbott <labbott@redhat.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ 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;
+ }
+
--- /dev/null
+From a56dcc6b455830776899ce3686735f1172e12243 Mon Sep 17 00:00:00 2001
+From: Dan Carpenter <dan.carpenter@oracle.com>
+Date: Wed, 13 Nov 2019 21:28:31 +0300
+Subject: net: cdc_ncm: Signedness bug in cdc_ncm_set_dgram_size()
+
+From: Dan Carpenter <dan.carpenter@oracle.com>
+
+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 <dan.carpenter@oracle.com>
+Signed-off-by: David S. Miller <davem@davemloft.net>
+Signed-off-by: Nobuhiro Iwamatsu <nobuhiro1.iwamatsu@toshiba.co.jp>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+
+---
+ 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;
+ }