瀏覽代碼

Kernel: Stricter path checking in validate_path_against_process_veil

This change enforces that paths passed to
VFS::validate_path_against_process_veil are absolute and do not contain
any '..' or '.' parts. We should VERIFY here instead of returning EINVAL
since the code that calls this should resolve non-canonical paths before
calling this function.
Max Wipfli 4 年之前
父節點
當前提交
502436f9fc
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      Kernel/FileSystem/VirtualFileSystem.cpp

+ 3 - 3
Kernel/FileSystem/VirtualFileSystem.cpp

@@ -852,9 +852,9 @@ KResult VFS::validate_path_against_process_veil(StringView path, int options)
     if (path == "/usr/lib/Loader.so")
     if (path == "/usr/lib/Loader.so")
         return KSuccess;
         return KSuccess;
 
 
-    // FIXME: Figure out a nicer way to do this.
-    if (String(path).contains("/.."))
-        return EINVAL;
+    VERIFY(path.starts_with('/'));
+    VERIFY(!path.contains("/../"sv) && !path.ends_with("/.."sv));
+    VERIFY(!path.contains("/./"sv) && !path.ends_with("/."sv));
 
 
     auto& unveiled_path = find_matching_unveiled_path(path);
     auto& unveiled_path = find_matching_unveiled_path(path);
     if (unveiled_path.permissions() == UnveilAccess::None) {
     if (unveiled_path.permissions() == UnveilAccess::None) {