From f5692f7dcc48a76a5d7b45cdf71b59be876adb42 Mon Sep 17 00:00:00 2001 From: Nicolas Lacasse Date: Wed, 24 Feb 2021 15:37:46 -0800 Subject: 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 --- test/syscalls/linux/rename.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/syscalls/linux') 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 -- cgit v1.2.3