Skip to content

Truly independent web browser

LibSandbox: Permit `statfs`

Aliaksandr Kalenikfacac7d661c4
diff --git a/Libraries/LibSandbox/Seccomp.cpp b/Libraries/LibSandbox/Seccomp.cpp
index 1cc31300316..968f7eac50d 100644
--- a/Libraries/LibSandbox/Seccomp.cpp
+++ b/Libraries/LibSandbox/Seccomp.cpp
@@ -193,6 +193,7 @@ static constexpr unsigned read_only_open_flags = [] {
#define IF_DEFINED_socket(if_defined, if_not_defined) if_defined
#define IF_DEFINED_socketpair(if_defined, if_not_defined) if_defined
#define IF_DEFINED_stat(if_defined, if_not_defined) if_defined
+#define IF_DEFINED_statfs(if_defined, if_not_defined) if_defined
#define IF_DEFINED_statx(if_defined, if_not_defined) if_defined
#define IF_DEFINED_symlink(if_defined, if_not_defined) if_defined
#define IF_DEFINED_sysinfo(if_defined, if_not_defined) if_defined
@@ -454,6 +455,10 @@ static constexpr unsigned read_only_open_flags = [] {
# undef IF_DEFINED_stat
# define IF_DEFINED_stat(if_defined, if_not_defined) if_not_defined
#endif
+#ifndef __NR_statfs
+# undef IF_DEFINED_statfs
+# define IF_DEFINED_statfs(if_defined, if_not_defined) if_not_defined
+#endif
#ifndef __NR_statx
# undef IF_DEFINED_statx
# define IF_DEFINED_statx(if_defined, if_not_defined) if_not_defined
@@ -683,6 +688,9 @@ static char const* syscall_name(long syscall_number)
#ifdef __NR_stat
CASE_SYSCALL_NAME(stat);
#endif
+#ifdef __NR_statfs
+ CASE_SYSCALL_NAME(statfs);
+#endif
#ifdef __NR_statx
CASE_SYSCALL_NAME(statx);
#endif
@@ -1200,6 +1208,7 @@ void SeccompPolicy::allow_filesystem_metadata_queries()
SECCOMP_APPEND_ALLOW_SYSCALL_IF_DEFINED(*this, readlink);
SECCOMP_APPEND_ALLOW_SYSCALL_IF_DEFINED(*this, readlinkat);
SECCOMP_APPEND_ALLOW_SYSCALL_IF_DEFINED(*this, stat);
+ SECCOMP_APPEND_ALLOW_SYSCALL_IF_DEFINED(*this, statfs);
SECCOMP_APPEND_ALLOW_SYSCALL_IF_DEFINED(*this, statx);
}
diff --git a/Tests/LibSandbox/TestSeccomp.cpp b/Tests/LibSandbox/TestSeccomp.cpp
index 0d760d9428e..2588fdca594 100644
--- a/Tests/LibSandbox/TestSeccomp.cpp
+++ b/Tests/LibSandbox/TestSeccomp.cpp
@@ -34,6 +34,7 @@
#include <sys/resource.h>
#include <sys/socket.h>
#include <sys/stat.h>
+#include <sys/statvfs.h>
#include <sys/syscall.h>
#include <sys/un.h>
#include <sys/wait.h>
@@ -211,6 +212,21 @@ TEST_CASE(process_creation_policy_allows_parent_death_signal)
EXPECT_EQ(WEXITSTATUS(status), 0);
}
+TEST_CASE(filesystem_metadata_policy_answers_the_statvfs_that_mesa_uses)
+{
+ // Mesa calls statvfs() on its shader cache directory while a GPU driver starts up, and glibc implements it
+ // with the statfs syscall.
+ auto status = run_with_policy(
+ [](auto& policy) { policy.allow_filesystem_metadata_queries(); },
+ [] {
+ struct statvfs metadata {};
+ VERIFY(statvfs("/tmp", &metadata) == 0);
+ });
+ EXPECT(WIFEXITED(status));
+ if (WIFEXITED(status))
+ EXPECT_EQ(WEXITSTATUS(status), 0);
+}
+
TEST_CASE(gpu_policy_allows_graphics_ioctl_families)
{
auto status = run_with_policy(