Skip to content

Commit 16050e0

Browse files
authored
Merge pull request #57 from chenhunghan/fix-chown-eperm
Treat chown EPERM as no-op success for emulated-root guests
2 parents 75fb59b + 8a1eec4 commit 16050e0

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/syscall/fs.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,14 @@ int64_t sys_fchmodat(guest_t *g,
16931693
return 0;
16941694
}
16951695

1696+
/* Fake success on EPERM: emulated-root guests expect chown to succeed. */
1697+
static int64_t chown_result(int rc)
1698+
{
1699+
if (rc < 0)
1700+
return (errno == EPERM) ? 0 : linux_errno();
1701+
return 0;
1702+
}
1703+
16961704
int64_t sys_fchownat(guest_t *g,
16971705
int dirfd,
16981706
uint64_t path_gva,
@@ -1719,13 +1727,10 @@ int64_t sys_fchownat(guest_t *g,
17191727
return -LINUX_EBADF;
17201728

17211729
int mac_flags = translate_at_flags(flags);
1722-
if (fchownat(dir_ref.fd, tx.host_path, owner, group, mac_flags) < 0) {
1723-
host_fd_ref_close(&dir_ref);
1724-
return linux_errno();
1725-
}
1726-
1730+
int64_t out = chown_result(
1731+
fchownat(dir_ref.fd, tx.host_path, owner, group, mac_flags));
17271732
host_fd_ref_close(&dir_ref);
1728-
return 0;
1733+
return out;
17291734
}
17301735

17311736
int64_t sys_fchown(int fd, uint32_t owner, uint32_t group)
@@ -1737,12 +1742,9 @@ int64_t sys_fchown(int fd, uint32_t owner, uint32_t group)
17371742
host_fd_ref_t host_ref;
17381743
if (host_fd_ref_open(fd, &host_ref) < 0)
17391744
return -LINUX_EBADF;
1740-
if (fchown(host_ref.fd, owner, group) < 0) {
1741-
host_fd_ref_close(&host_ref);
1742-
return linux_errno();
1743-
}
1745+
int64_t out = chown_result(fchown(host_ref.fd, owner, group));
17441746
host_fd_ref_close(&host_ref);
1745-
return 0;
1747+
return out;
17461748
}
17471749

17481750
int64_t sys_utimensat(guest_t *g,

0 commit comments

Comments
 (0)