REDHAT-BUG-2562680: Use After Free
In the Linux kernel, the following vulnerability has been resolved:
scsi: st: Fix use-after-free race between stremove() and stopen()
stremove() drops the probe reference on the scsitape with krefput() and only afterwards removes its index from stindexidr. If that was the last reference, scsitaperelease() frees the structure while it is still published in the idr.
scsitapeget(), called from stopen(), looks up the tape in stindexidr and takes a reference under strefmutex and stindexlock. removecdevs() does not wait for opens that are already past chrdevopen(), so an open that is blocked on strefmutex while stremove() holds it can take the mutex as soon as stremove() drops it, find the freed tpnt in the idr and call krefget() on it:
BUG: KASAN: slab-use-after-free in stopen Write of size 4 ... stopen (drivers/scsi/st.c:254 drivers/scsi/st.c:1291) chrdevopen ... Freed by task ...: kfree stremove (drivers/scsi/st.c:4512)
Remove the index from the idr before dropping the reference, all under strefmutex. A concurrent scsitapeget() now either runs first and holds a valid reference that keeps the tape alive, or runs afterwards and finds nothing, so stopen() fails with -ENXIO.
This restores the ordering stremove() had before the conversion to stindexidr, where the tape was unpublished from scsitapes[] before the final krefput().
Affected Software
Event History
Frequently Asked Questions
When can this race be triggered?
The race requires a concurrent tape-device removal and an attempt to open the corresponding SCSI tape character device. The open must have progressed past chrdev_open() and contend on st_ref_mutex while st_remove() is running.
What is the likely impact of a successful race?
A concurrent open can retrieve a freed scsi_tape structure from the index and perform kref_get() on it, causing a slab use-after-free. The reported manifestation is a KASAN use-after-free in st_open().
How can systems determine whether they are exposed to this condition?
Systems using the Linux kernel SCSI tape driver and performing tape-device removal while the device may be opened concurrently are relevant to this race. Evidence may include KASAN reports identifying a slab-use-after-free in st_open(), with st_remove() shown as freeing the object.
What does the available fix change?
The fix removes the tape index from st_index_idr before dropping the final reference, while holding st_ref_mutex. This makes a concurrent open either obtain a valid reference before removal or find no indexed tape after removal.