media: pvrusb2: fix use after free on context disconnection
authorRicardo B. Marliere <ricardo@marliere.net>
Thu, 12 Oct 2023 23:09:12 +0000 (01:09 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Thu, 23 Nov 2023 12:35:08 +0000 (13:35 +0100)
Upon module load, a kthread is created targeting the
pvr2_context_thread_func function, which may call pvr2_context_destroy
and thus call kfree() on the context object. However, that might happen
before the usb hub_event handler is able to notify the driver. This
patch adds a sanity check before the invalid read reported by syzbot,
within the context disconnection call stack.

Reported-and-tested-by: syzbot+621409285c4156a009b3@syzkaller.appspotmail.com
Closes: https://lore.kernel.org/all/000000000000a02a4205fff8eb92@google.com/
Fixes: e5be15c63804 ("V4L/DVB (7711): pvrusb2: Fix race on module unload")
Signed-off-by: Ricardo B. Marliere <ricardo@marliere.net>
Acked-by: Mike Isely <isely@pobox.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/usb/pvrusb2/pvrusb2-context.c

index 14170a5d72b350852632f946d88377ba374be1b4..1764674de98bc062faf5861681690aa19586e1ed 100644 (file)
@@ -268,7 +268,8 @@ void pvr2_context_disconnect(struct pvr2_context *mp)
 {
        pvr2_hdw_disconnect(mp->hdw);
        mp->disconnect_flag = !0;
-       pvr2_context_notify(mp);
+       if (!pvr2_context_shutok())
+               pvr2_context_notify(mp);
 }