Skip to contentSkip to conversation

erofs: fix use-after-free on sbi->sync_decompress

PATCH In review Gao Xiang 3 participants 3 messages May 22 EROFS file system

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/1 erofs: fix use-after-free on sbi->sync_decompress

z_erofs_decompress_kickoff() can race with filesystem unmount, causing a use-after-free on sbi->sync_decompress.

When I/O completes, z_erofs_endio() calls z_erofs_decompress_kickoff() to queue z_erofs_decompressqueue_work() asynchronously. Then, after all folios are unlocked, unmount workflow can proceed and sbi will be freed before accessing to sbi->sync_decompress.

Thread (unmount) I/O completion kworker
queue_work
z_erofs_decompressqueue_work
(all folios are unlocked)
cleanup_mnt
..
erofs_kill_sb
erofs_sb_free
kfree(sbi)

                        access sbi->sync_decompress  // UAF!!
Fixes 40452ffca3c1 ("erofs: add sysfs node to control sync decompression strategy")
Reported-by [email protected]
---
 fs/erofs/zdata.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/erofs/zdata.c +3 -3
index 27ab7bd844ec..c6240dccbb0f 100644
@@ -1455,6 +1455,9 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
 	if (atomic_add_return(bios, &io->pending_bios))
 		return;
 	if (z_erofs_in_atomic()) {
+		/* See `sync_decompress` in sysfs-fs-erofs for more details */
+		if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
+			sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
 #ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
 		struct kthread_worker *worker;
 
@@ -1471,9 +1474,6 @@ static void z_erofs_decompress_kickoff(struct z_erofs_decompressqueue *io,
 #else
 		queue_work(z_erofs_workqueue, &io->u.work);
 #endif
-		/* See `sync_decompress` in sysfs-fs-erofs for more details */
-		if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
-			sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_ON;
 		return;
 	}
 	gfp_flag = memalloc_noio_save();
Signature · 1 line
2.43.5
Reviewed-by on v1 1/1
#1 lore raw

Thanks,
Jianan

Quoted 63 lines · 在 2026年5月22日星期五,Gao Xiang <[email protected]> 写道:

z_erofs_decompress_kickoff() can race with filesystem unmount, causing a use-after-free on sbi->sync_decompress.

When I/O completes, z_erofs_endio() calls z_erofs_decompress_kickoff() to queue z_erofs_decompressqueue_work() asynchronously. Then, after all folios are unlocked, unmount workflow can proceed and sbi will be freed before accessing to sbi->sync_decompress.

Thread (unmount) I/O completion kworker
queue_work
z_erofs_decompressqueue_work
(all folios are unlocked)
cleanup_mnt
..
erofs_kill_sb
erofs_sb_free
kfree(sbi)

                        access sbi->sync_decompress  // UAF!!
Fixes 40452ffca3c1 ("erofs: add sysfs node to control sync decompression

strategy")

---
 fs/erofs/zdata.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/erofs/zdata.c +1 -0
index 27ab7bd844ec..c6240dccbb0f 100644
@@ -1455,6 +1455,9 @@ static void z_erofs_decompress_kickoff(struct
 z_erofs_decompressqueue *io,
        if (atomic_add_return(bios, &io->pending_bios))
                return;
        if (z_erofs_in_atomic()) {
+               /* See `sync_decompress` in sysfs-fs-erofs for more

details */

fs/erofs/zdata.c +2 -0
+               if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
+                       sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_

ON;

 #ifdef CONFIG_EROFS_FS_PCPU_KTHREAD
                struct kthread_worker *worker;
fs/erofs/zdata.c +0 -1
@@ -1471,9 +1474,6 @@ static void z_erofs_decompress_kickoff(struct
 z_erofs_decompressqueue *io,
 #else
                queue_work(z_erofs_workqueue, &io->u.work);
 #endif
-               /* See `sync_decompress` in sysfs-fs-erofs for more

details */

fs/erofs/zdata.c +0 -2
-               if (sbi->sync_decompress == EROFS_SYNC_DECOMPRESS_AUTO)
-                       sbi->sync_decompress = EROFS_SYNC_DECOMPRESS_FORCE_
ON;
                return;
        }
        gfp_flag = memalloc_noio_save();

--
2.43.5

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Gao Xiang
Quoted 16 lines · Gao Xiang

z_erofs_decompress_kickoff() can race with filesystem unmount, causing a use-after-free on sbi->sync_decompress.

When I/O completes, z_erofs_endio() calls z_erofs_decompress_kickoff() to queue z_erofs_decompressqueue_work() asynchronously. Then, after all folios are unlocked, unmount workflow can proceed and sbi will be freed before accessing to sbi->sync_decompress.

Thread (unmount) I/O completion kworker
queue_work
z_erofs_decompressqueue_work
(all folios are unlocked)
cleanup_mnt
..
erofs_kill_sb
erofs_sb_free

Quoted 7 lines
    kfree(sbi)
                         access sbi->sync_decompress  // UAF!!
Fixes 40452ffca3c1 ("erofs: add sysfs node to control sync decompression strategy")
Reported-by [email protected]

Thanks,