Skip to content

Commit 043436d

Browse files
committed
Using global variable in xnu kernel, set # of addressable bits
The kernel has a global variable with the TCR_EL1.T1SZ value, from which was can calculate the number of addressable bits. Find that symbol in DynamicLoaderDarwinKernel and set the bits to that value for this Process. Differential Revision: https://reviews.llvm.org/D147462 rdar://107445318 (cherry picked from commit 8b09271)
1 parent 096db03 commit 043436d

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

lldb/source/Plugins/DynamicLoader/Darwin-Kernel/DynamicLoaderDarwinKernel.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() {
10111011

10121012
if (m_kernel.IsLoaded() && m_kernel.GetModule()) {
10131013
static ConstString kext_summary_symbol("gLoadedKextSummaries");
1014+
static ConstString arm64_T1Sz_value("gT1Sz");
10141015
const Symbol *symbol =
10151016
m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
10161017
kext_summary_symbol, eSymbolTypeData);
@@ -1019,6 +1020,36 @@ void DynamicLoaderDarwinKernel::LoadKernelModuleIfNeeded() {
10191020
// Update all image infos
10201021
ReadAllKextSummaries();
10211022
}
1023+
// If the kernel global with the T1Sz setting is available,
1024+
// update the target.process.virtual-addressable-bits to be correct.
1025+
symbol = m_kernel.GetModule()->FindFirstSymbolWithNameAndType(
1026+
arm64_T1Sz_value, eSymbolTypeData);
1027+
if (symbol) {
1028+
const uint32_t orig_bits_value = m_process->GetVirtualAddressableBits();
1029+
// Mark all bits as addressable so we don't strip any from our
1030+
// memory read below, with an incorrect default value.
1031+
// b55 is the sign extension bit with PAC, b56:63 are TBI,
1032+
// don't mark those as addressable.
1033+
m_process->SetVirtualAddressableBits(55);
1034+
Status error;
1035+
// gT1Sz is 8 bytes. We may run on a stripped kernel binary
1036+
// where we can't get the size accurately. Hardcode it.
1037+
const size_t sym_bytesize = 8; // size of gT1Sz value
1038+
uint64_t sym_value =
1039+
m_process->GetTarget().ReadUnsignedIntegerFromMemory(
1040+
symbol->GetAddress(), sym_bytesize, 0, error);
1041+
if (error.Success()) {
1042+
// 64 - T1Sz is the highest bit used for auth.
1043+
// The value we pass in to SetVirtualAddressableBits is
1044+
// the number of bits used for addressing, so if
1045+
// T1Sz is 25, then 64-25 == 39, bits 0..38 are used for
1046+
// addressing, bits 39..63 are used for PAC/TBI or whatever.
1047+
uint32_t virt_addr_bits = 64 - sym_value;
1048+
m_process->SetVirtualAddressableBits(virt_addr_bits);
1049+
} else {
1050+
m_process->SetVirtualAddressableBits(orig_bits_value);
1051+
}
1052+
}
10221053
} else {
10231054
m_kernel.Clear();
10241055
}

0 commit comments

Comments
 (0)