CVE-2026-99039: memstick: core: wait for request completion before freeing card
In the Linux kernel, the following vulnerability has been resolved:
memstick: core: wait for request completion before freeing card
In memstickalloccard() and memsticksetrwaddr(), waitforcompletiontimeout() is used to wait for device identification and address configuration requests to complete.
The memstick subsystem does not provide an abort or cancellation callback in struct memstickhost for in-flight requests. If waitforcompletiontimeout() expires (for instance, when a USB transfer or command retry is delayed), memstickalloccard() returns an error and frees the memstickdev structure via kfree(card).
However, the host controller driver (such as rtsxusbms) is still running the request asynchronously in worker context. When the transfer eventually finishes, the driver writes into host->req->data, which points to memory inside the already freed card structure. This leads to a KASAN slab-use-after-free write:
BUG: KASAN: slab-use-after-free in msreadbytes+0x8fe/0x990 Write of size 1 at addr ffff88813c188079 by task kworker/1:5/5239 Workqueue: events rtsxusbmshandlereq Call Trace: msreadbytes+0x8fe/0x990 drivers/memstick/host/rtsxusbms.c:450 rtsxusbmsissuecmd drivers/memstick/host/rtsxusbms.c:477 [inline] rtsxusbmshandlereq+0x557/0x1a00 drivers/memstick/host/rtsxusbms.c:531 processonework+0xac7/0x1b10 kernel/workqueue.c:3396 workerthread+0x5ef/0xe50 kernel/workqueue.c:3560 kthread+0x373/0x450 kernel/kthread.c:436
Allocated by task 1662: memstickalloccard drivers/memstick/core/memstick.c:383 [inline] memstickcheck+0x2c1/0x10d0 drivers/memstick/core/memstick.c:452 processonework+0xac7/0x1b10 kernel/workqueue.c:3396
Freed by task 1662: kfree+0x20c/0x650 mm/slub.c:6792 memstickalloccard drivers/memstick/core/memstick.c:420 [inline] memstickcheck+0x72b/0x10d0 drivers/memstick/core/memstick.c:452 processonework+0xac7/0x1b10 kernel/workqueue.c:3396
Host controller drivers (rtsxusbms, jmb38xms, tifmms, r592) already implement their own hardware and bus timeouts, and callers in msproblock and msblock already rely on waitforcompletion() unconditionally.
Replace waitforcompletiontimeout() with waitforcompletion() in memsticksetrwaddr() and memstickalloccard() so that the card structure is never freed while an asynchronous request is in flight.