Skip to content

Truly independent web browser

LibSandbox: Stop naming the file system rules after Landlock

Andreas Kling6ca1aa423899
diff --git a/Libraries/LibSandbox/GpuDriverPaths.cpp b/Libraries/LibSandbox/GpuDriverPaths.cpp
index 9ea6ab9e11a..ccc9b5b5e38 100644
--- a/Libraries/LibSandbox/GpuDriverPaths.cpp
+++ b/Libraries/LibSandbox/GpuDriverPaths.cpp
@@ -20,7 +20,7 @@ namespace Sandbox {
// A driver or layer manifest names the library that the loader opens. A bare name is found by the dynamic loader in
// the library directories, which are already allowed. A path, which may be relative to the manifest, can be anywhere.
-static ErrorOr<void> add_manifest_library_paths(Vector<LandlockPath>& paths, StringView manifest_path)
+static ErrorOr<void> add_manifest_library_paths(Vector<PathRule>& paths, StringView manifest_path)
{
auto file = Core::File::open(manifest_path, Core::File::OpenMode::Read);
if (file.is_error())
@@ -35,7 +35,7 @@ static ErrorOr<void> add_manifest_library_paths(Vector<LandlockPath>& paths, Str
if (!library_path.has_value() || !library_path->contains('/'))
return {};
auto path = LexicalPath::absolute_path(LexicalPath::dirname(manifest_path), *library_path);
- return add_landlock_path_if_exists(paths, path, LandlockPath::Access::ReadOnly);
+ return add_path_if_exists(paths, path, PathRule::Access::ReadOnly);
};
auto const& object = manifest.value().as_object();
@@ -53,12 +53,12 @@ static ErrorOr<void> add_manifest_library_paths(Vector<LandlockPath>& paths, Str
}
// Allows a manifest, or every manifest in a directory, along with the libraries that they point to.
-static ErrorOr<void> add_manifest_paths(Vector<LandlockPath>& paths, StringView manifest_file_or_directory)
+static ErrorOr<void> add_manifest_paths(Vector<PathRule>& paths, StringView manifest_file_or_directory)
{
auto metadata = Core::System::stat(manifest_file_or_directory);
if (metadata.is_error())
return {};
- TRY(add_landlock_path_if_exists(paths, manifest_file_or_directory, LandlockPath::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, manifest_file_or_directory, PathRule::Access::ReadOnly));
if (!S_ISDIR(metadata.value().st_mode))
return add_manifest_library_paths(paths, manifest_file_or_directory);
@@ -73,7 +73,7 @@ static ErrorOr<void> add_manifest_paths(Vector<LandlockPath>& paths, StringView
// The Vulkan loader and glvnd find their drivers and layers through manifests, which they read while the GPU backend
// starts, after Landlock is in place. So we allow the directories that they search by default, and whatever the
// environment points them at instead.
-static ErrorOr<void> add_loader_manifest_paths(Vector<LandlockPath>& paths)
+static ErrorOr<void> add_loader_manifest_paths(Vector<PathRule>& paths)
{
auto home = Core::Environment::get("HOME"sv).value_or(""sv);
auto environment_or = [](StringView name, ByteString fallback) {
@@ -124,46 +124,46 @@ static ErrorOr<void> add_loader_manifest_paths(Vector<LandlockPath>& paths)
return {};
}
-ErrorOr<void> add_gpu_driver_landlock_paths(Vector<LandlockPath>& paths)
+ErrorOr<void> add_gpu_driver_paths(Vector<PathRule>& paths)
{
- TRY(add_landlock_path_if_exists(paths, "/lib"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/lib64"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/lib"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/local/lib"sv, LandlockPath::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/lib"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/lib64"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/lib"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/local/lib"sv, PathRule::Access::ReadOnly));
// The driver loads more libraries after Landlock is in place, and they must come from where the libraries that we
// already use came from. Otherwise the dynamic loader skips to another copy, such as the system's instead of our own.
TRY(add_loaded_library_directories(paths));
// cpptrace opens loaded ELF objects when symbolizing in-process stack traces, and drivers read it too.
- TRY(add_landlock_path_if_exists(paths, TRY(Core::System::current_executable_path()), LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/etc/glvnd"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/share/glvnd"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/share/drirc.d"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/share/libdrm"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/share/vulkan"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/dev/dri"sv, LandlockPath::Access::ReadWrite));
- TRY(add_landlock_path_if_exists(paths, "/dev/udmabuf"sv, LandlockPath::Access::ReadWrite));
- TRY(add_landlock_path_if_exists(paths, "/sys"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/etc/ld.so.cache"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/etc/egl"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/share/egl"sv, LandlockPath::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, TRY(Core::System::current_executable_path()), PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/etc/glvnd"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/share/glvnd"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/share/drirc.d"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/share/libdrm"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/share/vulkan"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/dev/dri"sv, PathRule::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/dev/udmabuf"sv, PathRule::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/sys"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/etc/ld.so.cache"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/etc/egl"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/share/egl"sv, PathRule::Access::ReadOnly));
TRY(add_loader_manifest_paths(paths));
// NB: GPU drivers read these while they set up and while they run. They used to do the setup before Landlock was in
// place, and in threads that it never confined.
- TRY(add_landlock_path_if_exists(paths, "/proc/self"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/proc/meminfo"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/proc/stat"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/proc/filesystems"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/proc/sys/dev"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/proc/driver/nvidia"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/etc/nvidia"sv, LandlockPath::Access::ReadOnly));
- TRY(add_landlock_path_if_exists(paths, "/usr/share/nvidia"sv, LandlockPath::Access::ReadOnly));
-
- TRY(add_landlock_path_if_exists(paths, "/dev/nvidiactl"sv, LandlockPath::Access::ReadWrite));
- TRY(add_landlock_path_if_exists(paths, "/dev/nvidia-modeset"sv, LandlockPath::Access::ReadWrite));
- TRY(add_landlock_path_if_exists(paths, "/dev/nvidia-uvm"sv, LandlockPath::Access::ReadWrite));
- TRY(add_landlock_path_if_exists(paths, "/dev/nvidia-uvm-tools"sv, LandlockPath::Access::ReadWrite));
- TRY(add_landlock_path_if_exists(paths, "/dev/nvidia-caps"sv, LandlockPath::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/proc/self"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/proc/meminfo"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/proc/stat"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/proc/filesystems"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/proc/sys/dev"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/proc/driver/nvidia"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/etc/nvidia"sv, PathRule::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, "/usr/share/nvidia"sv, PathRule::Access::ReadOnly));
+
+ TRY(add_path_if_exists(paths, "/dev/nvidiactl"sv, PathRule::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/dev/nvidia-modeset"sv, PathRule::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/dev/nvidia-uvm"sv, PathRule::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/dev/nvidia-uvm-tools"sv, PathRule::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, "/dev/nvidia-caps"sv, PathRule::Access::ReadWrite));
// NB: Add all of the primary nvidia device files (e.g. /dev/nvidia0, /dev/nvidia1, etc).
auto flags = static_cast<Core::DirIterator::Flags>(Core::DirIterator::SkipDots | Core::DirIterator::NoStat);
@@ -171,7 +171,7 @@ ErrorOr<void> add_gpu_driver_landlock_paths(Vector<LandlockPath>& paths)
if (entry.name.starts_with("nvidia"sv)) {
auto suffix = entry.name.substring_view(6);
if (!suffix.is_empty() && all_of(suffix, is_ascii_digit))
- TRY(add_landlock_path_if_exists(paths, TRY(String::formatted("/dev/{}", entry.name)), LandlockPath::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, TRY(String::formatted("/dev/{}", entry.name)), PathRule::Access::ReadWrite));
}
return IterationDecision::Continue;
@@ -181,7 +181,7 @@ ErrorOr<void> add_gpu_driver_landlock_paths(Vector<LandlockPath>& paths)
.map([](auto path) { return path.to_byte_string(); })
.value_or_lazy_evaluated([] { return ByteString::formatted("{}/mesa_shader_cache", Core::StandardPaths::cache_directory()); });
TRY(Core::Directory::create(mesa_shader_cache_path, Core::Directory::CreateDirectories::Yes));
- TRY(add_landlock_path_if_exists(paths, mesa_shader_cache_path, LandlockPath::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, mesa_shader_cache_path, PathRule::Access::ReadWrite));
// The NVIDIA driver keeps its own shader cache.
if (!Core::System::access("/dev/nvidiactl"sv, F_OK).is_error()) {
@@ -189,7 +189,7 @@ ErrorOr<void> add_gpu_driver_landlock_paths(Vector<LandlockPath>& paths)
.map([](auto path) { return path.to_byte_string(); })
.value_or_lazy_evaluated([] { return ByteString::formatted("{}/nvidia", Core::StandardPaths::cache_directory()); });
TRY(Core::Directory::create(nvidia_shader_cache_path, Core::Directory::CreateDirectories::Yes));
- TRY(add_landlock_path_if_exists(paths, nvidia_shader_cache_path, LandlockPath::Access::ReadWrite));
+ TRY(add_path_if_exists(paths, nvidia_shader_cache_path, PathRule::Access::ReadWrite));
}
return {};
diff --git a/Libraries/LibSandbox/Sandbox.cpp b/Libraries/LibSandbox/Sandbox.cpp
index d4ade3aa298..5659c1adde5 100644
--- a/Libraries/LibSandbox/Sandbox.cpp
+++ b/Libraries/LibSandbox/Sandbox.cpp
@@ -75,7 +75,7 @@ ErrorOr<void> configure_runtime()
}
#if defined(AK_OS_LINUX)
-ErrorOr<void> add_landlock_path_if_exists(Vector<LandlockPath>& paths, StringView path, LandlockPath::Access access)
+ErrorOr<void> add_path_if_exists(Vector<PathRule>& paths, StringView path, PathRule::Access access)
{
auto path_bytes = path.to_byte_string();
@@ -97,7 +97,7 @@ ErrorOr<void> add_landlock_path_if_exists(Vector<LandlockPath>& paths, StringVie
return {};
}
-ErrorOr<void> add_loaded_library_directories(Vector<LandlockPath>& paths, Optional<StringView> root)
+ErrorOr<void> add_loaded_library_directories(Vector<PathRule>& paths, Optional<StringView> root)
{
Vector<ByteString> directories;
dl_iterate_phdr([](dl_phdr_info* info, size_t, void* data) {
@@ -114,7 +114,7 @@ ErrorOr<void> add_loaded_library_directories(Vector<LandlockPath>& paths, Option
for (auto const& directory : directories) {
if (!root.has_value() || LexicalPath { directory }.is_child_of(LexicalPath { root->to_byte_string() }))
- TRY(add_landlock_path_if_exists(paths, directory, LandlockPath::Access::ReadOnly));
+ TRY(add_path_if_exists(paths, directory, PathRule::Access::ReadOnly));
}
return {};
}
@@ -795,7 +795,7 @@ static ErrorOr<size_t> count_threads()
return thread_count;
}
-ErrorOr<void> restrict_filesystem_with_landlock(ReadonlySpan<LandlockPath> paths)
+ErrorOr<void> restrict_filesystem(ReadonlySpan<PathRule> paths)
{
// Landlock confines only the calling thread and the threads that it starts later. A thread that already runs would
// keep full access to the file system.
@@ -880,21 +880,21 @@ ErrorOr<void> restrict_filesystem_with_landlock(ReadonlySpan<LandlockPath> paths
landlock_path_beneath_attr path_beneath {};
switch (landlock_path.access) {
- case LandlockPath::Access::ReadOnly: {
+ case PathRule::Access::ReadOnly: {
path_beneath.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE;
if (landlock_path.is_directory)
path_beneath.allowed_access |= LANDLOCK_ACCESS_FS_READ_DIR;
break;
}
- case LandlockPath::Access::ReadAndExecute: {
+ case PathRule::Access::ReadAndExecute: {
path_beneath.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_EXECUTE;
if (landlock_path.is_directory)
path_beneath.allowed_access |= LANDLOCK_ACCESS_FS_READ_DIR;
break;
}
- case LandlockPath::Access::ReadWrite: {
+ case PathRule::Access::ReadWrite: {
path_beneath.allowed_access = LANDLOCK_ACCESS_FS_READ_FILE | LANDLOCK_ACCESS_FS_WRITE_FILE;
# ifdef LANDLOCK_ACCESS_FS_TRUNCATE
diff --git a/Libraries/LibSandbox/Sandbox.h b/Libraries/LibSandbox/Sandbox.h
index c3885af9e50..1b4b01b0f91 100644
--- a/Libraries/LibSandbox/Sandbox.h
+++ b/Libraries/LibSandbox/Sandbox.h
@@ -18,7 +18,7 @@
namespace Sandbox {
#if defined(AK_OS_LINUX)
-struct LandlockPath {
+struct PathRule {
enum class Access {
ReadOnly,
ReadAndExecute,
@@ -84,10 +84,10 @@ struct SeatbeltProfile {
[[nodiscard]] ErrorOr<void> configure_runtime();
#if defined(AK_OS_LINUX)
-[[nodiscard]] ErrorOr<void> add_landlock_path_if_exists(Vector<LandlockPath>& paths, StringView path, LandlockPath::Access);
-[[nodiscard]] ErrorOr<void> add_loaded_library_directories(Vector<LandlockPath>& paths, Optional<StringView> root = {});
-[[nodiscard]] ErrorOr<void> restrict_filesystem_with_landlock(ReadonlySpan<LandlockPath> = {});
-[[nodiscard]] ErrorOr<void> add_gpu_driver_landlock_paths(Vector<LandlockPath>& paths);
+[[nodiscard]] ErrorOr<void> add_path_if_exists(Vector<PathRule>& paths, StringView path, PathRule::Access);
+[[nodiscard]] ErrorOr<void> add_loaded_library_directories(Vector<PathRule>& paths, Optional<StringView> root = {});
+[[nodiscard]] ErrorOr<void> restrict_filesystem(ReadonlySpan<PathRule> = {});
+[[nodiscard]] ErrorOr<void> add_gpu_driver_paths(Vector<PathRule>& paths);
#endif
#if defined(AK_OS_MACOS)
diff --git a/Services/AudioServer/SandboxLinux.cpp b/Services/AudioServer/SandboxLinux.cpp
index 5b68ba559e1..224c024c85a 100644
--- a/Services/AudioServer/SandboxLinux.cpp
+++ b/Services/AudioServer/SandboxLinux.cpp
@@ -22,19 +22,19 @@ ErrorOr<void> apply_sandbox(StringView)
auto executable_path = TRY(Core::System::current_executable_path());
auto build_root = LexicalPath::dirname(LexicalPath::dirname(executable_path));
- Vector<Sandbox::LandlockPath> paths;
+ Vector<Sandbox::PathRule> paths;
// cpptrace opens loaded ELF objects when symbolizing in-process stack traces.
- TRY(Sandbox::add_landlock_path_if_exists(paths, executable_path, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, executable_path, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::PathRule::Access::ReadOnly));
TRY(Sandbox::add_loaded_library_directories(paths, build_root));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/proc/self"sv, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/proc/self"sv, Sandbox::PathRule::Access::ReadOnly));
// libpulse still keeps its cookie and runtime files in these, so they stay readable.
auto pulse_runtime_path = LexicalPath::join(TRY(Core::StandardPaths::runtime_directory()), "pulse"sv).string();
TRY(Core::Directory::create(pulse_runtime_path, Core::Directory::CreateDirectories::Yes, 0700));
- TRY(Sandbox::add_landlock_path_if_exists(paths, pulse_runtime_path, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, LexicalPath::join(Core::StandardPaths::config_directory(), "pulse"sv).string(), Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
+ TRY(Sandbox::add_path_if_exists(paths, pulse_runtime_path, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, LexicalPath::join(Core::StandardPaths::config_directory(), "pulse"sv).string(), Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::restrict_filesystem(paths.span()));
Sandbox::SeccompPolicy policy;
policy.allow_readonly_file_opens();
diff --git a/Services/Compositor/SandboxLinux.cpp b/Services/Compositor/SandboxLinux.cpp
index 1c71f4635f2..23bb7e2a2e8 100644
--- a/Services/Compositor/SandboxLinux.cpp
+++ b/Services/Compositor/SandboxLinux.cpp
@@ -16,11 +16,11 @@ ErrorOr<void> restrict_filesystem(StringView resource_root)
TRY(Sandbox::install_no_new_privileges());
TRY(Sandbox::configure_runtime());
- Vector<Sandbox::LandlockPath> paths;
- TRY(Sandbox::add_landlock_path_if_exists(paths, TRY(String::formatted("{}/fonts", resource_root)), Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_gpu_driver_landlock_paths(paths));
+ Vector<Sandbox::PathRule> paths;
+ TRY(Sandbox::add_path_if_exists(paths, TRY(String::formatted("{}/fonts", resource_root)), Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_gpu_driver_paths(paths));
- TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
+ TRY(Sandbox::restrict_filesystem(paths.span()));
return {};
}
diff --git a/Services/ImageDecoder/SandboxLinux.cpp b/Services/ImageDecoder/SandboxLinux.cpp
index 28cc3a3bb7e..4e1ea5c99fb 100644
--- a/Services/ImageDecoder/SandboxLinux.cpp
+++ b/Services/ImageDecoder/SandboxLinux.cpp
@@ -14,7 +14,7 @@ ErrorOr<void> apply_sandbox(StringView)
{
TRY(Sandbox::install_no_new_privileges());
TRY(Sandbox::configure_runtime());
- TRY(Sandbox::restrict_filesystem_with_landlock());
+ TRY(Sandbox::restrict_filesystem());
Sandbox::SeccompPolicy policy;
policy.deny_readonly_filesystem_probes();
diff --git a/Services/MediaServer/SandboxLinux.cpp b/Services/MediaServer/SandboxLinux.cpp
index e556900d248..9797f2850fe 100644
--- a/Services/MediaServer/SandboxLinux.cpp
+++ b/Services/MediaServer/SandboxLinux.cpp
@@ -20,14 +20,14 @@ ErrorOr<void> apply_sandbox(StringView)
auto executable_path = TRY(Core::System::current_executable_path());
auto build_root = LexicalPath::dirname(LexicalPath::dirname(executable_path));
- Vector<Sandbox::LandlockPath> paths;
+ Vector<Sandbox::PathRule> paths;
// cpptrace opens loaded ELF objects when symbolizing in-process stack traces.
- TRY(Sandbox::add_landlock_path_if_exists(paths, executable_path, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, executable_path, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::PathRule::Access::ReadOnly));
TRY(Sandbox::add_loaded_library_directories(paths, build_root));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/proc/self"sv, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/proc/self"sv, Sandbox::PathRule::Access::ReadOnly));
- TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
+ TRY(Sandbox::restrict_filesystem(paths.span()));
Sandbox::SeccompPolicy policy;
policy.allow_readonly_file_opens();
diff --git a/Services/RendererSandboxLinux.cpp b/Services/RendererSandboxLinux.cpp
index b648ff0226c..35f4f2297d3 100644
--- a/Services/RendererSandboxLinux.cpp
+++ b/Services/RendererSandboxLinux.cpp
@@ -21,15 +21,15 @@ ErrorOr<void> apply_sandbox(StringView)
auto executable_path = TRY(Core::System::current_executable_path());
auto build_root = LexicalPath::dirname(LexicalPath::dirname(executable_path));
- Vector<Sandbox::LandlockPath> paths;
- TRY(Sandbox::add_landlock_path_if_exists(paths, WebView::s_ladybird_resource_root, Sandbox::LandlockPath::Access::ReadOnly));
+ Vector<Sandbox::PathRule> paths;
+ TRY(Sandbox::add_path_if_exists(paths, WebView::s_ladybird_resource_root, Sandbox::PathRule::Access::ReadOnly));
// cpptrace opens loaded ELF objects when symbolizing in-process stack traces.
- TRY(Sandbox::add_landlock_path_if_exists(paths, executable_path, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, executable_path, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::PathRule::Access::ReadOnly));
TRY(Sandbox::add_loaded_library_directories(paths, build_root));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/proc/self"sv, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/proc/self"sv, Sandbox::PathRule::Access::ReadOnly));
- TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
+ TRY(Sandbox::restrict_filesystem(paths.span()));
Sandbox::SeccompPolicy policy;
policy.allow_readonly_file_opens();
diff --git a/Services/RequestServer/SandboxLinux.cpp b/Services/RequestServer/SandboxLinux.cpp
index 861f6765e7c..0a9742c5549 100644
--- a/Services/RequestServer/SandboxLinux.cpp
+++ b/Services/RequestServer/SandboxLinux.cpp
@@ -22,28 +22,28 @@
namespace RequestServer {
// Landlock binds to inodes. Open each bundle path to grant its symlink target, including targets outside /etc/ssl.
-static ErrorOr<void> add_certificate_store_paths(Vector<Sandbox::LandlockPath>& paths)
+static ErrorOr<void> add_certificate_store_paths(Vector<Sandbox::PathRule>& paths)
{
// OpenSSL may load OPENSSL_CONF during initialization.
if (auto* config_file = CONF_get1_default_config_file()) {
- auto result = Sandbox::add_landlock_path_if_exists(paths, StringView { config_file, strlen(config_file) }, Sandbox::LandlockPath::Access::ReadOnly);
+ auto result = Sandbox::add_path_if_exists(paths, StringView { config_file, strlen(config_file) }, Sandbox::PathRule::Access::ReadOnly);
OPENSSL_free(config_file);
TRY(result);
}
if (auto const* version_info = curl_version_info(CURLVERSION_NOW)) {
if (version_info->cainfo)
- TRY(Sandbox::add_landlock_path_if_exists(paths, ByteString { version_info->cainfo }, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, ByteString { version_info->cainfo }, Sandbox::PathRule::Access::ReadOnly));
if (version_info->capath)
- TRY(Sandbox::add_landlock_path_if_exists(paths, ByteString { version_info->capath }, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, ByteString { version_info->capath }, Sandbox::PathRule::Access::ReadOnly));
}
// libcurl is built with CURL_CA_FALLBACK, so OpenSSL's default store is consulted when no bundle is set.
- TRY(Sandbox::add_landlock_path_if_exists(paths, ByteString { X509_get_default_cert_file() }, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, ByteString { X509_get_default_cert_dir() }, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, ByteString { X509_get_default_cert_file() }, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, ByteString { X509_get_default_cert_dir() }, Sandbox::PathRule::Access::ReadOnly));
for (auto variable : { X509_get_default_cert_file_env(), X509_get_default_cert_dir_env() }) {
if (auto value = Core::Environment::get(StringView { variable, strlen(variable) }); value.has_value() && !value->is_empty())
- TRY(Sandbox::add_landlock_path_if_exists(paths, *value, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, *value, Sandbox::PathRule::Access::ReadOnly));
}
return {};
@@ -94,31 +94,31 @@ ErrorOr<void> apply_sandbox(StringView, Vector<ByteString> const& certificates,
preload_nss_host_modules();
- Vector<Sandbox::LandlockPath> paths;
+ Vector<Sandbox::PathRule> paths;
TRY(add_certificate_store_paths(paths));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/etc/host.conf"sv, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/etc/hosts"sv, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/etc/nsswitch.conf"sv, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/etc/resolv.conf"sv, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/run/systemd/resolve"sv, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/etc/host.conf"sv, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/etc/hosts"sv, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/etc/nsswitch.conf"sv, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/etc/resolv.conf"sv, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/run/systemd/resolve"sv, Sandbox::PathRule::Access::ReadOnly));
// nss-resolve checks this sysctl to decide whether to ask for AAAA records.
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/proc/sys/net/ipv6/conf/all/disable_ipv6"sv, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/proc/sys/net/ipv6/conf/all/disable_ipv6"sv, Sandbox::PathRule::Access::ReadOnly));
for (auto const& certificate : certificates)
- TRY(Sandbox::add_landlock_path_if_exists(paths, certificate, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, certificate, Sandbox::PathRule::Access::ReadOnly));
if (g_resource_substitution_map) {
TRY(g_resource_substitution_map->for_each_substitution([&](auto const& substitution) -> ErrorOr<void> {
- TRY(Sandbox::add_landlock_path_if_exists(paths, substitution.file_path, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, substitution.file_path, Sandbox::PathRule::Access::ReadOnly));
return {};
}));
}
if (disk_cache_directory.has_value())
- TRY(Sandbox::add_landlock_path_if_exists(paths, *disk_cache_directory, Sandbox::LandlockPath::Access::ReadWrite));
+ TRY(Sandbox::add_path_if_exists(paths, *disk_cache_directory, Sandbox::PathRule::Access::ReadWrite));
- TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
+ TRY(Sandbox::restrict_filesystem(paths.span()));
Sandbox::SeccompPolicy policy;
policy.allow_readonly_file_opens();
diff --git a/Services/VideoDecoderServer/SandboxLinux.cpp b/Services/VideoDecoderServer/SandboxLinux.cpp
index c904f5a138c..5e2f3cc40aa 100644
--- a/Services/VideoDecoderServer/SandboxLinux.cpp
+++ b/Services/VideoDecoderServer/SandboxLinux.cpp
@@ -20,15 +20,15 @@ ErrorOr<void> restrict_filesystem(bool allow_gpu_driver)
auto executable_path = TRY(Core::System::current_executable_path());
auto build_root = LexicalPath::dirname(LexicalPath::dirname(executable_path));
- Vector<Sandbox::LandlockPath> paths;
+ Vector<Sandbox::PathRule> paths;
// cpptrace opens loaded ELF objects when symbolizing in-process stack traces.
- TRY(Sandbox::add_landlock_path_if_exists(paths, executable_path, Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::LandlockPath::Access::ReadOnly));
- TRY(Sandbox::add_landlock_path_if_exists(paths, "/proc/self"sv, Sandbox::LandlockPath::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, executable_path, Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, LexicalPath::join(build_root, "lib"sv).string(), Sandbox::PathRule::Access::ReadOnly));
+ TRY(Sandbox::add_path_if_exists(paths, "/proc/self"sv, Sandbox::PathRule::Access::ReadOnly));
if (allow_gpu_driver)
- TRY(Sandbox::add_gpu_driver_landlock_paths(paths));
+ TRY(Sandbox::add_gpu_driver_paths(paths));
- TRY(Sandbox::restrict_filesystem_with_landlock(paths.span()));
+ TRY(Sandbox::restrict_filesystem(paths.span()));
return {};
}
diff --git a/Services/WebRTCClient/SandboxLinux.cpp b/Services/WebRTCClient/SandboxLinux.cpp
index e44a665fea4..0e06c0ae217 100644
--- a/Services/WebRTCClient/SandboxLinux.cpp
+++ b/Services/WebRTCClient/SandboxLinux.cpp
@@ -16,7 +16,7 @@ ErrorOr<void> apply_sandbox(StringView, NetworkAccess network_access)
TRY(Sandbox::configure_runtime());
// Nothing on the file system is ours to read. Even host names are looked up by the renderer, through RequestServer.
- TRY(Sandbox::restrict_filesystem_with_landlock({}));
+ TRY(Sandbox::restrict_filesystem({}));
Sandbox::SeccompPolicy policy;
policy.allow_readonly_file_opens();
diff --git a/Tests/LibSandbox/TestLandlock.cpp b/Tests/LibSandbox/TestLandlock.cpp
index 015aa1f5539..8c69bb6ca47 100644
--- a/Tests/LibSandbox/TestLandlock.cpp
+++ b/Tests/LibSandbox/TestLandlock.cpp
@@ -50,7 +50,7 @@ static Outcome restrict_filesystem_when_version_probe_returns(u32 error)
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0 || prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &program) < 0)
_exit(2);
- auto result = Sandbox::restrict_filesystem_with_landlock();
+ auto result = Sandbox::restrict_filesystem();
_exit(result.is_error() ? 0 : 1);
}
@@ -100,7 +100,7 @@ TEST_CASE(a_missing_landlock_can_be_allowed_explicitly)
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) < 0 || prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &program) < 0)
_exit(2);
- auto result = Sandbox::restrict_filesystem_with_landlock();
+ auto result = Sandbox::restrict_filesystem();
_exit(result.is_error() ? 1 : 0);
}
@@ -130,7 +130,7 @@ TEST_CASE(a_process_with_a_second_thread_refuses_the_sandbox)
if (pthread_create(&thread, nullptr, wait_for_pipe, &pipe_fds[0]) != 0)
_exit(2);
- auto result = Sandbox::restrict_filesystem_with_landlock();
+ auto result = Sandbox::restrict_filesystem();
_exit(result.is_error() ? 0 : 1);
}
@@ -172,7 +172,7 @@ TEST_CASE(abstract_unix_sockets_outside_the_landlock_domain_are_unreachable)
VERIFY(child >= 0);
if (child == 0) {
MUST(Sandbox::install_no_new_privileges());
- MUST(Sandbox::restrict_filesystem_with_landlock());
+ MUST(Sandbox::restrict_filesystem());
// No seccomp policy is installed: these refusals must come from Landlock.
VERIFY(connect(sender, reinterpret_cast<sockaddr*>(&address), address_length) == -1);
@@ -225,7 +225,7 @@ TEST_CASE(signals_stay_within_the_landlock_process_tree)
VERIFY(child >= 0);
if (child == 0) {
MUST(Sandbox::install_no_new_privileges());
- MUST(Sandbox::restrict_filesystem_with_landlock());
+ MUST(Sandbox::restrict_filesystem());
Sandbox::SeccompPolicy policy;
policy.allow_common_runtime();
policy.allow_process_creation();
diff --git a/Tests/LibSandbox/TestSeccomp.cpp b/Tests/LibSandbox/TestSeccomp.cpp
index 6f669c80b25..ca35f6be435 100644
--- a/Tests/LibSandbox/TestSeccomp.cpp
+++ b/Tests/LibSandbox/TestSeccomp.cpp
@@ -271,7 +271,7 @@ TEST_CASE(filesystem_write_policy_refuses_timestamp_changes_outside_landlock)
auto status = run_with_policy(
[&](auto& policy) {
VERIFY(close(fd) == 0);
- MUST(Sandbox::restrict_filesystem_with_landlock());
+ MUST(Sandbox::restrict_filesystem());
policy.allow_filesystem_writes();
},
[&] {
@@ -387,7 +387,7 @@ TEST_CASE(pulseaudio_client_policy_allows_directory_creation_and_record_locks)
auto status = run_with_policy(
[&](auto& policy) {
if (has_landlock)
- MUST(Sandbox::restrict_filesystem_with_landlock());
+ MUST(Sandbox::restrict_filesystem());
policy.allow_pulseaudio_client_file_operations();
},
[&] {