Skip to content

Commit

Permalink
Prevent AV in processinfo2 while suspended (#55379)
Browse files Browse the repository at this point in the history
  • Loading branch information
John Salem committed Jul 12, 2021
1 parent cd4df7d commit e544ccf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
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

0 comments on commit e544ccf

Please sign in to comment.