diff options
author | Nicolas Lacasse <nlacasse@google.com> | 2021-02-24 15:37:46 -0800 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-02-24 15:39:32 -0800 |
commit | f5692f7dcc48a76a5d7b45cdf71b59be876adb42 (patch) | |
tree | b16a82bfc49ccc24b58397e3fabfee824eda92a8 /test/syscalls/linux/rename.cc | |
parent | 303c913c5e0e6f0bac766970d9ed19c08aabb980 (diff) |
Kernfs should not try to rename a file to itself.
One precondition of VFS.PrepareRenameAt is that the `from` and `to` dentries
are not the same. Kernfs was not checking this, which could lead to a deadlock.
PiperOrigin-RevId: 359385974
Diffstat (limited to 'test/syscalls/linux/rename.cc')
-rw-r--r-- | test/syscalls/linux/rename.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/test/syscalls/linux/rename.cc b/test/syscalls/linux/rename.cc index 22c8c19cf..b1a813de0 100644 --- a/test/syscalls/linux/rename.cc +++ b/test/syscalls/linux/rename.cc @@ -424,6 +424,20 @@ TEST(RenameTest, SysfsPathEndingWithDots) { SyscallFailsWithErrno(EBUSY)); } +TEST(RenameTest, SysfsFileToSelf) { + // If a non-root user tries to rename inside /sys then we get EPERM. + SKIP_IF(geteuid() != 0); + std::string const path = "/sys/devices/system/cpu/online"; + EXPECT_THAT(rename(path.c_str(), path.c_str()), SyscallSucceeds()); +} + +TEST(RenameTest, SysfsDirectoryToSelf) { + // If a non-root user tries to rename inside /sys then we get EPERM. + SKIP_IF(geteuid() != 0); + std::string const path = "/sys/devices"; + EXPECT_THAT(rename(path.c_str(), path.c_str()), SyscallSucceeds()); +} + } // namespace } // namespace testing |