[lldb][Process/FreeBSDKernelCore] Set kernel displacement#183975
[lldb][Process/FreeBSDKernelCore] Set kernel displacement#183975
Conversation
|
@llvm/pr-subscribers-lldb Author: Minsoo Choo (mchoo7) ChangesWhen KASLR is enabled, the address passed through Full diff: https://github.com/llvm/llvm-project/pull/183975.diff 2 Files Affected:
diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
index 577d8e0d50cf1..0217177c87dbd 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
@@ -118,6 +118,8 @@ bool ProcessFreeBSDKernelCore::CanDebug(lldb::TargetSP target_sp,
Status ProcessFreeBSDKernelCore::DoLoadCore() {
// The core is already loaded by CreateInstance().
+ ApplyKASLR();
+
return Status();
}
@@ -324,6 +326,28 @@ lldb::addr_t ProcessFreeBSDKernelCore::FindSymbol(const char *name) {
return sym ? sym->GetLoadAddress(&GetTarget()) : LLDB_INVALID_ADDRESS;
}
+void ProcessFreeBSDKernelCore::ApplyKASLR() {
+ kssize_t displacement = kvm_kerndisp(m_kvm);
+
+ if (displacement == 0)
+ return;
+
+ Target &target = GetTarget();
+ lldb::ModuleSP kernel_module_sp = target.GetExecutableModule();
+ if (!kernel_module_sp)
+ return;
+
+ bool changed = false;
+ kernel_module_sp->SetLoadAddress(
+ target, static_cast<lldb::addr_t>(displacement), true, changed);
+
+ if (changed) {
+ ModuleList loaded_module_list;
+ loaded_module_list.Append(kernel_module_sp);
+ target.ModulesDidLoad(loaded_module_list);
+ }
+}
+
void ProcessFreeBSDKernelCore::PrintUnreadMessage() {
Target &target = GetTarget();
Debugger &debugger = target.GetDebugger();
diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h
index 67cfae13d2a4d..92ddec4696066 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h
@@ -64,6 +64,8 @@ class ProcessFreeBSDKernelCore : public lldb_private::PostMortemProcess {
lldb::addr_t FindSymbol(const char *name);
private:
+ void ApplyKASLR();
+
void PrintUnreadMessage();
const char *GetError();
|
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
DavidSpickett
left a comment
There was a problem hiding this comment.
I'll let some FreeBSD person be the approver here.
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
🐧 Linux x64 Test Results
✅ The build succeeded and all tests passed. |
|
I don't think that we have KASLR. kvm_kerndisp is just compile time offset. |
Right, I just saw the commit messgae of freebsd/freebsd-src@38cf2a4. Update PR title and description and removed relnotes changes. |
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
No? It's 0 for all architectures except PowerPC, which defines RELOCATABLE_KERNEL and has special code in sys/kern/link_elf.c such that kern.base_address and kern.relbase_address are not the same value (and is the only architecture with a non-NULL ka_kerndisp hook for kernel dump parsing). |
lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
jrtc27
left a comment
There was a problem hiding this comment.
Ok to me subject to resolving the comments. Might also be nice to elaborate a bit in the summary to mention that PowerPC is the only supported architecture this can be non-zero for, as context?
lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
Outdated
Show resolved
Hide resolved
lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
Outdated
Show resolved
Hide resolved
Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
Use
kvm_kerndisp()on core load to retrieve the kernel displacement, that is the difference between the kernel'sbase virtual address at run time and the kernel base virtual address specified in the kernel image file. Currently PowerPC is the only architecture supporting kernel displacement.