From 475a17fa4bdd74c428bdac785bbc69881dfcd115 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Apr 2019 23:34:33 +0200 Subject: [PATCH] VFS: Also respect the sticky bit of the new parent in rename(). Obviously we should not allow overwriting someone else's files in a sticky directory either. --- Kernel/FileSystem/VirtualFileSystem.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 0ec583f6e63..7b1087c9adf 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -336,6 +336,10 @@ KResult VFS::rename(StringView old_path, StringView new_path, Inode& base) // FIXME: Is this really correct? Check what other systems do. if (new_inode == old_inode) return KSuccess; + if (new_parent_inode->metadata().is_sticky()) { + if (!current->process().is_superuser() && new_inode->metadata().uid != current->process().euid()) + return KResult(-EACCES); + } if (new_inode->is_directory() && !old_inode->is_directory()) return KResult(-EISDIR); auto result = new_parent_inode->remove_child(FileSystemPath(new_path).basename());