erofs-utils: fsck: keep S{U,G}ID bits properly on extraction
authorGao Xiang <hsiangkao@linux.alibaba.com>
Fri, 24 Jan 2025 09:06:27 +0000 (17:06 +0800)
committerGao Xiang <hsiangkao@linux.alibaba.com>
Thu, 6 Feb 2025 05:01:10 +0000 (13:01 +0800)
commit7e24aafef050be8703281d0240751eb575854a1a
tree6fca28d1b5ef228a6104c94ca970a2f1073edfc8
parentefbc1b1f85757d92284fb4259646160967fb6c5d
erofs-utils: fsck: keep S{U,G}ID bits properly on extraction

As chown(2) explained, "
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 <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20250124090628.2865088-1-hsiangkao@linux.alibaba.com
fsck/main.c