Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
33c53fa
Add auth-strip in prolog and epilog of jitted methods
SwapnilGaikwad Dec 6, 2024
c45b4a8
Merge main
SwapnilGaikwad Jan 24, 2025
19b977a
Use unwind info to indicate use of PAC
SwapnilGaikwad Jan 24, 2025
c2c03f9
Merge main
SwapnilGaikwad Jan 30, 2025
c64cc1f
Switch to auth with zero and fix tail call optimisations
SwapnilGaikwad Jan 30, 2025
cfddf71
fix nativeaot CFI unwind code
kunalspathak Jan 31, 2025
3bf9346
fix build
kunalspathak Jan 31, 2025
042210f
Add STRIP_PAC
kunalspathak Feb 5, 2025
435a901
wip
kunalspathak Feb 6, 2025
e9f101c
Uncomment the implementation of RtlStripPacOnline()
kunalspathak Feb 6, 2025
1dae16f
Add some missing declaration of CFI_NEGATE_RA_STATE
kunalspathak Feb 6, 2025
a1265fb
build fix
kunalspathak Feb 6, 2025
8a05d92
Comment StripOnline
kunalspathak Feb 6, 2025
98246b7
Add JitPacEnabled() switch
kunalspathak Feb 6, 2025
cb3879b
Make PacEnabled a Release flag
kunalspathak Feb 7, 2025
5a24d2a
Just strip from bit 48 onwards because thats what works for linux
kunalspathak Feb 7, 2025
ba343d2
Fix return address hijacking
SwapnilGaikwad Feb 13, 2025
e414fc7
Unwinder: Strip the Lr before storing in PC
kunalspathak Feb 17, 2025
f3b9e61
Emit pac unwind info in epilog
SwapnilGaikwad Feb 19, 2025
bb67312
Add inline assembly variants for MSVC
SwapnilGaikwad Feb 21, 2025
abfe3d4
Merge main
SwapnilGaikwad Feb 24, 2025
0d0fc7f
Remove MSVC assembly
SwapnilGaikwad Mar 3, 2025
8394024
Merge main
SwapnilGaikwad Mar 3, 2025
ddf6c3d
Restore previous fix to check its impact on nativeaot failures
SwapnilGaikwad Mar 12, 2025
2b6bf2b
Fix basic AOT tests
SwapnilGaikwad Mar 12, 2025
b408ec5
Fix reaturn address hijacking for AOT
SwapnilGaikwad Mar 12, 2025
a5a94a7
Merge main
SwapnilGaikwad Mar 13, 2025
240b551
Disable emitting authenticate to see behaviour on windows
SwapnilGaikwad Mar 18, 2025
09a6c40
Fix return address comparison for tail calls in native aot
SwapnilGaikwad Mar 18, 2025
1dcf083
Sign return address while restoring it in unhijacking a thread
SwapnilGaikwad Mar 18, 2025
618b79c
Merge main
SwapnilGaikwad Mar 19, 2025
25c7f72
Fix build errors
SwapnilGaikwad Mar 19, 2025
1e6b5b6
Fix build errors
SwapnilGaikwad Mar 19, 2025
6aebd8b
Fix build errors for casting
SwapnilGaikwad Mar 19, 2025
b230513
Fix build errors
SwapnilGaikwad Mar 19, 2025
b9802ed
Merge main
SwapnilGaikwad Mar 31, 2025
9c216f5
Put dwarf cfi code for pac
SwapnilGaikwad Apr 9, 2025
f5b6ffa
Add a placeholder for OSX ObjectWriter
SwapnilGaikwad Apr 10, 2025
57112e3
Merge main
SwapnilGaikwad Apr 13, 2025
7d92dae
Add DEF_CFA opcode for ilc
SwapnilGaikwad Apr 13, 2025
6ef4025
Fix formatting
SwapnilGaikwad Apr 13, 2025
03cde20
Merge main
SwapnilGaikwad Apr 16, 2025
beb7829
Merge main
SwapnilGaikwad Apr 17, 2025
8e1a725
Enable PAC for non-jitted code
SwapnilGaikwad Apr 17, 2025
fb3ab0e
Merge main
SwapnilGaikwad Apr 24, 2025
457dd89
Intial clean-up: use xpacia instead of a mask
SwapnilGaikwad Apr 24, 2025
a17e8ba
Merge main
SwapnilGaikwad Apr 28, 2025
268a895
Clean-up inline assembly
SwapnilGaikwad Apr 28, 2025
526b7c2
Remove PAC for non-jitted code, added using compile time flags
SwapnilGaikwad Apr 28, 2025
711d1fc
Fix windows build errors
SwapnilGaikwad Apr 28, 2025
a99f639
Fix build errors
SwapnilGaikwad Apr 28, 2025
eefb18b
Update strip/sign mechanism to use nop variants of PAC instructions
SwapnilGaikwad May 1, 2025
8e087f5
Merge main
SwapnilGaikwad May 1, 2025
a1298d7
Merge main
SwapnilGaikwad May 15, 2025
36f166e
Incorporate review comments
SwapnilGaikwad May 15, 2025
989ff17
Merge main
SwapnilGaikwad May 16, 2025
05f8731
Incorporate review comments
SwapnilGaikwad May 16, 2025
260a807
Merge main
SwapnilGaikwad May 19, 2025
526717a
Disable JitPacEnabled flag by default
SwapnilGaikwad May 19, 2025
2c81d43
Merge main
SwapnilGaikwad Jun 12, 2025
7b552e5
Use unwind info to detect if PAC is present for jitted code
SwapnilGaikwad Jun 12, 2025
f36e335
Fix assert failure for return address
SwapnilGaikwad Jun 12, 2025
a862791
Make IsPacPresent() Arm64 only
SwapnilGaikwad Jun 12, 2025
8f5b485
Fix build errors
SwapnilGaikwad Jun 12, 2025
e7bc0fa
Fix build errors
SwapnilGaikwad Jun 13, 2025
f53b929
Add a prototype of using unwind info to detect PAC
SwapnilGaikwad Jun 22, 2025
82b0709
Merge main
SwapnilGaikwad Jun 22, 2025
7e207a4
Merge main
SwapnilGaikwad Jun 27, 2025
52f63d8
Extract IsPacPresent() outside the undwinder.cpp
SwapnilGaikwad Jun 27, 2025
79a3fbc
Remove clrnt.h changes
SwapnilGaikwad Jun 29, 2025
e1ba37b
Address review comments
SwapnilGaikwad Jun 29, 2025
75316bc
Fix starting offset while unwinding dwarf info
SwapnilGaikwad Jul 2, 2025
c9f8bd1
Fix build failures of MacOS
SwapnilGaikwad Jul 2, 2025
b8574ab
Merge main
SwapnilGaikwad Jul 7, 2025
333b5b2
Fix SIGILL in NativeAOT during unwinding
SwapnilGaikwad Jul 7, 2025
cecc9f4
Fix segfaults in libraries tests
SwapnilGaikwad Jul 7, 2025
34401fb
Restore JIT's stack unwinding that was lost while restoring unwinder.cpp
SwapnilGaikwad Jul 7, 2025
0bc660e
Merge main
SwapnilGaikwad Jul 11, 2025
3c00fb6
Merge main
SwapnilGaikwad Oct 6, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@ private static unsafe void DispatchTailCalls(
IntPtr callersRetAddr;
TailCallTls* tls = GetTailCallInfo(callersRetAddrSlot, &callersRetAddr);
PortableTailCallFrame* prevFrame = tls->Frame;
if (callersRetAddr == prevFrame->TailCallAwareReturnAddress)
// TODO-PAC: Implement stripping of PAC from return addresses in coreclr
if ((callersRetAddr & 0x0000FFFFFFFFFFFF) == (prevFrame->TailCallAwareReturnAddress & 0x0000FFFFFFFFFFFF))
{
prevFrame->NextCall = callTarget;
return;
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@ void CodeGen::genPopCalleeSavedRegistersAndFreeLclFrame(bool jmpEpilog)
GetEmitter()->emitIns_R_R_I(INS_add, EA_PTRSIZE, REG_SPBASE, REG_SPBASE, spAdjust);
compiler->unwindAllocStack(spAdjust);
}

// TODO-PAC: emit autiasp
GetEmitter()->emitIns(INS_autiaz);
//compiler->unwindPacSignLR();
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -523,6 +527,11 @@ void CodeGen::genPrologSaveRegPair(regNumber reg1,
compiler->unwindSaveRegPair(reg1, reg2, spOffset);
}
}

if (reg2 == REG_LR)
{
compiler->unwindPacSignLR();
}
}

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1398,6 +1407,10 @@ void CodeGen::genFuncletProlog(BasicBlock* block)

compiler->unwindBegProlog();

// Sign LR as part of Pointer Authentication (PAC) support
GetEmitter()->emitIns(INS_paciaz);
compiler->unwindPacSignLR();

regMaskTP maskSaveRegsFloat = genFuncletInfo.fiSaveRegs & RBM_ALLFLOAT;
regMaskTP maskSaveRegsInt = genFuncletInfo.fiSaveRegs & ~maskSaveRegsFloat;

Expand Down Expand Up @@ -1721,6 +1734,10 @@ void CodeGen::genFuncletEpilog()
}
}

// TODO-PAC: emit autiasp
GetEmitter()->emitIns(INS_autiaz);
//compiler->unwindPacSignLR();

inst_RV(INS_ret, REG_LR, TYP_I_IMPL);
compiler->unwindReturn(REG_LR);

Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4744,6 +4744,10 @@ void CodeGen::genPushCalleeSavedRegisters()
}
#endif // DEBUG

// Sign LR as part of Pointer Authentication (PAC) support
GetEmitter()->emitIns(INS_paciaz);
compiler->unwindPacSignLR();

// The frameType number is arbitrary, is defined below, and corresponds to one of the frame styles we
// generate based on various sizes.
int frameType = 0;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8949,6 +8949,7 @@ class Compiler
void unwindSaveRegPair(regNumber reg1, regNumber reg2, int offset); // stp reg1, reg2, [sp, #offset]
void unwindSaveRegPairPreindexed(regNumber reg1, regNumber reg2, int offset); // stp reg1, reg2, [sp, #offset]!
void unwindSaveNext(); // unwind code: save_next
void unwindPacSignLR(); // unwind code: pac_sign_lr
void unwindReturn(regNumber reg); // ret lr
#endif // defined(TARGET_ARM64)

Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/jit/unwindarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,31 @@ void Compiler::unwindSaveNext()
pu->AddCode(0xE6);
}

void Compiler::unwindPacSignLR()
{
#if defined(FEATURE_CFI_SUPPORT)
if (generateCFIUnwindCodes())
{
FuncInfoDsc* func = funCurrentFunc();
UNATIVE_OFFSET cbProlog = 0;
if (compGeneratingProlog)
{
cbProlog = unwindGetCurrentOffset(func);
}

// DW_CFA_GNU_window_save 0x2D
createCfiCode(func, cbProlog, CFI_DEF_CFA_REGISTER, DWARF_REG_ILLEGAL);

return;
}
#endif // FEATURE_CFI_SUPPORT

assert(compGeneratingProlog);

// pac_sign_lr: 11111100: sign the return address in lr with pacibsp
funCurrentFunc()->uwi.AddCode(0xFC);
}

void Compiler::unwindReturn(regNumber reg)
{
// Nothing to do; we will always have at least one trailing "end" opcode in our padding.
Expand Down Expand Up @@ -1081,6 +1106,12 @@ void DumpUnwindInfo(Compiler* comp,

printf(" %02X save_next\n", b1);
}
else if (b1 == 0xFC)
{
// pac_sign_lr: 11111100 : sign the return address in lr with pacibsp.

printf(" %02X pac_sign_lr\n", b1);
}
else
{
// Unknown / reserved unwind code
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/unwinder/arm64/unwinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ do {
#if !defined(DEBUGGER_STRIP_PAC)

// NOTE: Pointer authentication is not used by .NET, so the implementation does nothing
#define STRIP_PAC(Params, pointer)
#define STRIP_PAC(pointer) *pointer &= 0x0000FFFFFFFFFFFF

#endif

Expand Down Expand Up @@ -2335,15 +2335,15 @@ Return Value:
}

//
// pac (11111100): function has pointer authentication
// pac (11111100): function has pointer authentication
//

else if (CurCode == 0xfc) {
if (AccumulatedSaveNexts != 0) {
return STATUS_UNWIND_INVALID_SEQUENCE;
}

STRIP_PAC(UnwindParams, &ContextRecord->Lr);
STRIP_PAC(&ContextRecord->Lr);

//
// TODO: Implement support for UnwindFlags RTL_VIRTUAL_UNWIND2_VALIDATE_PAC.
Expand Down
Loading