All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yifan Zhao <stopire@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: Yifan Zhao <stopire@gmail.com>
Subject: [PATCH 2/8] erofs-utils: mkfs: fix incremental superblock stack overread
Date: Thu, 12 Nov 2026 20:47:19 +0800	[thread overview]
Message-ID: <20261112124725.2774244-3-stopire@gmail.com> (raw)
In-Reply-To: <20261112124725.2774244-1-stopire@gmail.com>

Running mkfs.erofs --incremental on a base image with sb_extslots > 1
retains a superblock size larger than the 144-byte stack object in
erofs_writesb(). The final memcpy() reads past that object and writes
adjacent stack contents into the image.

Trigger path:
  main()
    erofs_mkfs_load_fs()
      erofs_read_superblock()  /* sb_size = 128 + sb_extslots * 16 */
    erofs_writesb()
      memcpy(..., &sb, sbi->sb_size)

Let's limit the source image sb size in incremental builds.

Fixes: c6903c7e32a1 ("erofs-utils: dump,fsck,fuse: support metadata compression")
Assisted-by: Codex:gpt-6-astra
Assisted-by: Claude Code:deepseek-v4.1-flash-1017
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
 lib/super.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/super.c b/lib/super.c
index 5cb9016..694a3e9 100644
--- a/lib/super.c
+++ b/lib/super.c
@@ -515,6 +515,12 @@ int erofs_mkfs_load_fs(struct erofs_sb_info *sbi, unsigned int dsunit)
 		return err;
 	}
 
+	if (sbi->sb_size > sizeof(struct erofs_super_block)) {
+		erofs_err("unsupported superblock size %u for incremental builds",
+			  sbi->sb_size);
+		return -EOPNOTSUPP;
+	}
+
 	err = erofs_io_fstat(&sbi->bdev, &u.st);
 	if (!err && S_ISREG(u.st.st_mode))
 		u.startblk = DIV_ROUND_UP(u.st.st_size, erofs_blksiz(sbi));
-- 
2.56.0



  parent reply	other threads:[~2026-11-12 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 12:47 [PATCH 0/8] erofs-utils: fix issues found by LLMs Yifan Zhao
2026-11-12 12:47 ` [PATCH 1/8] erofs-utils: lib: fix arithmetic overflow in large file handling Yifan Zhao
2026-11-12 12:47 ` Yifan Zhao [this message]
2026-11-12 12:47 ` [PATCH 3/8] erofs-utils: tar: fix out-of-bounds access when trimming PAX paths Yifan Zhao
2026-11-12 12:47 ` [PATCH 4/8] erofs-utils: lib: fix buffer leaks in error paths Yifan Zhao
2026-11-12 23:20   ` Gao Xiang
2026-11-12 12:47 ` [PATCH 5/8] erofs-utils: exclude: fix stack overflow when checking long paths Yifan Zhao
2026-11-12 12:47 ` [PATCH 6/8] erofs-utils: lib: fix gzran EOF handling and state leaks Yifan Zhao
2026-11-12 12:47 ` [PATCH 7/8] erofs-utils: lib: fix metabox inline data reads Yifan Zhao
2026-11-12 12:47 ` [PATCH 8/8] erofs-utils: fix read error and short read handling Yifan Zhao
2026-11-12 23:41   ` Gao Xiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112124725.2774244-3-stopire@gmail.com \
    --to=stopire@gmail.com \
    --cc=linux-erofs@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.