mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [[PATCH] MTD: fix slab-use-after-free due to dangling pointer in notifier chain]  MTD: fix slab-use-after-free due to dangling pointer in notifier chain
@ 2024-12-08  8:44 Dennis Lam
  2024-12-08 17:21 ` Dennis Lam
  0 siblings, 1 reply; 2+ messages in thread
From: Dennis Lam @ 2024-12-08  8:44 UTC (permalink / raw)
  To: richard, chengzhihao1, miquel.raynal, vigneshr
  Cc: syzkaller-bugs, syzbot+0988a383ae7c57b99dd9, linux-kernel,
	linux-mtd, Dennis Lam

When attaching MTDs, a reboot notifier is added to the blocking
notification chain. However, when detaching a MTD and freeing its
related objects, the notifier is never unregistered from the
notification chain. Thus, when the chain is iterated there is a
possibility of finding the address of the reboot notifier which has
already been freed, resulting in a slab-use-after-free error.

To fix this, I added an unregister notifier function in the ubi_wl_close
function to ensure that the notifier is removed from the chain after the
device has been detached.

Reported-by: syzbot+0988a383ae7c57b99dd9@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/67409091.050a0220.363a1b.013d.GAE@google.com/T/
Signed-off-by: Dennis Lam <dennis.lamerice@gmail.com>
---
 drivers/mtd/ubi/wl.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 4f6f339d8fb8..31a1e5515d98 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1995,6 +1995,7 @@ static void protection_queue_destroy(struct ubi_device *ubi)
 void ubi_wl_close(struct ubi_device *ubi)
 {
 	dbg_wl("close the WL sub-system");
+	unregister_reboot_notifier(&ubi->wl_reboot_notifier);
 	ubi_fastmap_close(ubi);
 	shutdown_work(ubi);
 	protection_queue_destroy(ubi);
-- 
2.47.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [[PATCH] MTD: fix slab-use-after-free due to dangling pointer in notifier chain] MTD: fix slab-use-after-free due to dangling pointer in notifier chain
  2024-12-08  8:44 [[PATCH] MTD: fix slab-use-after-free due to dangling pointer in notifier chain] MTD: fix slab-use-after-free due to dangling pointer in notifier chain Dennis Lam
@ 2024-12-08 17:21 ` Dennis Lam
  0 siblings, 0 replies; 2+ messages in thread
From: Dennis Lam @ 2024-12-08 17:21 UTC (permalink / raw)
  To: richard, chengzhihao1, miquel.raynal, vigneshr
  Cc: syzkaller-bugs, syzbot+0988a383ae7c57b99dd9, linux-kernel, linux-mtd

On Sun, Dec 8, 2024 at 3:51 AM Dennis Lam <dennis.lamerice@gmail.com> wrote:
>
> When attaching MTDs, a reboot notifier is added to the blocking
> notification chain. However, when detaching a MTD and freeing its
> related objects, the notifier is never unregistered from the
> notification chain. Thus, when the chain is iterated there is a
> possibility of finding the address of the reboot notifier which has
> already been freed, resulting in a slab-use-after-free error.
>
> To fix this, I added an unregister notifier function in the ubi_wl_close
> function to ensure that the notifier is removed from the chain after the
> device has been detached.
>
> Reported-by: syzbot+0988a383ae7c57b99dd9@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/67409091.050a0220.363a1b.013d.GAE@google.com/T/
> Signed-off-by: Dennis Lam <dennis.lamerice@gmail.com>
> ---
>  drivers/mtd/ubi/wl.c | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> index 4f6f339d8fb8..31a1e5515d98 100644
> --- a/drivers/mtd/ubi/wl.c
> +++ b/drivers/mtd/ubi/wl.c
> @@ -1995,6 +1995,7 @@ static void protection_queue_destroy(struct ubi_device *ubi)
>  void ubi_wl_close(struct ubi_device *ubi)
>  {
>         dbg_wl("close the WL sub-system");
> +       unregister_reboot_notifier(&ubi->wl_reboot_notifier);
>         ubi_fastmap_close(ubi);
>         shutdown_work(ubi);
>         protection_queue_destroy(ubi);
> --
> 2.47.0
>

My apologies everyone, please ignore this email. My mailing script
seems to have changed my email header and commit message. I will send
another better formatted email later.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-08 17:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-08  8:44 [[PATCH] MTD: fix slab-use-after-free due to dangling pointer in notifier chain] MTD: fix slab-use-after-free due to dangling pointer in notifier chain Dennis Lam
2024-12-08 17:21 ` Dennis Lam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®