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") Signed-off-by: Gao Xiang <hsiang...@linux.alibaba.com> --- fsck/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fsck/main.c b/fsck/main.c index d375835..b1d6214 100644 --- a/fsck/main.c +++ b/fsck/main.c @@ -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) -- 2.43.5