From: Vansh Choudhary <ch@vnsh.in>
To: linux-erofs@lists.ozlabs.org
Cc: Vansh Choudhary <ch@vnsh.in>
Subject: [PATCH] erofs-utils: mkfs: bound-check s3 passwd_file credentials
Date: Sat, 21 Mar 2026 18:02:39 +0000 [thread overview]
Message-ID: <20260321180239.36249-1-ch@vnsh.in> (raw)
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@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
next reply other threads:[~2026-03-21 18:02 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-21 18:02 Vansh Choudhary [this message]
2026-03-22 3:48 ` [PATCH] erofs-utils: mkfs: bound-check s3 passwd_file credentials Ajay Rajera
2026-03-23 1:56 ` zhaoyifan (H)
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=20260321180239.36249-1-ch@vnsh.in \
--to=ch@vnsh.in \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox