Skip to contentSkip to conversation

erofs-utils: fsck: keep S{U,G}ID bits properly on extraction

PATCH New Gao Xiang 1 participant 2 messages Jan 24, 2025

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: fsck: keep S{U,G}ID bits properly on extraction

As chown(2) shown, "
When the owner or group of an executable file are changed by an unprivileged user the S_ISUID and S_ISGID mode bits are cleared. POSIX does not specify whether this also should happen when root does the chown(); the Linux behavior depends on the kernel version."

Fix it by chown() first.

Fixes 412c8f908132 ("erofs-utils: fsck: add --extract=X support to extract to path X")
---
 fsck/main.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
fsck/main.c +6 -6
index d375835..b1d6214 100644
@@ -300,6 +300,12 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path)
 #endif
 		erofs_warn("failed to set times: %s", path);
 
+	if (fsckcfg.preserve_owner) {
+		ret = lchown(path, inode->i_uid, inode->i_gid);
+		if (ret < 0)
+			erofs_warn("failed to change ownership: %s", path);
+	}
+
 	if (!S_ISLNK(inode->i_mode)) {
 		if (fsckcfg.preserve_perms)
 			ret = chmod(path, inode->i_mode);
@@ -308,12 +314,6 @@ static void erofsfsck_set_attributes(struct erofs_inode *inode, char *path)
 		if (ret < 0)
 			erofs_warn("failed to set permissions: %s", path);
 	}
-
-	if (fsckcfg.preserve_owner) {
-		ret = lchown(path, inode->i_uid, inode->i_gid);
-		if (ret < 0)
-			erofs_warn("failed to change ownership: %s", path);
-	}
 }
 
 static int erofs_check_sb_chksum(void)
Signature · 1 line
2.43.5
author
#1 lore raw

PATCH 2/2 erofs-utils: fsck: don't dump packed inode data if unneeded

It was a vain attempt.

---
 fsck/main.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
fsck/main.c +3 -4
index b1d6214..372fee6 100644
@@ -518,6 +518,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 	struct erofs_map_blocks map = {
 		.index = UINT_MAX,
 	};
+	bool needdecode = fsckcfg.check_decomp && !erofs_is_packed_inode(inode);
 	int ret = 0;
 	bool compressed;
 	erofs_off_t pos = 0;
@@ -552,7 +553,7 @@ static int erofs_verify_inode_data(struct erofs_inode *inode, int outfd)
 		pos += map.m_llen;
 
 		/* should skip decomp? */
-		if (map.m_la >= inode->i_size || !fsckcfg.check_decomp)
+		if (map.m_la >= inode->i_size || !needdecode)
 			continue;
 
 		if (outfd >= 0 && !(map.m_flags & EROFS_MAP_MAPPED)) {
@@ -918,7 +919,7 @@ static int erofsfsck_extract_inode(struct erofs_inode *inode)
 	int ret;
 	char *oldpath;
 
-	if (!fsckcfg.extract_path) {
+	if (!fsckcfg.extract_path || erofs_is_packed_inode(inode)) {
 verify:
 		/* verify data chunk layout */
 		return erofs_verify_inode_data(inode, -1);
@@ -939,8 +940,6 @@ verify:
 		ret = erofs_extract_dir(inode);
 		break;
 	case S_IFREG:
-		if (erofs_is_packed_inode(inode))
-			goto verify;
 		ret = erofs_extract_file(inode);
 		break;
 	case S_IFLNK:
Signature · 1 line
2.43.5