From e4eca1784876d244446c28f029d089fd93af1362 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 28 Apr 2019 22:54:30 +0200 Subject: [PATCH] VFS: Implement sticky bit behavior for rename() and unlink(). Removing entries from a sticky directory is only allowed when you are either the owner of the entry, or the superuser. :^) --- Kernel/FileSystem/VirtualFileSystem.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 04339efcbd..0ec583f6e6 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -326,6 +326,11 @@ KResult VFS::rename(StringView old_path, StringView new_path, Inode& base) if (!old_parent_inode->metadata().may_write(current->process())) return KResult(-EACCES); + if (old_parent_inode->metadata().is_sticky()) { + if (!current->process().is_superuser() && old_inode->metadata().uid != current->process().euid()) + return KResult(-EACCES); + } + if (!new_inode_or_error.is_error()) { auto new_inode = new_inode_or_error.value(); // FIXME: Is this really correct? Check what other systems do. @@ -436,6 +441,11 @@ KResult VFS::unlink(StringView path, Inode& base) if (!parent_inode->metadata().may_write(current->process())) return KResult(-EACCES); + if (parent_inode->metadata().is_sticky()) { + if (!current->process().is_superuser() && inode->metadata().uid != current->process().euid()) + return KResult(-EACCES); + } + return parent_inode->remove_child(FileSystemPath(path).basename()); }