public inbox for linux-erofs@ozlabs.org
 help / color / mirror / Atom feed
From: Utkal Singh <singhutkal015@gmail.com>
To: hsiangkao@linux.alibaba.com
Cc: linux-erofs@lists.ozlabs.org, Utkal Singh <singhutkal015@gmail.com>
Subject: [PATCH] erofs-utils: lib/tar: reject negative uid=/gid= values in PAX header
Date: Mon, 16 Mar 2026 08:12:43 +0000	[thread overview]
Message-ID: <20260316081243.40931-1-singhutkal015@gmail.com> (raw)

uid= and gid= values are parsed into a long long and then assigned
to st_uid/st_gid which are unsigned types. A negative PAX value
would silently wrap to a huge number, corrupting inode ownership.

Add the same negative-value guard already present for size= to
both uid= and gid= fields.

Signed-off-by: Utkal Singh <singhutkal015@gmail.com>
---
 lib/tar.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/lib/tar.c b/lib/tar.c
index 6fa2cda..13e777a 100644
--- a/lib/tar.c
+++ b/lib/tar.c
@@ -559,6 +559,11 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
 					ret = -EIO;
 					goto out;
 				}
+				if (lln < 0) {
+					erofs_err("invalid negative uid= in PAX header");
+					ret = -EINVAL;
+					goto out;
+				}
 				eh->st.st_uid = lln;
 				eh->use_uid = true;
 			} else if (!strncmp(kv, "gid=", sizeof("gid=") - 1)) {
@@ -567,6 +572,11 @@ int tarerofs_parse_pax_header(struct erofs_iostream *ios,
 					ret = -EIO;
 					goto out;
 				}
+				if (lln < 0) {
+					erofs_err("invalid negative gid= in PAX header");
+					ret = -EINVAL;
+					goto out;
+				}
 				eh->st.st_gid = lln;
 				eh->use_gid = true;
 			} else if (!strncmp(kv, "SCHILY.xattr.",
-- 
2.43.0



                 reply	other threads:[~2026-03-16  8:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260316081243.40931-1-singhutkal015@gmail.com \
    --to=singhutkal015@gmail.com \
    --cc=hsiangkao@linux.alibaba.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox