You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TT_ENTRY_COUNT >> -4 — right-shifting by a negative amount is undefined behavior in C (ISO/IEC 9899:2011 §6.5.7p3).
Bug 2 — Wrong EntryCount for the level-(-1) root table
Even after patching the UB, the formula TT_ENTRY_COUNT >> shift is architecturally incorrect for the level-(-1) root table. The ARM Architecture Reference Manual (D8.1.8) specifies that for 5-level paging with T0SZ=12 (52-bit VA), the root table has a 4-bit index (bits [51:48]) = 16 entries. The shift-based formula cannot correctly derive this.
Passing the wrong EntryCount to TT_LAST_BLOCK_ADDRESS() causes pointer underflow, and ParsePageTableLevel() then walks garbage page table entries — causing CheckPageAccess() / IsPageReadable() / IsPageWritable() to silently return wrong results on any system with T0SZ < 16.
Proposed Fix
Rework TableLevel/EntryCount into an explicit if/else that correctly handles each case:
Summary
Commit
aee730d(PR #158 — "Fix aarch64 page table parsing for 5 level paging") introduced two related bugs inCheckPageAccess()insideDebuggerFeaturePkg/Library/DebugAgent/AARCH64/DebugAarch64.c.Affected File
DebuggerFeaturePkg/Library/DebugAgent/AARCH64/DebugAarch64.c—CheckPageAccess(), lines 408–409Bug 1 — C Undefined Behavior: right-shift by negative amount
Code (current)
When
T0SZ < MIN_T0SZ(5-level paging, e.g.T0SZ=12):T0SZandMIN_T0SZare bothUINTN.T0SZ - MIN_T0SZwraps to a large unsigned value (e.g.0xFFFFFFFFFFFFFFFC).(INTN)(0xFFFFFFFFFFFFFFFC)= -4.(-4) % BITS_PER_LEVEL= -4 (C99 truncation toward zero).TT_ENTRY_COUNT >> -4— right-shifting by a negative amount is undefined behavior in C (ISO/IEC 9899:2011 §6.5.7p3).Bug 2 — Wrong EntryCount for the level-(-1) root table
Even after patching the UB, the formula
TT_ENTRY_COUNT >> shiftis architecturally incorrect for the level-(-1) root table. The ARM Architecture Reference Manual (D8.1.8) specifies that for 5-level paging withT0SZ=12(52-bit VA), the root table has a 4-bit index (bits [51:48]) = 16 entries. The shift-based formula cannot correctly derive this.Passing the wrong
EntryCounttoTT_LAST_BLOCK_ADDRESS()causes pointer underflow, andParsePageTableLevel()then walks garbage page table entries — causingCheckPageAccess()/IsPageReadable()/IsPageWritable()to silently return wrong results on any system withT0SZ < 16.Proposed Fix
Rework
TableLevel/EntryCountinto an explicitif/elsethat correctly handles each case:Verification
All arithmetic is on
UINTNwith no signed shifts and no negative values.Impact
T0SZ < 16, 52-bit VA)IsPageReadable()/IsPageWritable()return incorrect values, potentially allowing or blocking debugger memory access based on garbage page table attributesaee730dReferences