From: Greg Kroah-Hartman Date: Sun, 22 Jan 2023 12:59:24 +0000 (+0100) Subject: 5.4-stable patches X-Git-Tag: v4.14.304~38 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2395e9c1bc708c7085624c1526c2075f7592f74c;p=thirdparty%2Fkernel%2Fstable-queue.git 5.4-stable patches added patches: btrfs-fix-race-between-quota-rescan-and-disable-leading-to-null-pointer-deref.patch cifs-do-not-include-page-data-when-checking-signature.patch mmc-sunxi-mmc-fix-clock-refcount-imbalance-during-unbind.patch --- diff --git a/queue-5.4/btrfs-fix-race-between-quota-rescan-and-disable-leading-to-null-pointer-deref.patch b/queue-5.4/btrfs-fix-race-between-quota-rescan-and-disable-leading-to-null-pointer-deref.patch new file mode 100644 index 00000000000..e2adc4e65e1 --- /dev/null +++ b/queue-5.4/btrfs-fix-race-between-quota-rescan-and-disable-leading-to-null-pointer-deref.patch @@ -0,0 +1,134 @@ +From b7adbf9ada3513d2092362c8eac5cddc5b651f5c Mon Sep 17 00:00:00 2001 +From: Filipe Manana +Date: Thu, 12 Jan 2023 16:31:08 +0000 +Subject: btrfs: fix race between quota rescan and disable leading to NULL pointer deref + +From: Filipe Manana + +commit b7adbf9ada3513d2092362c8eac5cddc5b651f5c upstream. + +If we have one task trying to start the quota rescan worker while another +one is trying to disable quotas, we can end up hitting a race that results +in the quota rescan worker doing a NULL pointer dereference. The steps for +this are the following: + +1) Quotas are enabled; + +2) Task A calls the quota rescan ioctl and enters btrfs_qgroup_rescan(). + It calls qgroup_rescan_init() which returns 0 (success) and then joins a + transaction and commits it; + +3) Task B calls the quota disable ioctl and enters btrfs_quota_disable(). + It clears the bit BTRFS_FS_QUOTA_ENABLED from fs_info->flags and calls + btrfs_qgroup_wait_for_completion(), which returns immediately since the + rescan worker is not yet running. + Then it starts a transaction and locks fs_info->qgroup_ioctl_lock; + +4) Task A queues the rescan worker, by calling btrfs_queue_work(); + +5) The rescan worker starts, and calls rescan_should_stop() at the start + of its while loop, which results in 0 iterations of the loop, since + the flag BTRFS_FS_QUOTA_ENABLED was cleared from fs_info->flags by + task B at step 3); + +6) Task B sets fs_info->quota_root to NULL; + +7) The rescan worker tries to start a transaction and uses + fs_info->quota_root as the root argument for btrfs_start_transaction(). + This results in a NULL pointer dereference down the call chain of + btrfs_start_transaction(). The stack trace is something like the one + reported in Link tag below: + + general protection fault, probably for non-canonical address 0xdffffc0000000041: 0000 [#1] PREEMPT SMP KASAN + KASAN: null-ptr-deref in range [0x0000000000000208-0x000000000000020f] + CPU: 1 PID: 34 Comm: kworker/u4:2 Not tainted 6.1.0-syzkaller-13872-gb6bb9676f216 #0 + Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/26/2022 + Workqueue: btrfs-qgroup-rescan btrfs_work_helper + RIP: 0010:start_transaction+0x48/0x10f0 fs/btrfs/transaction.c:564 + Code: 48 89 fb 48 (...) + RSP: 0018:ffffc90000ab7ab0 EFLAGS: 00010206 + RAX: 0000000000000041 RBX: 0000000000000208 RCX: ffff88801779ba80 + RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000 + RBP: dffffc0000000000 R08: 0000000000000001 R09: fffff52000156f5d + R10: fffff52000156f5d R11: 1ffff92000156f5c R12: 0000000000000000 + R13: 0000000000000001 R14: 0000000000000001 R15: 0000000000000003 + FS: 0000000000000000(0000) GS:ffff8880b9900000(0000) knlGS:0000000000000000 + CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 + CR2: 00007f2bea75b718 CR3: 000000001d0cc000 CR4: 00000000003506e0 + DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 + DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 + Call Trace: + + btrfs_qgroup_rescan_worker+0x3bb/0x6a0 fs/btrfs/qgroup.c:3402 + btrfs_work_helper+0x312/0x850 fs/btrfs/async-thread.c:280 + process_one_work+0x877/0xdb0 kernel/workqueue.c:2289 + worker_thread+0xb14/0x1330 kernel/workqueue.c:2436 + kthread+0x266/0x300 kernel/kthread.c:376 + ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:308 + + Modules linked in: + +So fix this by having the rescan worker function not attempt to start a +transaction if it didn't do any rescan work. + +Reported-by: syzbot+96977faa68092ad382c4@syzkaller.appspotmail.com +Link: https://lore.kernel.org/linux-btrfs/000000000000e5454b05f065a803@google.com/ +Fixes: e804861bd4e6 ("btrfs: fix deadlock between quota disable and qgroup rescan worker") +CC: stable@vger.kernel.org # 5.4+ +Signed-off-by: Filipe Manana +Signed-off-by: David Sterba +Signed-off-by: Greg Kroah-Hartman +--- + fs/btrfs/qgroup.c | 25 +++++++++++++++++-------- + 1 file changed, 17 insertions(+), 8 deletions(-) + +--- a/fs/btrfs/qgroup.c ++++ b/fs/btrfs/qgroup.c +@@ -3209,6 +3209,7 @@ static void btrfs_qgroup_rescan_worker(s + int err = -ENOMEM; + int ret = 0; + bool stopped = false; ++ bool did_leaf_rescans = false; + + path = btrfs_alloc_path(); + if (!path) +@@ -3229,6 +3230,7 @@ static void btrfs_qgroup_rescan_worker(s + } + + err = qgroup_rescan_leaf(trans, path); ++ did_leaf_rescans = true; + + if (err > 0) + btrfs_commit_transaction(trans); +@@ -3249,16 +3251,23 @@ out: + mutex_unlock(&fs_info->qgroup_rescan_lock); + + /* +- * only update status, since the previous part has already updated the +- * qgroup info. ++ * Only update status, since the previous part has already updated the ++ * qgroup info, and only if we did any actual work. This also prevents ++ * race with a concurrent quota disable, which has already set ++ * fs_info->quota_root to NULL and cleared BTRFS_FS_QUOTA_ENABLED at ++ * btrfs_quota_disable(). + */ +- trans = btrfs_start_transaction(fs_info->quota_root, 1); +- if (IS_ERR(trans)) { +- err = PTR_ERR(trans); ++ if (did_leaf_rescans) { ++ trans = btrfs_start_transaction(fs_info->quota_root, 1); ++ if (IS_ERR(trans)) { ++ err = PTR_ERR(trans); ++ trans = NULL; ++ btrfs_err(fs_info, ++ "fail to start transaction for status update: %d", ++ err); ++ } ++ } else { + trans = NULL; +- btrfs_err(fs_info, +- "fail to start transaction for status update: %d", +- err); + } + + mutex_lock(&fs_info->qgroup_rescan_lock); diff --git a/queue-5.4/cifs-do-not-include-page-data-when-checking-signature.patch b/queue-5.4/cifs-do-not-include-page-data-when-checking-signature.patch new file mode 100644 index 00000000000..265155dec00 --- /dev/null +++ b/queue-5.4/cifs-do-not-include-page-data-when-checking-signature.patch @@ -0,0 +1,52 @@ +From 30b2b2196d6e4cc24cbec633535a2404f258ce69 Mon Sep 17 00:00:00 2001 +From: Enzo Matsumiya +Date: Wed, 18 Jan 2023 14:06:57 -0300 +Subject: cifs: do not include page data when checking signature + +From: Enzo Matsumiya + +commit 30b2b2196d6e4cc24cbec633535a2404f258ce69 upstream. + +On async reads, page data is allocated before sending. When the +response is received but it has no data to fill (e.g. +STATUS_END_OF_FILE), __calc_signature() will still include the pages in +its computation, leading to an invalid signature check. + +This patch fixes this by not setting the async read smb_rqst page data +(zeroed by default) if its got_bytes is 0. + +This can be reproduced/verified with xfstests generic/465. + +Cc: +Signed-off-by: Enzo Matsumiya +Reviewed-by: Paulo Alcantara (SUSE) +Signed-off-by: Steve French +Signed-off-by: Greg Kroah-Hartman +--- + fs/cifs/smb2pdu.c | 15 +++++++++------ + 1 file changed, 9 insertions(+), 6 deletions(-) + +--- a/fs/cifs/smb2pdu.c ++++ b/fs/cifs/smb2pdu.c +@@ -3639,12 +3639,15 @@ smb2_readv_callback(struct mid_q_entry * + (struct smb2_sync_hdr *)rdata->iov[0].iov_base; + struct cifs_credits credits = { .value = 0, .instance = 0 }; + struct smb_rqst rqst = { .rq_iov = &rdata->iov[1], +- .rq_nvec = 1, +- .rq_pages = rdata->pages, +- .rq_offset = rdata->page_offset, +- .rq_npages = rdata->nr_pages, +- .rq_pagesz = rdata->pagesz, +- .rq_tailsz = rdata->tailsz }; ++ .rq_nvec = 1, }; ++ ++ if (rdata->got_bytes) { ++ rqst.rq_pages = rdata->pages; ++ rqst.rq_offset = rdata->page_offset; ++ rqst.rq_npages = rdata->nr_pages; ++ rqst.rq_pagesz = rdata->pagesz; ++ rqst.rq_tailsz = rdata->tailsz; ++ } + + cifs_dbg(FYI, "%s: mid=%llu state=%d result=%d bytes=%u\n", + __func__, mid->mid, mid->mid_state, rdata->result, diff --git a/queue-5.4/mmc-sunxi-mmc-fix-clock-refcount-imbalance-during-unbind.patch b/queue-5.4/mmc-sunxi-mmc-fix-clock-refcount-imbalance-during-unbind.patch new file mode 100644 index 00000000000..e128c34cb6e --- /dev/null +++ b/queue-5.4/mmc-sunxi-mmc-fix-clock-refcount-imbalance-during-unbind.patch @@ -0,0 +1,41 @@ +From 8509419758f2cc28dd05370385af0d91573b76b4 Mon Sep 17 00:00:00 2001 +From: Samuel Holland +Date: Tue, 9 Aug 2022 21:25:09 -0500 +Subject: mmc: sunxi-mmc: Fix clock refcount imbalance during unbind + +From: Samuel Holland + +commit 8509419758f2cc28dd05370385af0d91573b76b4 upstream. + +If the controller is suspended by runtime PM, the clock is already +disabled, so do not try to disable it again during removal. Use +pm_runtime_disable() to flush any pending runtime PM transitions. + +Fixes: 9a8e1e8cc2c0 ("mmc: sunxi: Add runtime_pm support") +Signed-off-by: Samuel Holland +Acked-by: Jernej Skrabec +Cc: stable@vger.kernel.org +Link: https://lore.kernel.org/r/20220810022509.43743-1-samuel@sholland.org +Signed-off-by: Ulf Hansson +Signed-off-by: Greg Kroah-Hartman +--- + drivers/mmc/host/sunxi-mmc.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +--- a/drivers/mmc/host/sunxi-mmc.c ++++ b/drivers/mmc/host/sunxi-mmc.c +@@ -1456,9 +1456,11 @@ static int sunxi_mmc_remove(struct platf + struct sunxi_mmc_host *host = mmc_priv(mmc); + + mmc_remove_host(mmc); +- pm_runtime_force_suspend(&pdev->dev); +- disable_irq(host->irq); +- sunxi_mmc_disable(host); ++ pm_runtime_disable(&pdev->dev); ++ if (!pm_runtime_status_suspended(&pdev->dev)) { ++ disable_irq(host->irq); ++ sunxi_mmc_disable(host); ++ } + dma_free_coherent(&pdev->dev, PAGE_SIZE, host->sg_cpu, host->sg_dma); + mmc_free_host(mmc); + diff --git a/queue-5.4/series b/queue-5.4/series index d510f5e70c6..dcf88e903ba 100644 --- a/queue-5.4/series +++ b/queue-5.4/series @@ -28,3 +28,6 @@ misc-fastrpc-don-t-remove-map-on-creater_process-and-device_release.patch misc-fastrpc-fix-use-after-free-race-condition-for-maps.patch usb-core-hub-disable-autosuspend-for-ti-tusb8041.patch comedi-adv_pci1760-fix-pwm-instruction-handling.patch +mmc-sunxi-mmc-fix-clock-refcount-imbalance-during-unbind.patch +btrfs-fix-race-between-quota-rescan-and-disable-leading-to-null-pointer-deref.patch +cifs-do-not-include-page-data-when-checking-signature.patch