Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Prevent AV in processinfo2 while suspended #55379

Merged
merged 1 commit into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion src/coreclr/vm/eventing/eventpipe/ep-rt-coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,22 @@ ep_rt_entrypoint_assembly_name_get_utf8 (void)
{
STATIC_CONTRACT_NOTHROW;

return reinterpret_cast<const ep_char8_t*>(GetAppDomain ()->GetRootAssembly ()->GetSimpleName ());
AppDomain *app_domain_ref = nullptr;
Assembly *assembly_ref = nullptr;

app_domain_ref = GetAppDomain ();
if (app_domain_ref != nullptr)
{
assembly_ref = app_domain_ref->GetRootAssembly ();
if (assembly_ref != nullptr)
{
return reinterpret_cast<const ep_char8_t*>(assembly_ref->GetSimpleName ());
}
}

// fallback to the empty string if we can't get assembly info, e.g., if the runtime is
// suspended before an assembly is loaded.
return reinterpret_cast<const ep_char8_t*>("");
}

static
Expand Down
36 changes: 36 additions & 0 deletions src/tests/tracing/eventpipe/diagnosticport/diagnosticport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,42 @@ public static async Task<bool> TEST_ConfigValidation()
return fSuccess;
}

public static async Task<bool> TEST_CanGetProcessInfo2WhileSuspended()
{
bool fSuccess = true;
Task<bool> subprocessTask = Utils.RunSubprocess(
currentAssembly: Assembly.GetExecutingAssembly(),
environment: new Dictionary<string,string>
{
{ Utils.DiagnosticPortSuspend, "1" }
},
duringExecution: (int pid) =>
{
Stream stream = ConnectionHelper.GetStandardTransport(pid);

// 0x04 = ProcessCommandSet, 0x04 = ProcessInfo2
var processInfoMessage = new IpcMessage(0x04, 0x04);
Logger.logger.Log($"Wrote: {processInfoMessage}");
IpcMessage response = IpcClient.SendMessage(stream, processInfoMessage);
Logger.logger.Log($"Received: [{response.Payload.Select(b => b.ToString("X2") + " ").Aggregate(string.Concat)}]");
ProcessInfo2 processInfo2 = ProcessInfo2.TryParse(response.Payload);
Utils.Assert(String.IsNullOrEmpty(processInfo2.ManagedEntrypointAssemblyName));

// send resume command on this connection
var message = new IpcMessage(0x04,0x01);
Logger.logger.Log($"Sent: {message.ToString()}");
response = IpcClient.SendMessage(ConnectionHelper.GetStandardTransport(pid), message);
Logger.logger.Log($"Received: {response.ToString()}");

return Task.FromResult(true);
}
);

fSuccess &= await subprocessTask;

return fSuccess;
}

public static async Task<int> Main(string[] args)
{
if (args.Length >= 1)
Expand Down