Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Track ask and hold mode atomically while processing an event #187

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Source/santad/SNTExecutionController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ - (void)validateExecEvent:(const Message &)esMsg postAction:(bool (^)(SNTAction)
BOOL stoppedProc = false;
std::pair<pid_t, int> pidAndVersion =
std::make_pair(newProcPid, audit_token_to_pidversion(targetProc->audit_token));
bool holdAndAsk = false;
// Only allow a user in standalone mode to override a block if an
// explicit block rule is not set when using a sync service.
if (cd.decision == SNTEventStateBlockUnknown && config.clientMode == SNTClientModeStandalone) {
// In standalone mode we want hold off on making a decision until the user has had a chance to
// approve. ES won't let us do this, we'd hit the response deadline. Instead, we suspend the
Expand All @@ -330,6 +333,7 @@ - (void)validateExecEvent:(const Message &)esMsg postAction:(bool (^)(SNTAction)
_procSignalCache->set(pidAndVersion, true);
stoppedProc = [self manipulatePID:newProcPid withControl:ProcessControl::Suspend];
postAction(SNTActionRespondAllow);
holdAndAsk = true;
} else {
// Respond with the decision.
postAction(action);
Expand Down Expand Up @@ -411,7 +415,7 @@ - (void)validateExecEvent:(const Message &)esMsg postAction:(bool (^)(SNTAction)
if (!cd.silentBlock) {
[self maybeSendTTYMessageToTarget:targetProc
messageCreator:^NSString * {
if (config.clientMode == SNTClientModeStandalone) {
if (holdAndAsk) {
if (stoppedProc) {
return @"---\n\033[1mSanta\033[0m\n\nHolding execution of this "
@"binary until approval is granted in the GUI...\n";
Expand Down Expand Up @@ -443,10 +447,7 @@ - (void)validateExecEvent:(const Message &)esMsg postAction:(bool (^)(SNTAction)

void (^replyBlock)(BOOL) = nil;

// Only allow a user in standalone mode to override a block if an
// explicit block rule is not set when using a sync service.
if (config.clientMode == SNTClientModeStandalone &&
se.decision == SNTEventStateBlockUnknown) {
if (holdAndAsk) {
replyBlock = ^(BOOL authenticated) {
LOGD(@"User responded to block event for %@ with authenticated: %d", se.filePath,
authenticated);
Expand Down
Loading