Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10E1929CB4C for ; Wed, 18 Jun 2025 11:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750245383; cv=none; b=cbpZILMV/ES7zcqs0EQ9nnLajIzDEBap0Agcz4hAruUHiWLden5fS8dIIfqTu7Qot+0hfV+NIqaj3kdxZLCRTfpYrdOyIoY3zDjJr7KBbwHjkQhaV2XRAnYI7wQ5ZvEVGXrmIzxGRkquiWoEterEa/zHu3Sk55ggtQedEhq+4q4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1750245383; c=relaxed/simple; bh=yQ65LOc/aBzGwYIPuyzIjIvovZqzRIImwx8EbEnbl/s=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=DM8LR1BYOUpYBD9cmdBkSUtdm8BDsci/ggW0tFZQz1wBhg/svt8HShXGxtHA3APxZqQhbWBda1QL7PAaYCl5ZgMeMlbiMWWq2NANrdiozbv5p0X3ipurulgMu0Skdbf/Lsz6Y8lMIG3k2M18wRUjK9ChqvTEFmlpecSLHenT0EU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=PoEFV7ve; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="PoEFV7ve" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7CBCFC4CEE7; Wed, 18 Jun 2025 11:16:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1750245382; bh=yQ65LOc/aBzGwYIPuyzIjIvovZqzRIImwx8EbEnbl/s=; h=From:To:Cc:Subject:Date:Reply-to:From; b=PoEFV7ven7MI8v5Za8Wg59e5fQff0ylQb1VLIm1N+EtedmZJbN8xY7b9W1hvYHzNM KVg4K98QqSppdUs+sOvgrXTFbqVDfDab7Mgl4FlQZHt0OMibXRF2kQR2ix8+oWjK2Q YwnE6XKyfEA8MY6SBUKjyHWP3XTqpSfgxAUVOfTs= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2022-50216: md-raid: destroy the bitmap after destroying the thread Date: Wed, 18 Jun 2025 13:04:41 +0200 Message-ID: <2025061845-CVE-2022-50216-bac4@gregkh> X-Mailer: git-send-email 2.49.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=5769; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=QOGWVuCjkUSiibDt19tiroBAQuodKMGZVD5M/ZYsTSo=; b=owGbwMvMwCRo6H6F97bub03G02pJDBlBc2Z2zz76fc25sKZ5f15MNz8s8UukjTvQ+2aOrtEBm Xn3luyv7IhlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJbGVkmJ9voV7FoVx94PwP i4OrFddqsVi332ZY0HJ+UvJeBUOOxRkxBW2yYRqFRQHiAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: 8bit From: Greg Kroah-Hartman Description =========== In the Linux kernel, the following vulnerability has been resolved: md-raid: destroy the bitmap after destroying the thread When we ran the lvm test "shell/integrity-blocksize-3.sh" on a kernel with kasan, we got failure in write_page. The reason for the failure is that md_bitmap_destroy is called before destroying the thread and the thread may be waiting in the function write_page for the bio to complete. When the thread finishes waiting, it executes "if (test_bit(BITMAP_WRITE_ERROR, &bitmap->flags))", which triggers the kasan warning. Note that the commit 48df498daf62 that caused this bug claims that it is neede for md-cluster, you should check md-cluster and possibly find another bugfix for it. BUG: KASAN: use-after-free in write_page+0x18d/0x680 [md_mod] Read of size 8 at addr ffff889162030c78 by task mdX_raid1/5539 CPU: 10 PID: 5539 Comm: mdX_raid1 Not tainted 5.19.0-rc2 #1 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 Call Trace: dump_stack_lvl+0x34/0x44 print_report.cold+0x45/0x57a ? __lock_text_start+0x18/0x18 ? write_page+0x18d/0x680 [md_mod] kasan_report+0xa8/0xe0 ? write_page+0x18d/0x680 [md_mod] kasan_check_range+0x13f/0x180 write_page+0x18d/0x680 [md_mod] ? super_sync+0x4d5/0x560 [dm_raid] ? md_bitmap_file_kick+0xa0/0xa0 [md_mod] ? rs_set_dev_and_array_sectors+0x2e0/0x2e0 [dm_raid] ? mutex_trylock+0x120/0x120 ? preempt_count_add+0x6b/0xc0 ? preempt_count_sub+0xf/0xc0 md_update_sb+0x707/0xe40 [md_mod] md_reap_sync_thread+0x1b2/0x4a0 [md_mod] md_check_recovery+0x533/0x960 [md_mod] raid1d+0xc8/0x2a20 [raid1] ? var_wake_function+0xe0/0xe0 ? psi_group_change+0x411/0x500 ? preempt_count_sub+0xf/0xc0 ? _raw_spin_lock_irqsave+0x78/0xc0 ? __lock_text_start+0x18/0x18 ? raid1_end_read_request+0x2a0/0x2a0 [raid1] ? preempt_count_sub+0xf/0xc0 ? _raw_spin_unlock_irqrestore+0x19/0x40 ? del_timer_sync+0xa9/0x100 ? try_to_del_timer_sync+0xc0/0xc0 ? _raw_spin_lock_irqsave+0x78/0xc0 ? __lock_text_start+0x18/0x18 ? __list_del_entry_valid+0x68/0xa0 ? finish_wait+0xa3/0x100 md_thread+0x161/0x260 [md_mod] ? unregister_md_personality+0xa0/0xa0 [md_mod] ? _raw_spin_lock_irqsave+0x78/0xc0 ? prepare_to_wait_event+0x2c0/0x2c0 ? unregister_md_personality+0xa0/0xa0 [md_mod] kthread+0x148/0x180 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x1f/0x30 Allocated by task 5522: kasan_save_stack+0x1e/0x40 __kasan_kmalloc+0x80/0xa0 md_bitmap_create+0xa8/0xe80 [md_mod] md_run+0x777/0x1300 [md_mod] raid_ctr+0x249c/0x4a30 [dm_raid] dm_table_add_target+0x2b0/0x620 [dm_mod] table_load+0x1c8/0x400 [dm_mod] ctl_ioctl+0x29e/0x560 [dm_mod] dm_compat_ctl_ioctl+0x7/0x20 [dm_mod] __do_compat_sys_ioctl+0xfa/0x160 do_syscall_64+0x90/0xc0 entry_SYSCALL_64_after_hwframe+0x46/0xb0 Freed by task 5680: kasan_save_stack+0x1e/0x40 kasan_set_track+0x21/0x40 kasan_set_free_info+0x20/0x40 __kasan_slab_free+0xf7/0x140 kfree+0x80/0x240 md_bitmap_free+0x1c3/0x280 [md_mod] __md_stop+0x21/0x120 [md_mod] md_stop+0x9/0x40 [md_mod] raid_dtr+0x1b/0x40 [dm_raid] dm_table_destroy+0x98/0x1e0 [dm_mod] __dm_destroy+0x199/0x360 [dm_mod] dev_remove+0x10c/0x160 [dm_mod] ctl_ioctl+0x29e/0x560 [dm_mod] dm_compat_ctl_ioctl+0x7/0x20 [dm_mod] __do_compat_sys_ioctl+0xfa/0x160 do_syscall_64+0x90/0xc0 entry_SYSCALL_64_after_hwframe+0x46/0xb0 The Linux kernel CVE team has assigned CVE-2022-50216 to this issue. Affected and fixed versions =========================== Issue introduced in 4.12 with commit 48df498daf62e1292868005675331929305067f0 and fixed in 5.10.137 with commit e0bdaed154e5b9cc4310ddaf5da290483d00e6ba Issue introduced in 4.12 with commit 48df498daf62e1292868005675331929305067f0 and fixed in 5.15.61 with commit c5e4cdd4438787e008c1b4a23bb66e49f4b12417 Issue introduced in 4.12 with commit 48df498daf62e1292868005675331929305067f0 and fixed in 5.18.18 with commit f192434601b9a1ef072b8ad631d6008fea578234 Issue introduced in 4.12 with commit 48df498daf62e1292868005675331929305067f0 and fixed in 5.19.2 with commit 7f82027b6b74553f7fe8541c0a04bfbd3557fb11 Issue introduced in 4.12 with commit 48df498daf62e1292868005675331929305067f0 and fixed in 6.0 with commit e151db8ecfb019b7da31d076130a794574c89f6f Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2022-50216 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: drivers/md/md.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/e0bdaed154e5b9cc4310ddaf5da290483d00e6ba https://git.kernel.org/stable/c/c5e4cdd4438787e008c1b4a23bb66e49f4b12417 https://git.kernel.org/stable/c/f192434601b9a1ef072b8ad631d6008fea578234 https://git.kernel.org/stable/c/7f82027b6b74553f7fe8541c0a04bfbd3557fb11 https://git.kernel.org/stable/c/e151db8ecfb019b7da31d076130a794574c89f6f