From: Greg Kroah-Hartman Date: Mon, 16 May 2022 08:03:33 +0000 (+0200) Subject: 5.15-stable patches X-Git-Tag: v4.9.315~37 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0fe3ba4524bcf228693b9353ee2906af7c1ee20b;p=thirdparty%2Fkernel%2Fstable-queue.git 5.15-stable patches added patches: firmware_loader-use-kernel-credentials-when-reading-firmware.patch kvm-ppc-book3s-pr-enable-msr_dr-for-switch_mmu_context.patch tty-n_gsm-fix-buffer-over-read-in-gsm_dlci_data.patch tty-n_gsm-fix-mux-activation-issues-in-gsm_config.patch tty-serial-digicolor-fix-possible-null-ptr-deref-in-digicolor_uart_probe.patch usb-cdc-wdm-fix-reading-stuck-on-device-close.patch usb-xhci-mtk-fix-fs-isoc-s-transfer-error.patch x86-mm-fix-marking-of-unused-sub-pmd-ranges.patch --- diff --git a/queue-5.15/firmware_loader-use-kernel-credentials-when-reading-firmware.patch b/queue-5.15/firmware_loader-use-kernel-credentials-when-reading-firmware.patch new file mode 100644 index 00000000000..17dd439dfc7 --- /dev/null +++ b/queue-5.15/firmware_loader-use-kernel-credentials-when-reading-firmware.patch @@ -0,0 +1,87 @@ +From 581dd69830341d299b0c097fc366097ab497d679 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Thi=C3=A9baud=20Weksteen?= +Date: Mon, 2 May 2022 10:49:52 +1000 +Subject: firmware_loader: use kernel credentials when reading firmware +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Thiébaud Weksteen + +commit 581dd69830341d299b0c097fc366097ab497d679 upstream. + +Device drivers may decide to not load firmware when probed to avoid +slowing down the boot process should the firmware filesystem not be +available yet. In this case, the firmware loading request may be done +when a device file associated with the driver is first accessed. The +credentials of the userspace process accessing the device file may be +used to validate access to the firmware files requested by the driver. +Ensure that the kernel assumes the responsibility of reading the +firmware. + +This was observed on Android for a graphic driver loading their firmware +when the device file (e.g. /dev/mali0) was first opened by userspace +(i.e. surfaceflinger). The security context of surfaceflinger was used +to validate the access to the firmware file (e.g. +/vendor/firmware/mali.bin). + +Previously, Android configurations were not setting up the +firmware_class.path command line argument and were relying on the +userspace fallback mechanism. In this case, the security context of the +userspace daemon (i.e. ueventd) was consistently used to read firmware +files. More Android devices are now found to set firmware_class.path +which gives the kernel the opportunity to read the firmware directly +(via kernel_read_file_from_path_initns). In this scenario, the current +process credentials were used, even if unrelated to the loading of the +firmware file. + +Signed-off-by: Thiébaud Weksteen +Cc: # 5.10 +Reviewed-by: Paul Moore +Acked-by: Luis Chamberlain +Link: https://lore.kernel.org/r/20220502004952.3970800-1-tweek@google.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/base/firmware_loader/main.c | 17 +++++++++++++++++ + 1 file changed, 17 insertions(+) + +--- a/drivers/base/firmware_loader/main.c ++++ b/drivers/base/firmware_loader/main.c +@@ -795,6 +795,8 @@ _request_firmware(const struct firmware + size_t offset, u32 opt_flags) + { + struct firmware *fw = NULL; ++ struct cred *kern_cred = NULL; ++ const struct cred *old_cred; + bool nondirect = false; + int ret; + +@@ -811,6 +813,18 @@ _request_firmware(const struct firmware + if (ret <= 0) /* error or already assigned */ + goto out; + ++ /* ++ * We are about to try to access the firmware file. Because we may have been ++ * called by a driver when serving an unrelated request from userland, we use ++ * the kernel credentials to read the file. ++ */ ++ kern_cred = prepare_kernel_cred(NULL); ++ if (!kern_cred) { ++ ret = -ENOMEM; ++ goto out; ++ } ++ old_cred = override_creds(kern_cred); ++ + ret = fw_get_filesystem_firmware(device, fw->priv, "", NULL); + + /* Only full reads can support decompression, platform, and sysfs. */ +@@ -836,6 +850,9 @@ _request_firmware(const struct firmware + } else + ret = assign_fw(fw, device); + ++ revert_creds(old_cred); ++ put_cred(kern_cred); ++ + out: + if (ret < 0) { + fw_abort_batch_reqs(fw); diff --git a/queue-5.15/kvm-ppc-book3s-pr-enable-msr_dr-for-switch_mmu_context.patch b/queue-5.15/kvm-ppc-book3s-pr-enable-msr_dr-for-switch_mmu_context.patch new file mode 100644 index 00000000000..e9c2bbf5ae2 --- /dev/null +++ b/queue-5.15/kvm-ppc-book3s-pr-enable-msr_dr-for-switch_mmu_context.patch @@ -0,0 +1,71 @@ +From ee8348496c77e3737d0a6cda307a521f2cff954f Mon Sep 17 00:00:00 2001 +From: Alexander Graf +Date: Tue, 10 May 2022 14:37:17 +0200 +Subject: KVM: PPC: Book3S PR: Enable MSR_DR for switch_mmu_context() + +From: Alexander Graf + +commit ee8348496c77e3737d0a6cda307a521f2cff954f upstream. + +Commit 863771a28e27 ("powerpc/32s: Convert switch_mmu_context() to C") +moved the switch_mmu_context() to C. While in principle a good idea, it +meant that the function now uses the stack. The stack is not accessible +from real mode though. + +So to keep calling the function, let's turn on MSR_DR while we call it. +That way, all pointer references to the stack are handled virtually. + +In addition, make sure to save/restore r12 on the stack, as it may get +clobbered by the C function. + +Fixes: 863771a28e27 ("powerpc/32s: Convert switch_mmu_context() to C") +Cc: stable@vger.kernel.org # v5.14+ +Reported-by: Matt Evans +Signed-off-by: Alexander Graf +Signed-off-by: Michael Ellerman +Link: https://lore.kernel.org/r/20220510123717.24508-1-graf@amazon.com +Signed-off-by: Greg Kroah-Hartman +--- + arch/powerpc/kvm/book3s_32_sr.S | 26 +++++++++++++++++++++----- + 1 file changed, 21 insertions(+), 5 deletions(-) + +diff --git a/arch/powerpc/kvm/book3s_32_sr.S b/arch/powerpc/kvm/book3s_32_sr.S +index e3ab9df6cf19..6cfcd20d4668 100644 +--- a/arch/powerpc/kvm/book3s_32_sr.S ++++ b/arch/powerpc/kvm/book3s_32_sr.S +@@ -122,11 +122,27 @@ + + /* 0x0 - 0xb */ + +- /* 'current->mm' needs to be in r4 */ +- tophys(r4, r2) +- lwz r4, MM(r4) +- tophys(r4, r4) +- /* This only clobbers r0, r3, r4 and r5 */ ++ /* switch_mmu_context() needs paging, let's enable it */ ++ mfmsr r9 ++ ori r11, r9, MSR_DR ++ mtmsr r11 ++ sync ++ ++ /* switch_mmu_context() clobbers r12, rescue it */ ++ SAVE_GPR(12, r1) ++ ++ /* Calling switch_mmu_context(, current->mm, ); */ ++ lwz r4, MM(r2) + bl switch_mmu_context + ++ /* restore r12 */ ++ REST_GPR(12, r1) ++ ++ /* Disable paging again */ ++ mfmsr r9 ++ li r6, MSR_DR ++ andc r9, r9, r6 ++ mtmsr r9 ++ sync ++ + .endm +-- +2.36.1 + diff --git a/queue-5.15/series b/queue-5.15/series index b2d9c7a661e..47a31f5c3af 100644 --- a/queue-5.15/series +++ b/queue-5.15/series @@ -60,3 +60,11 @@ tcp-dynamically-allocate-the-perturb-table-used-by-s.patch tcp-increase-source-port-perturb-table-to-2-16.patch tcp-drop-the-hash_32-part-from-the-index-calculation.patch interconnect-restore-sync-state-by-ignoring-ipa-virt.patch +firmware_loader-use-kernel-credentials-when-reading-firmware.patch +kvm-ppc-book3s-pr-enable-msr_dr-for-switch_mmu_context.patch +usb-xhci-mtk-fix-fs-isoc-s-transfer-error.patch +x86-mm-fix-marking-of-unused-sub-pmd-ranges.patch +tty-serial-digicolor-fix-possible-null-ptr-deref-in-digicolor_uart_probe.patch +tty-n_gsm-fix-buffer-over-read-in-gsm_dlci_data.patch +tty-n_gsm-fix-mux-activation-issues-in-gsm_config.patch +usb-cdc-wdm-fix-reading-stuck-on-device-close.patch diff --git a/queue-5.15/tty-n_gsm-fix-buffer-over-read-in-gsm_dlci_data.patch b/queue-5.15/tty-n_gsm-fix-buffer-over-read-in-gsm_dlci_data.patch new file mode 100644 index 00000000000..d918c87231e --- /dev/null +++ b/queue-5.15/tty-n_gsm-fix-buffer-over-read-in-gsm_dlci_data.patch @@ -0,0 +1,37 @@ +From fd442e5ba30aaa75ea47b32149e7a3110dc20a46 Mon Sep 17 00:00:00 2001 +From: Daniel Starke +Date: Wed, 4 May 2022 10:17:31 +0200 +Subject: tty: n_gsm: fix buffer over-read in gsm_dlci_data() + +From: Daniel Starke + +commit fd442e5ba30aaa75ea47b32149e7a3110dc20a46 upstream. + +'len' is decreased after each octet that has its EA bit set to 0, which +means that the value is encoded with additional octets. However, the final +octet does not decreases 'len' which results in 'len' being one byte too +long. A buffer over-read may occur in tty_insert_flip_string() as it tries +to read one byte more than the passed content size of 'data'. +Decrease 'len' also for the final octet which has the EA bit set to 1 to +write the correct number of bytes from the internal receive buffer to the +virtual tty. + +Fixes: 2e124b4a390c ("TTY: switch tty_flip_buffer_push") +Cc: stable@vger.kernel.org +Signed-off-by: Daniel Starke +Link: https://lore.kernel.org/r/20220504081733.3494-1-daniel.starke@siemens.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/tty/n_gsm.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/drivers/tty/n_gsm.c ++++ b/drivers/tty/n_gsm.c +@@ -1587,6 +1587,7 @@ static void gsm_dlci_data(struct gsm_dlc + if (len == 0) + return; + } ++ len--; + slen++; + tty = tty_port_tty_get(port); + if (tty) { diff --git a/queue-5.15/tty-n_gsm-fix-mux-activation-issues-in-gsm_config.patch b/queue-5.15/tty-n_gsm-fix-mux-activation-issues-in-gsm_config.patch new file mode 100644 index 00000000000..0db04e15aa2 --- /dev/null +++ b/queue-5.15/tty-n_gsm-fix-mux-activation-issues-in-gsm_config.patch @@ -0,0 +1,60 @@ +From edd5f60c340086891fab094ad61270d6c80f9ca4 Mon Sep 17 00:00:00 2001 +From: Daniel Starke +Date: Wed, 4 May 2022 10:17:32 +0200 +Subject: tty: n_gsm: fix mux activation issues in gsm_config() + +From: Daniel Starke + +commit edd5f60c340086891fab094ad61270d6c80f9ca4 upstream. + +The current implementation activates the mux if it was restarted and opens +the control channel if the mux was previously closed and we are now acting +as initiator instead of responder, which is the default setting. +This has two issues. +1) No mux is activated if we keep all default values and only switch to +initiator. The control channel is not allocated but will be opened next +which results in a NULL pointer dereference. +2) Switching the configuration after it was once configured while keeping +the initiator value the same will not reopen the control channel if it was +closed due to parameter incompatibilities. The mux remains dead. + +Fix 1) by always activating the mux if it is dead after configuration. +Fix 2) by always opening the control channel after mux activation. + +Fixes: e1eaea46bb40 ("tty: n_gsm line discipline") +Cc: stable@vger.kernel.org +Signed-off-by: Daniel Starke +Link: https://lore.kernel.org/r/20220504081733.3494-2-daniel.starke@siemens.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/tty/n_gsm.c | 12 ++++++++---- + 1 file changed, 8 insertions(+), 4 deletions(-) + +--- a/drivers/tty/n_gsm.c ++++ b/drivers/tty/n_gsm.c +@@ -2276,6 +2276,7 @@ static void gsm_copy_config_values(struc + + static int gsm_config(struct gsm_mux *gsm, struct gsm_config *c) + { ++ int ret = 0; + int need_close = 0; + int need_restart = 0; + +@@ -2343,10 +2344,13 @@ static int gsm_config(struct gsm_mux *gs + * FIXME: We need to separate activation/deactivation from adding + * and removing from the mux array + */ +- if (need_restart) +- gsm_activate_mux(gsm); +- if (gsm->initiator && need_close) +- gsm_dlci_begin_open(gsm->dlci[0]); ++ if (gsm->dead) { ++ ret = gsm_activate_mux(gsm); ++ if (ret) ++ return ret; ++ if (gsm->initiator) ++ gsm_dlci_begin_open(gsm->dlci[0]); ++ } + return 0; + } + diff --git a/queue-5.15/tty-serial-digicolor-fix-possible-null-ptr-deref-in-digicolor_uart_probe.patch b/queue-5.15/tty-serial-digicolor-fix-possible-null-ptr-deref-in-digicolor_uart_probe.patch new file mode 100644 index 00000000000..9cc21eb5e3a --- /dev/null +++ b/queue-5.15/tty-serial-digicolor-fix-possible-null-ptr-deref-in-digicolor_uart_probe.patch @@ -0,0 +1,40 @@ +From 447ee1516f19f534a228dda237eddb202f23e163 Mon Sep 17 00:00:00 2001 +From: Yang Yingliang +Date: Thu, 5 May 2022 20:46:21 +0800 +Subject: tty/serial: digicolor: fix possible null-ptr-deref in digicolor_uart_probe() + +From: Yang Yingliang + +commit 447ee1516f19f534a228dda237eddb202f23e163 upstream. + +It will cause null-ptr-deref when using 'res', if platform_get_resource() +returns NULL, so move using 'res' after devm_ioremap_resource() that +will check it to avoid null-ptr-deref. +And use devm_platform_get_and_ioremap_resource() to simplify code. + +Fixes: 5930cb3511df ("serial: driver for Conexant Digicolor USART") +Signed-off-by: Yang Yingliang +Reviewed-by: Baruch Siach +Cc: stable +Link: https://lore.kernel.org/r/20220505124621.1592697-1-yangyingliang@huawei.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/tty/serial/digicolor-usart.c | 5 ++--- + 1 file changed, 2 insertions(+), 3 deletions(-) + +--- a/drivers/tty/serial/digicolor-usart.c ++++ b/drivers/tty/serial/digicolor-usart.c +@@ -471,11 +471,10 @@ static int digicolor_uart_probe(struct p + if (IS_ERR(uart_clk)) + return PTR_ERR(uart_clk); + +- res = platform_get_resource(pdev, IORESOURCE_MEM, 0); +- dp->port.mapbase = res->start; +- dp->port.membase = devm_ioremap_resource(&pdev->dev, res); ++ dp->port.membase = devm_platform_get_and_ioremap_resource(pdev, 0, &res); + if (IS_ERR(dp->port.membase)) + return PTR_ERR(dp->port.membase); ++ dp->port.mapbase = res->start; + + irq = platform_get_irq(pdev, 0); + if (irq < 0) diff --git a/queue-5.15/usb-cdc-wdm-fix-reading-stuck-on-device-close.patch b/queue-5.15/usb-cdc-wdm-fix-reading-stuck-on-device-close.patch new file mode 100644 index 00000000000..a622232ea59 --- /dev/null +++ b/queue-5.15/usb-cdc-wdm-fix-reading-stuck-on-device-close.patch @@ -0,0 +1,56 @@ +From 01e01f5c89773c600a9f0b32c888de0146066c3a Mon Sep 17 00:00:00 2001 +From: Sergey Ryazanov +Date: Sun, 1 May 2022 20:58:28 +0300 +Subject: usb: cdc-wdm: fix reading stuck on device close + +From: Sergey Ryazanov + +commit 01e01f5c89773c600a9f0b32c888de0146066c3a upstream. + +cdc-wdm tracks whether a response reading request is in-progress and +blocks the next request from being sent until the previous request is +completed. As soon as last user closes the cdc-wdm device file, the +driver cancels any ongoing requests, resets the pending response +counter, but leaves the response reading in-progress flag +(WDM_RESPONDING) untouched. + +So if the user closes the device file during the response receive +request is being performed, no more data will be obtained from the +modem. The request will be cancelled, effectively preventing the +WDM_RESPONDING flag from being reseted. Keeping the flag set will +prevent a new response receive request from being sent, permanently +blocking the read path. The read path will staying blocked until the +module will be reloaded or till the modem will be re-attached. + +This stuck has been observed with a Huawei E3372 modem attached to an +OpenWrt router and using the comgt utility to set up a network +connection. + +Fix this issue by clearing the WDM_RESPONDING flag on the device file +close. + +Without this fix, the device reading stuck can be easily reproduced in a +few connection establishing attempts. With this fix, a load test for +modem connection re-establishing worked for several hours without any +issues. + +Fixes: 922a5eadd5a3 ("usb: cdc-wdm: Fix race between autosuspend and reading from the device") +Signed-off-by: Sergey Ryazanov +Cc: stable +Acked-by: Oliver Neukum +Link: https://lore.kernel.org/r/20220501175828.8185-1-ryazanov.s.a@gmail.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/usb/class/cdc-wdm.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/drivers/usb/class/cdc-wdm.c ++++ b/drivers/usb/class/cdc-wdm.c +@@ -774,6 +774,7 @@ static int wdm_release(struct inode *ino + poison_urbs(desc); + spin_lock_irq(&desc->iuspin); + desc->resp_count = 0; ++ clear_bit(WDM_RESPONDING, &desc->flags); + spin_unlock_irq(&desc->iuspin); + desc->manage_power(desc->intf, 0); + unpoison_urbs(desc); diff --git a/queue-5.15/usb-xhci-mtk-fix-fs-isoc-s-transfer-error.patch b/queue-5.15/usb-xhci-mtk-fix-fs-isoc-s-transfer-error.patch new file mode 100644 index 00000000000..cc7e7ebe88d --- /dev/null +++ b/queue-5.15/usb-xhci-mtk-fix-fs-isoc-s-transfer-error.patch @@ -0,0 +1,60 @@ +From c237566b78ad8c72bc0431c5d6171db8d12e6f94 Mon Sep 17 00:00:00 2001 +From: Chunfeng Yun +Date: Thu, 12 May 2022 14:49:30 +0800 +Subject: usb: xhci-mtk: fix fs isoc's transfer error + +From: Chunfeng Yun + +commit c237566b78ad8c72bc0431c5d6171db8d12e6f94 upstream. + +Due to the scheduler allocates the optimal bandwidth for FS ISOC endpoints, +this may be not enough actually and causes data transfer error, so come up +with an estimate that is no less than the worst case bandwidth used for +any one mframe, but may be an over-estimate. + +Fixes: 451d3912586a ("usb: xhci-mtk: update fs bus bandwidth by bw_budget_table") +Cc: stable@vger.kernel.org +Signed-off-by: Chunfeng Yun +Link: https://lore.kernel.org/r/20220512064931.31670-1-chunfeng.yun@mediatek.com +Signed-off-by: Greg Kroah-Hartman +--- + drivers/usb/host/xhci-mtk-sch.c | 16 +++++++--------- + 1 file changed, 7 insertions(+), 9 deletions(-) + +--- a/drivers/usb/host/xhci-mtk-sch.c ++++ b/drivers/usb/host/xhci-mtk-sch.c +@@ -465,7 +465,7 @@ static int check_fs_bus_bw(struct mu3h_s + */ + for (j = 0; j < sch_ep->num_budget_microframes; j++) { + k = XHCI_MTK_BW_INDEX(base + j); +- tmp = tt->fs_bus_bw[k] + sch_ep->bw_budget_table[j]; ++ tmp = tt->fs_bus_bw[k] + sch_ep->bw_cost_per_microframe; + if (tmp > FS_PAYLOAD_MAX) + return -ESCH_BW_OVERFLOW; + } +@@ -539,19 +539,17 @@ static int check_sch_tt(struct mu3h_sch_ + static void update_sch_tt(struct mu3h_sch_ep_info *sch_ep, bool used) + { + struct mu3h_sch_tt *tt = sch_ep->sch_tt; ++ int bw_updated; + u32 base; +- int i, j, k; ++ int i, j; ++ ++ bw_updated = sch_ep->bw_cost_per_microframe * (used ? 1 : -1); + + for (i = 0; i < sch_ep->num_esit; i++) { + base = sch_ep->offset + i * sch_ep->esit; + +- for (j = 0; j < sch_ep->num_budget_microframes; j++) { +- k = XHCI_MTK_BW_INDEX(base + j); +- if (used) +- tt->fs_bus_bw[k] += sch_ep->bw_budget_table[j]; +- else +- tt->fs_bus_bw[k] -= sch_ep->bw_budget_table[j]; +- } ++ for (j = 0; j < sch_ep->num_budget_microframes; j++) ++ tt->fs_bus_bw[XHCI_MTK_BW_INDEX(base + j)] += bw_updated; + } + + if (used) diff --git a/queue-5.15/x86-mm-fix-marking-of-unused-sub-pmd-ranges.patch b/queue-5.15/x86-mm-fix-marking-of-unused-sub-pmd-ranges.patch new file mode 100644 index 00000000000..1abf50e9e35 --- /dev/null +++ b/queue-5.15/x86-mm-fix-marking-of-unused-sub-pmd-ranges.patch @@ -0,0 +1,48 @@ +From 280abe14b6e0a38de9cc86fe6a019523aadd8f70 Mon Sep 17 00:00:00 2001 +From: Adrian-Ken Rueegsegger +Date: Mon, 9 May 2022 11:06:37 +0200 +Subject: x86/mm: Fix marking of unused sub-pmd ranges + +From: Adrian-Ken Rueegsegger + +commit 280abe14b6e0a38de9cc86fe6a019523aadd8f70 upstream. + +The unused part precedes the new range spanned by the start, end parameters +of vmemmap_use_new_sub_pmd(). This means it actually goes from +ALIGN_DOWN(start, PMD_SIZE) up to start. + +Use the correct address when applying the mark using memset. + +Fixes: 8d400913c231 ("x86/vmemmap: handle unpopulated sub-pmd ranges") +Signed-off-by: Adrian-Ken Rueegsegger +Signed-off-by: Thomas Gleixner +Reviewed-by: Oscar Salvador +Reviewed-by: David Hildenbrand +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20220509090637.24152-2-ken@codelabs.ch +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/mm/init_64.c | 5 +++-- + 1 file changed, 3 insertions(+), 2 deletions(-) + +--- a/arch/x86/mm/init_64.c ++++ b/arch/x86/mm/init_64.c +@@ -902,6 +902,8 @@ static void __meminit vmemmap_use_sub_pm + + static void __meminit vmemmap_use_new_sub_pmd(unsigned long start, unsigned long end) + { ++ const unsigned long page = ALIGN_DOWN(start, PMD_SIZE); ++ + vmemmap_flush_unused_pmd(); + + /* +@@ -914,8 +916,7 @@ static void __meminit vmemmap_use_new_su + * Mark with PAGE_UNUSED the unused parts of the new memmap range + */ + if (!IS_ALIGNED(start, PMD_SIZE)) +- memset((void *)start, PAGE_UNUSED, +- start - ALIGN_DOWN(start, PMD_SIZE)); ++ memset((void *)page, PAGE_UNUSED, start - page); + + /* + * We want to avoid memset(PAGE_UNUSED) when populating the vmemmap of