]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.19-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Aug 2022 15:21:09 +0000 (17:21 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 13 Aug 2022 15:21:09 +0000 (17:21 +0200)
added patches:
netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch
netfilter-nf_tables-fix-null-deref-due-to-zeroed-list-head.patch
usb-gadget-fix-use-after-free-read-in-usb_udc_uevent.patch
usb-hcd-fix-urb-giveback-issue-in-tasklet-function.patch

queue-4.19/netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch [new file with mode: 0644]
queue-4.19/netfilter-nf_tables-fix-null-deref-due-to-zeroed-list-head.patch [new file with mode: 0644]
queue-4.19/series
queue-4.19/usb-gadget-fix-use-after-free-read-in-usb_udc_uevent.patch [new file with mode: 0644]
queue-4.19/usb-hcd-fix-urb-giveback-issue-in-tasklet-function.patch [new file with mode: 0644]

diff --git a/queue-4.19/netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch b/queue-4.19/netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch
new file mode 100644 (file)
index 0000000..0d52cab
--- /dev/null
@@ -0,0 +1,57 @@
+From 470ee20e069a6d05ae549f7d0ef2bdbcee6a81b2 Mon Sep 17 00:00:00 2001
+From: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
+Date: Tue, 9 Aug 2022 14:01:46 -0300
+Subject: netfilter: nf_tables: do not allow SET_ID to refer to another table
+
+From: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
+
+commit 470ee20e069a6d05ae549f7d0ef2bdbcee6a81b2 upstream.
+
+When doing lookups for sets on the same batch by using its ID, a set from a
+different table can be used.
+
+Then, when the table is removed, a reference to the set may be kept after
+the set is freed, leading to a potential use-after-free.
+
+When looking for sets by ID, use the table that was used for the lookup by
+name, and only return sets belonging to that same table.
+
+This fixes CVE-2022-2586, also reported as ZDI-CAN-17470.
+
+Reported-by: Team Orca of Sea Security (@seasecresponse)
+Fixes: 958bee14d071 ("netfilter: nf_tables: use new transaction infrastructure to handle sets")
+Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
+Cc: <stable@vger.kernel.org>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ net/netfilter/nf_tables_api.c |    4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+--- a/net/netfilter/nf_tables_api.c
++++ b/net/netfilter/nf_tables_api.c
+@@ -3039,6 +3039,7 @@ static struct nft_set *nft_set_lookup_by
+ }
+ static struct nft_set *nft_set_lookup_byid(const struct net *net,
++                                         const struct nft_table *table,
+                                          const struct nlattr *nla, u8 genmask)
+ {
+       struct nft_trans *trans;
+@@ -3049,6 +3050,7 @@ static struct nft_set *nft_set_lookup_by
+                       struct nft_set *set = nft_trans_set(trans);
+                       if (id == nft_trans_set_id(trans) &&
++                          set->table == table &&
+                           nft_active_genmask(set, genmask))
+                               return set;
+               }
+@@ -3069,7 +3071,7 @@ struct nft_set *nft_set_lookup_global(co
+               if (!nla_set_id)
+                       return set;
+-              set = nft_set_lookup_byid(net, nla_set_id, genmask);
++              set = nft_set_lookup_byid(net, table, nla_set_id, genmask);
+       }
+       return set;
+ }
diff --git a/queue-4.19/netfilter-nf_tables-fix-null-deref-due-to-zeroed-list-head.patch b/queue-4.19/netfilter-nf_tables-fix-null-deref-due-to-zeroed-list-head.patch
new file mode 100644 (file)
index 0000000..259e91a
--- /dev/null
@@ -0,0 +1,45 @@
+From 580077855a40741cf511766129702d97ff02f4d9 Mon Sep 17 00:00:00 2001
+From: Florian Westphal <fw@strlen.de>
+Date: Tue, 9 Aug 2022 18:34:02 +0200
+Subject: netfilter: nf_tables: fix null deref due to zeroed list head
+
+From: Florian Westphal <fw@strlen.de>
+
+commit 580077855a40741cf511766129702d97ff02f4d9 upstream.
+
+In nf_tables_updtable, if nf_tables_table_enable returns an error,
+nft_trans_destroy is called to free the transaction object.
+
+nft_trans_destroy() calls list_del(), but the transaction was never
+placed on a list -- the list head is all zeroes, this results in
+a null dereference:
+
+BUG: KASAN: null-ptr-deref in nft_trans_destroy+0x26/0x59
+Call Trace:
+ nft_trans_destroy+0x26/0x59
+ nf_tables_newtable+0x4bc/0x9bc
+ [..]
+
+Its sane to assume that nft_trans_destroy() can be called
+on the transaction object returned by nft_trans_alloc(), so
+make sure the list head is initialised.
+
+Fixes: 55dd6f93076b ("netfilter: nf_tables: use new transaction infrastructure to handle table")
+Reported-by: mingi cho <mgcho.minic@gmail.com>
+Signed-off-by: Florian Westphal <fw@strlen.de>
+Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ net/netfilter/nf_tables_api.c |    1 +
+ 1 file changed, 1 insertion(+)
+
+--- a/net/netfilter/nf_tables_api.c
++++ b/net/netfilter/nf_tables_api.c
+@@ -96,6 +96,7 @@ static struct nft_trans *nft_trans_alloc
+       if (trans == NULL)
+               return NULL;
++      INIT_LIST_HEAD(&trans->list);
+       trans->msg_type = msg_type;
+       trans->ctx      = *ctx;
index b71fa7aeec95a6d0076c643c07eb571618535df5..25ed5ce97019915f192fee39ad3221ef519ee51e 100644 (file)
@@ -34,3 +34,7 @@ ia64-processor-fix-wincompatible-pointer-types-in-ia64_get_irr.patch
 powerpc-fsl-pci-fix-class-code-of-pcie-root-port.patch
 powerpc-powernv-avoid-crashing-if-rng-is-null.patch
 mips-cpuinfo-fix-a-warning-for-config_cpumask_offstack.patch
+usb-hcd-fix-urb-giveback-issue-in-tasklet-function.patch
+usb-gadget-fix-use-after-free-read-in-usb_udc_uevent.patch
+netfilter-nf_tables-do-not-allow-set_id-to-refer-to-another-table.patch
+netfilter-nf_tables-fix-null-deref-due-to-zeroed-list-head.patch
diff --git a/queue-4.19/usb-gadget-fix-use-after-free-read-in-usb_udc_uevent.patch b/queue-4.19/usb-gadget-fix-use-after-free-read-in-usb_udc_uevent.patch
new file mode 100644 (file)
index 0000000..c50773e
--- /dev/null
@@ -0,0 +1,72 @@
+From 2191c00855b03aa59c20e698be713d952d51fc18 Mon Sep 17 00:00:00 2001
+From: Alan Stern <stern@rowland.harvard.edu>
+Date: Thu, 21 Jul 2022 11:07:10 -0400
+Subject: USB: gadget: Fix use-after-free Read in usb_udc_uevent()
+
+From: Alan Stern <stern@rowland.harvard.edu>
+
+commit 2191c00855b03aa59c20e698be713d952d51fc18 upstream.
+
+The syzbot fuzzer found a race between uevent callbacks and gadget
+driver unregistration that can cause a use-after-free bug:
+
+---------------------------------------------------------------
+BUG: KASAN: use-after-free in usb_udc_uevent+0x11f/0x130
+drivers/usb/gadget/udc/core.c:1732
+Read of size 8 at addr ffff888078ce2050 by task udevd/2968
+
+CPU: 1 PID: 2968 Comm: udevd Not tainted 5.19.0-rc4-next-20220628-syzkaller #0
+Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google
+06/29/2022
+Call Trace:
+ <TASK>
+ __dump_stack lib/dump_stack.c:88 [inline]
+ dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
+ print_address_description mm/kasan/report.c:317 [inline]
+ print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
+ kasan_report+0xbe/0x1f0 mm/kasan/report.c:495
+ usb_udc_uevent+0x11f/0x130 drivers/usb/gadget/udc/core.c:1732
+ dev_uevent+0x290/0x770 drivers/base/core.c:2424
+---------------------------------------------------------------
+
+The bug occurs because usb_udc_uevent() dereferences udc->driver but
+does so without acquiring the udc_lock mutex, which protects this
+field.  If the gadget driver is unbound from the udc concurrently with
+uevent processing, the driver structure may be accessed after it has
+been deallocated.
+
+To prevent the race, we make sure that the routine holds the mutex
+around the racing accesses.
+
+Link: <https://lore.kernel.org/all/0000000000004de90405a719c951@google.com>
+CC: stable@vger.kernel.org # fc274c1e9973
+Reported-and-tested-by: syzbot+b0de012ceb1e2a97891b@syzkaller.appspotmail.com
+Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
+Link: https://lore.kernel.org/r/YtlrnhHyrHsSky9m@rowland.harvard.edu
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/usb/gadget/udc/core.c |   11 ++++++-----
+ 1 file changed, 6 insertions(+), 5 deletions(-)
+
+--- a/drivers/usb/gadget/udc/core.c
++++ b/drivers/usb/gadget/udc/core.c
+@@ -1587,13 +1587,14 @@ static int usb_udc_uevent(struct device
+               return ret;
+       }
+-      if (udc->driver) {
++      mutex_lock(&udc_lock);
++      if (udc->driver)
+               ret = add_uevent_var(env, "USB_UDC_DRIVER=%s",
+                               udc->driver->function);
+-              if (ret) {
+-                      dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
+-                      return ret;
+-              }
++      mutex_unlock(&udc_lock);
++      if (ret) {
++              dev_err(dev, "failed to add uevent USB_UDC_DRIVER\n");
++              return ret;
+       }
+       return 0;
diff --git a/queue-4.19/usb-hcd-fix-urb-giveback-issue-in-tasklet-function.patch b/queue-4.19/usb-hcd-fix-urb-giveback-issue-in-tasklet-function.patch
new file mode 100644 (file)
index 0000000..c1eb7e8
--- /dev/null
@@ -0,0 +1,124 @@
+From 26c6c2f8a907c9e3a2f24990552a4d77235791e6 Mon Sep 17 00:00:00 2001
+From: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
+Date: Tue, 26 Jul 2022 15:49:18 +0800
+Subject: USB: HCD: Fix URB giveback issue in tasklet function
+
+From: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
+
+commit 26c6c2f8a907c9e3a2f24990552a4d77235791e6 upstream.
+
+Usb core introduce the mechanism of giveback of URB in tasklet context to
+reduce hardware interrupt handling time. On some test situation(such as
+FIO with 4KB block size), when tasklet callback function called to
+giveback URB, interrupt handler add URB node to the bh->head list also.
+If check bh->head list again after finish all URB giveback of local_list,
+then it may introduce a "dynamic balance" between giveback URB and add URB
+to bh->head list. This tasklet callback function may not exit for a long
+time, which will cause other tasklet function calls to be delayed. Some
+real-time applications(such as KB and Mouse) will see noticeable lag.
+
+In order to prevent the tasklet function from occupying the cpu for a long
+time at a time, new URBS will not be added to the local_list even though
+the bh->head list is not empty. But also need to ensure the left URB
+giveback to be processed in time, so add a member high_prio for structure
+giveback_urb_bh to prioritize tasklet and schelule this tasklet again if
+bh->head list is not empty.
+
+At the same time, we are able to prioritize tasklet through structure
+member high_prio. So, replace the local high_prio_bh variable with this
+structure member in usb_hcd_giveback_urb.
+
+Fixes: 94dfd7edfd5c ("USB: HCD: support giveback of URB in tasklet context")
+Cc: stable <stable@kernel.org>
+Reviewed-by: Alan Stern <stern@rowland.harvard.edu>
+Signed-off-by: Weitao Wang <WeitaoWang-oc@zhaoxin.com>
+Link: https://lore.kernel.org/r/20220726074918.5114-1-WeitaoWang-oc@zhaoxin.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/usb/core/hcd.c  |   26 +++++++++++++++-----------
+ include/linux/usb/hcd.h |    1 +
+ 2 files changed, 16 insertions(+), 11 deletions(-)
+
+--- a/drivers/usb/core/hcd.c
++++ b/drivers/usb/core/hcd.c
+@@ -1805,7 +1805,6 @@ static void usb_giveback_urb_bh(unsigned
+       spin_lock_irq(&bh->lock);
+       bh->running = true;
+- restart:
+       list_replace_init(&bh->head, &local_list);
+       spin_unlock_irq(&bh->lock);
+@@ -1819,10 +1818,17 @@ static void usb_giveback_urb_bh(unsigned
+               bh->completing_ep = NULL;
+       }
+-      /* check if there are new URBs to giveback */
++      /*
++       * giveback new URBs next time to prevent this function
++       * from not exiting for a long time.
++       */
+       spin_lock_irq(&bh->lock);
+-      if (!list_empty(&bh->head))
+-              goto restart;
++      if (!list_empty(&bh->head)) {
++              if (bh->high_prio)
++                      tasklet_hi_schedule(&bh->bh);
++              else
++                      tasklet_schedule(&bh->bh);
++      }
+       bh->running = false;
+       spin_unlock_irq(&bh->lock);
+ }
+@@ -1847,7 +1853,7 @@ static void usb_giveback_urb_bh(unsigned
+ void usb_hcd_giveback_urb(struct usb_hcd *hcd, struct urb *urb, int status)
+ {
+       struct giveback_urb_bh *bh;
+-      bool running, high_prio_bh;
++      bool running;
+       /* pass status to tasklet via unlinked */
+       if (likely(!urb->unlinked))
+@@ -1858,13 +1864,10 @@ void usb_hcd_giveback_urb(struct usb_hcd
+               return;
+       }
+-      if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe)) {
++      if (usb_pipeisoc(urb->pipe) || usb_pipeint(urb->pipe))
+               bh = &hcd->high_prio_bh;
+-              high_prio_bh = true;
+-      } else {
++      else
+               bh = &hcd->low_prio_bh;
+-              high_prio_bh = false;
+-      }
+       spin_lock(&bh->lock);
+       list_add_tail(&urb->urb_list, &bh->head);
+@@ -1873,7 +1876,7 @@ void usb_hcd_giveback_urb(struct usb_hcd
+       if (running)
+               ;
+-      else if (high_prio_bh)
++      else if (bh->high_prio)
+               tasklet_hi_schedule(&bh->bh);
+       else
+               tasklet_schedule(&bh->bh);
+@@ -2881,6 +2884,7 @@ int usb_add_hcd(struct usb_hcd *hcd,
+       /* initialize tasklets */
+       init_giveback_urb_bh(&hcd->high_prio_bh);
++      hcd->high_prio_bh.high_prio = true;
+       init_giveback_urb_bh(&hcd->low_prio_bh);
+       /* enable irqs just before we start the controller,
+--- a/include/linux/usb/hcd.h
++++ b/include/linux/usb/hcd.h
+@@ -66,6 +66,7 @@
+ struct giveback_urb_bh {
+       bool running;
++      bool high_prio;
+       spinlock_t lock;
+       struct list_head  head;
+       struct tasklet_struct bh;