Skip to content

Commit be7d737

Browse files
Sandboxed API Teamcopybara-github
authored andcommitted
Automated rollback of commit 47b072b.
PiperOrigin-RevId: 869969399 Change-Id: I429f6fcbc8ae569c82dbac9c758aa7ee35ccb09a
1 parent 47b072b commit be7d737

File tree

3 files changed

+5
-35
lines changed

3 files changed

+5
-35
lines changed

sandboxed_api/sandbox2/fork_client.cc

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
#include "sandboxed_api/sandbox2/fork_client.h"
1616

1717
#include <sys/types.h>
18-
#include <syscall.h>
19-
#include <unistd.h>
2018

2119
#include <cstdint>
2220

@@ -31,14 +29,6 @@ namespace sandbox2 {
3129

3230
using ::sapi::file_util::fileops::FDCloser;
3331

34-
namespace {
35-
36-
int pidfd_open(pid_t pid, unsigned int flags) {
37-
return syscall(__NR_pidfd_open, pid, flags);
38-
}
39-
40-
} // namespace
41-
4232
ForkClient::ForkClient(pid_t pid, Comms* comms, bool is_global)
4333
: pid_(pid), comms_(comms), is_global_(is_global) {
4434
}
@@ -78,23 +68,14 @@ SandboxeeProcess ForkClient::SendRequest(const ForkRequest& request,
7868
LOG(ERROR) << "Receiving init PID from the ForkServer failed";
7969
return process;
8070
}
81-
if (pid != 0) { // No init process if pid is 0
82-
process.init_pid = static_cast<pid_t>(pid);
83-
process.init_pidfd = FDCloser(pidfd_open(process.init_pid, 0));
84-
PCHECK(process.init_pidfd.get() != -1)
85-
<< "Failed to open pidfd for init process";
86-
}
71+
process.init_pid = static_cast<pid_t>(pid);
8772

8873
// Receive sandboxee process ID.
8974
if (!comms_->RecvInt32(&pid)) {
9075
LOG(ERROR) << "Receiving sandboxee PID from the ForkServer failed";
9176
return process;
9277
}
9378
process.main_pid = static_cast<pid_t>(pid);
94-
process.main_pidfd = FDCloser(pidfd_open(process.main_pid, 0));
95-
PCHECK(process.main_pidfd.get() != -1)
96-
<< "Failed to open pidfd for main process";
97-
9879
if (request.monitor_type() == FORKSERVER_MONITOR_UNOTIFY) {
9980
int fd = -1;
10081
if (!comms_->RecvFD(&fd)) {

sandboxed_api/sandbox2/fork_client.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,8 @@ class Comms;
3232
class ForkRequest;
3333

3434
struct SandboxeeProcess {
35-
pid_t init_pid = 0;
36-
sapi::file_util::fileops::FDCloser init_pidfd;
37-
pid_t main_pid = 0;
38-
sapi::file_util::fileops::FDCloser main_pidfd;
35+
pid_t init_pid = -1;
36+
pid_t main_pid = -1;
3937
sapi::file_util::fileops::FDCloser status_fd;
4038
};
4139

@@ -44,7 +42,6 @@ class ForkClient {
4442
ForkClient(pid_t pid, Comms* comms) : ForkClient(pid, comms, false) {}
4543
ForkClient(const ForkClient&) = delete;
4644
ForkClient& operator=(const ForkClient&) = delete;
47-
4845
~ForkClient();
4946

5047
// Runs a custom transaction over the Comms channel.

sandboxed_api/sandbox2/monitor_unotify.cc

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,6 @@ absl::Status WaitForTaskToStop(pid_t pid) {
125125
: absl::InternalError("task did not stop");
126126
}
127127

128-
int pidfd_send_signal(int pidfd, int sig, siginfo_t* info, unsigned int flags) {
129-
return syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
130-
}
131-
132128
} // namespace
133129

134130
UnotifyMonitor::UnotifyMonitor(Executor* executor, Policy* policy,
@@ -424,20 +420,16 @@ void UnotifyMonitor::NotifyMonitor() {
424420

425421
bool UnotifyMonitor::KillSandboxee() {
426422
VLOG(1) << "Sending SIGKILL to the PID: " << process_.main_pid;
427-
if (pidfd_send_signal(process_.main_pidfd.get(), SIGKILL, nullptr, 0) != 0) {
423+
if (kill(process_.main_pid, SIGKILL) != 0) {
428424
PLOG(ERROR) << "Could not send SIGKILL to PID " << process_.main_pid;
429-
SetExitStatusCode(Result::INTERNAL_ERROR, Result::FAILED_KILL);
430425
return false;
431426
}
432427
return true;
433428
}
434429

435430
void UnotifyMonitor::KillInit() {
436431
VLOG(1) << "Sending SIGKILL to the PID: " << process_.init_pid;
437-
if (process_.init_pid != 0 &&
438-
pidfd_send_signal(process_.init_pidfd.get(), SIGKILL, nullptr, 0) != 0 &&
439-
errno != ESRCH) {
440-
// Ignore ESRCH (process not found), as it is not an error.
432+
if (kill(process_.init_pid, SIGKILL) != 0) {
441433
PLOG(ERROR) << "Could not send SIGKILL to PID " << process_.init_pid;
442434
}
443435
}

0 commit comments

Comments
 (0)