public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] adfs: validate nzones in adfs_read_map()
@ 2026-03-20 14:23 Greg Kroah-Hartman
  2026-03-20 14:37 ` Russell King (Oracle)
  0 siblings, 1 reply; 12+ messages in thread
From: Greg Kroah-Hartman @ 2026-03-20 14:23 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: linux-kernel, Bae Yeonju, stable, Kees Cook, Russell King,
	Al Viro, Greg Kroah-Hartman

From: Bae Yeonju <iwasbaeyz@gmail.com>

adfs_read_map() reads the zone count from the on-disk disc record
without validation:

  nzones = dr->nzones | dr->nzones_high << 8;

When nzones is 0, the subsequent kmalloc_array(0, ...) returns
ZERO_SIZE_PTR (0x10), and adfs_map_layout() writes to dm[-1],
causing an out-of-bounds write before the allocated buffer.

This can be triggered by mounting a crafted ADFS filesystem image
with nzones set to 0 in the disc record. It leads to kernel heap
corruption and a NULL pointer dereference during mount.

Add a check to reject disc records with nzones == 0 before the
allocation.

Found by syzkaller.

Fixes: f6f14a0d71b0 ("fs/adfs: map: move map-specific sb initialisation to map.c")
Cc: stable <stable@kernel.org>
Cc: Kees Cook <kees@kernel.org>
Cc: Bae Yeonju <iwasbaeyz@gmail.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Bae Yeonju <iwasbaeyz@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 fs/adfs/map.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/adfs/map.c b/fs/adfs/map.c
index 9d535a2ca2d1..5d671e7b4663 100644
--- a/fs/adfs/map.c
+++ b/fs/adfs/map.c
@@ -361,6 +361,10 @@ struct adfs_discmap *adfs_read_map(struct super_block *sb, struct adfs_discrecor
 	int ret;
 
 	nzones    = dr->nzones | dr->nzones_high << 8;
+	if (nzones == 0) {
+		adfs_error(sb, "invalid zone count");
+		return ERR_PTR(-EINVAL);
+	}
 	zone_size = (8 << dr->log2secsize) - le16_to_cpu(dr->zone_spare);
 
 	asb->s_idlen = dr->idlen;
-- 
2.53.0


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

end of thread, other threads:[~2026-03-21  4:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 14:23 [PATCH] adfs: validate nzones in adfs_read_map() Greg Kroah-Hartman
2026-03-20 14:37 ` Russell King (Oracle)
2026-03-20 15:05   ` Greg Kroah-Hartman
2026-03-20 15:21     ` paeyz
2026-03-20 15:40       ` Greg KH
2026-03-20 15:52         ` [PATCH v2] adfs: validate nzones in adfs_validate_bblk() paeyz
2026-03-20 16:04           ` Greg KH
2026-03-20 16:08             ` Russell King (Oracle)
2026-03-20 16:11               ` Greg KH
2026-03-21  4:45                 ` [PATCH v3] " paeyz
2026-03-20 16:05         ` [PATCH] adfs: validate nzones in adfs_read_map() Russell King (Oracle)
2026-03-20 16:02     ` Russell King (Oracle)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox