[PATCH] erofs-utils: mkfs: bound-check s3 passwd_file credentials
Vansh Choudhary
ch at vnsh.in
Sun Mar 22 05:02:39 AEDT 2026
mkfs_parse_s3_cfg_passwd() only checked the total passwd_file size,
which left two issues in the parser:
- a file exactly as large as the temporary buffer left no room for the
trailing NUL byte;
- either credential could still exceed its destination buffer after the
string is split at ':'.
Use sizeof(buf) for the temporary buffer check and reject overlong
access key or secret key fields before copying them out.
This keeps the existing parsing flow intact while making the bounds
checks match the actual destination sizes.
Signed-off-by: Vansh Choudhary <ch at vnsh.in>
---
mkfs/main.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/mkfs/main.c b/mkfs/main.c
index 58c18f9..eb13aba 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -663,7 +663,7 @@ static int mkfs_parse_s3_cfg_passwd(const char *filepath, char *ak, char *sk)
erofs_warn("passwd_file %s should not be accessible by group or others",
filepath);
- if (st.st_size > S3_ACCESS_KEY_LEN + S3_SECRET_KEY_LEN + 3) {
+ if (st.st_size >= sizeof(buf)) {
erofs_err("passwd_file %s is too large (size: %llu)", filepath,
st.st_size | 0ULL);
ret = -EINVAL;
@@ -687,6 +687,12 @@ static int mkfs_parse_s3_cfg_passwd(const char *filepath, char *ak, char *sk)
}
*colon = '\0';
+ if (strlen(buf) > S3_ACCESS_KEY_LEN ||
+ strlen(colon + 1) > S3_SECRET_KEY_LEN) {
+ ret = -EINVAL;
+ goto err;
+ }
+
strcpy(ak, buf);
strcpy(sk, colon + 1);
--
2.43.0
More information about the Linux-erofs
mailing list