Closed lambdageek closed 9 months ago
It only reproduces when the shared library is loaded as an LLDB plugin.
Loading it into a user-built host app that is codesigned to use the Hardened Runtime doesn't cause the same crash - mprotect
works fine
I read somewhere that vm_protect(.... , VM_PROT_WRITE | VM_PROT_COPY)
might work more frequently than mprotect
or vm_protect
without the VM_PROT_COPY
, but the following doesn't fix it:
vm_prot_t machProtect = UnixProtectToMachProtect(unixProtect);
mach_port_t selfTask = mach_task_self();
printf ("trying first mach_vm_protect (selfTask, %p, %zu, 0, 0x%08x)\n", pPageStart, memSize, (int)machProtect);
kern_return_t ret = mach_vm_protect (selfTask, (mach_vm_address_t)pPageStart, (mach_vm_size_t)memSize, /*setMaximum*/0, machProtect);
printf("first vm_protect returned %d (eq KERN_SUCCESS? %s)\n", (int)ret, (ret == KERN_SUCCESS) ? "yes" : "no");
/* see mach/vm_prot.h VM_PROT_COPY note:
* When a caller finds that he cannot obtain write permission on a
* mapped entry, the following flag can be used. The entry will
* be made "needs copy" effectively copying the object (using COW),
* and write permission will be added to the maximum protections
* for the associated entry.
*/
if (ret != KERN_SUCCESS && (machProtect & VM_PROT_WRITE) != 0) {
printf ("trying second mach_vm_protect (selfTask, %p, %zu, 0, 0x%08x)\n", pPageStart, memSize, (int)(machProtect | VM_PROT_COPY));
ret = mach_vm_protect(selfTask, (mach_vm_address_t)pPageStart, (mach_vm_size_t)memSize, 0, machProtect | VM_PROT_COPY);
printf("second mach_vm_protect returned %d (eq KERN_SUCCESS? %s)\n", (int)ret, (ret == KERN_SUCCESS) ? "yes" : "no");
}
return ret != KERN_SUCCESS; /* PalVirtualProtect returns 0 on success */
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.
Author: | lambdageek |
---|---|
Assignees: | - |
Labels: | `untriaged`, `area-NativeAOT-coreclr`, `needs-area-label` |
Milestone: | - |
I'm going to open a PR to disable FEATURE_READONLY_GS_COOKIE
on MacOS X. It's already for the ios-like platforms:
I'm am writing an LLDB plugin using NativeAOT. When I load my plugin into Apple's LLDB, it crashes when trying to change the memory protection on
__security_cookie
.Repro
dotnet new classlib
Expected output
Actual output
The Console.app shows a better crash dump with symbols
Repros with .NET 8.0.2 and .NET 9
main
.With some printf debugging I found that the crash happens because this call fails:
https://github.com/dotnet/runtime/blob/91008723d1f2c2daa29d69e1bd641ef651e39dc8/src/coreclr/nativeaot/Runtime/startup.cpp#L173-L176
Which fails because this call to
mprotect
fails:https://github.com/dotnet/runtime/blob/91008723d1f2c2daa29d69e1bd641ef651e39dc8/src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp#L831