mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] zram: fix NULL pointer dereference in zcomp_available_show()
@ 2025-08-03  6:25 Seyediman Seyedarab
  2025-08-05  9:08 ` Sergey Senozhatsky
  2025-08-05 10:22 ` Sergey Senozhatsky
  0 siblings, 2 replies; 8+ messages in thread
From: Seyediman Seyedarab @ 2025-08-03  6:25 UTC (permalink / raw)
  To: minchan, senozhatsky, axboe
  Cc: linux-kernel, linux-block, Seyediman Seyedarab,
	syzbot+1a281a451fd8c0945d07

During zram_reset_device(), comp_algs[prio] is set to NULL by
zram_destroy_comps() before being reinitialized to the default algorithm.
A concurrent sysfs read can occur between these operations, passing NULL
to strcmp() and causing a crash.

Additionally, there's a use-after-free race where zram_remove() frees the
zram structure while concurrent sysfs operations may still be accessing
it. This is because del_gendisk() doesn't wait for active sysfs operations
to complete - it only removes the files from the filesystem but doesn't
drain active references.

Temporarily add a NULL check in zcomp_available_show() to prevent the
crash. The use-after-free issue requires a more comprehensive fix using
proper reference counting to ensure the zram structure isn't freed while
still in use.

Fixes: e46b8a030d76 ("zram: make compression algorithm selection possible")
Reported-by: syzbot+1a281a451fd8c0945d07@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=1a281a451fd8c0945d07
Signed-off-by: Seyediman Seyedarab <ImanDevel@gmail.com>
---
 drivers/block/zram/zcomp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index b1bd1daa0060..98a2a3199ba2 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -95,7 +95,7 @@ ssize_t zcomp_available_show(const char *comp, char *buf, ssize_t at)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(backends) - 1; i++) {
-		if (!strcmp(comp, backends[i]->name)) {
+		if (comp && !strcmp(comp, backends[i]->name)) {
 			at += sysfs_emit_at(buf, at, "[%s] ",
 					    backends[i]->name);
 		} else {
-- 
2.50.1


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

end of thread, other threads:[~2025-08-06  3:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-03  6:25 [PATCH] zram: fix NULL pointer dereference in zcomp_available_show() Seyediman Seyedarab
2025-08-05  9:08 ` Sergey Senozhatsky
2025-08-05 10:22 ` Sergey Senozhatsky
2025-08-05 13:38   ` Seyediman Seyedarab
2025-08-05 14:43     ` Seyediman Seyedarab
2025-08-05 22:03       ` Seyediman Seyedarab
2025-08-06  2:59         ` Sergey Senozhatsky
2025-08-06  3:04       ` Sergey Senozhatsky

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®