Skip to content

Commit 1a64884

Browse files
happyCoder92copybara-github
authored andcommitted
Explicitly disable speculation
PiperOrigin-RevId: 818598246 Change-Id: I00df56fd033873d3210abed39a0a5b1ad90ccdae
1 parent 998b8ea commit 1a64884

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

sandboxed_api/sandbox2/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@ cc_library(
592592
":policy",
593593
":sanitizer",
594594
":syscall",
595+
"//sandboxed_api:config",
595596
"//sandboxed_api/sandbox2/network_proxy:client",
596597
"//sandboxed_api/sandbox2/util:bpf_helper",
597598
"//sandboxed_api/util:raw_logging",

sandboxed_api/sandbox2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,7 @@ target_link_libraries(sandbox2_client
562562
sandbox2::sanitizer
563563
sandbox2::syscall
564564
sapi::base
565+
sapi::config
565566
sapi::raw_logging
566567
PUBLIC absl::flat_hash_map
567568
absl::status

sandboxed_api/sandbox2/client.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "absl/strings/str_join.h"
4646
#include "absl/strings/str_split.h"
4747
#include "absl/strings/string_view.h"
48+
#include "sandboxed_api/config.h"
4849
#include "sandboxed_api/sandbox2/comms.h"
4950
#include "sandboxed_api/sandbox2/logsink.h"
5051
#include "sandboxed_api/sandbox2/network_proxy/client.h"
@@ -331,6 +332,18 @@ void Client::ApplyPolicyAndBecomeTracee() {
331332
SAPI_RAW_CHECK(comms_->RecvUint32(&message),
332333
"receving confirmation from executor");
333334
bool allow_speculation = message & kAllowSpeculationBit;
335+
if (!allow_speculation) {
336+
if constexpr (sapi::host_cpu::IsX8664() || sapi::host_cpu::IsArm64()) {
337+
SAPI_RAW_PCHECK(prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_STORE_BYPASS,
338+
PR_SPEC_FORCE_DISABLE, 0, 0) == 0,
339+
"could not disable store bypass speculation");
340+
}
341+
if constexpr (sapi::host_cpu::IsX8664()) {
342+
SAPI_RAW_PCHECK(prctl(PR_SET_SPECULATION_CTRL, PR_SPEC_INDIRECT_BRANCH,
343+
PR_SPEC_FORCE_DISABLE, 0, 0) == 0,
344+
"could not disable indirect branch speculation");
345+
}
346+
}
334347
uint32_t seccomp_extra_flags =
335348
allow_speculation ? SECCOMP_FILTER_FLAG_SPEC_ALLOW : 0;
336349
uint32_t monitor_type = message & kMonitorTypeMask;

0 commit comments

Comments
 (0)