[clang] Bypass FS sandbox during Linux distro detection#175201
[clang] Bypass FS sandbox during Linux distro detection#175201jansvoboda11 wants to merge 1 commit intollvm:mainfrom
Conversation
There's some logic in Linux distro detection that relies on the VFS being the real FS. This check is implemented such that it violates the IO sandbox. This PR implements narrow sandbox disablement for this specific check.
|
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Jan Svoboda (jansvoboda11) ChangesThere's some logic in Linux distro detection that relies on the VFS being the real FS. This check is implemented such that it violates the IO sandbox. This PR implements narrow sandbox disablement for this specific check. Full diff: https://github.com/llvm/llvm-project/pull/175201.diff 1 Files Affected:
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index df10458d092d6..3c335891f9971 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -11,6 +11,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/IOSandbox.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Threading.h"
#include "llvm/TargetParser/Host.h"
@@ -211,7 +212,10 @@ static Distro::DistroType GetDistro(llvm::vfs::FileSystem &VFS,
return Distro::UnknownDistro;
// True if we're backed by a real file system.
- const bool onRealFS = (llvm::vfs::getRealFileSystem() == &VFS);
+ const bool onRealFS = [&] {
+ auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
+ return llvm::vfs::getRealFileSystem() == &VFS;
+ }();
// If the host is not running Linux, and we're backed by a real file
// system, no need to check the distro. This is the case where someone
|
|
Closing in favor of #175097. Generally we don't expect any part of the driver to be free of sandbox violations. The new PR disables the sandbox for the entirety of the driver usage within the sandboxed frontend, instead of just fixing the single offending function call and hoping other parts of the driver don't trigger more violations. |
There's some logic in Linux distro detection that relies on the VFS being the real FS. This check is implemented such that it violates the IO sandbox. This PR implements narrow sandbox disablement for this specific check.