Unexporting kallsyms_lookup_name()
Unexporting kallsyms_lookup_name()
Posted Sep 2, 2021 18:33 UTC (Thu) by VojtaK (guest, #154079)Parent article: Unexporting kallsyms_lookup_name()
First I downloaded a fresh new package amdgpu-pro-21.10-1247438-ubuntu-20.04 from AMD. Well its not for Debian, but Debian is brand new so I was thinking I could run it there. Not really easy!
First they decided to support ubuntu-20.04 with kernel 5.8 and Debian 11 is shipped with 5.10. When my attempts to build their amdgpu module failed multiple times, I decided to downgrade and compile 5.9x, 5.8x kernels on my own.
I also would like to mention that 5.7x kernel was the last one, where "mmap_sem" was not called "mmap_lock" in mm_types.h https://lore.kernel.org/linux-mm/20200422001422.232330-11...
So I had to change inside amdgpu-dkms_5.9.20.104-1247438_all.deb find . -type f | xargs sed -i "s/mmap_sem/mmap_lock/g"
And to be able to retain the distribution kernel I also needed to add BUILD_EXCLUSIVE_KERNEL="^(5\.[0-9]\.)" to usr/src/amdgpu-5.9.20.104-1247438/dkms.conf
Well everything installed, module compiled, but it was not working. In my dmesg there was cryptic message
kernel BUG at /var/lib/dkms/amdgpu/5.9.20.104-1247438/build/amd/amdkcl/kcl_common.c:44!
Let's have a look to that source
void amdkcl_symbol_init(void)
{
#ifndef HAVE_KALLSYMS_LOOKUP_NAME
struct kprobe kp;
int r;
memset(&kp, 0, sizeof(kp));
kp.symbol_name = "kallsyms_lookup_name";
r = register_kprobe(&kp);
if (!r) {
_kcl_kallsyms_lookup_name = (void *)kp.addr;
unregister_kprobe(&kp);
} else {
pr_err("fail to get kallsyms_lookup_name, abort...\n");
BUG();
}
#else
_kcl_kallsyms_lookup_name = kallsyms_lookup_name;
#endif
}
This is a code from AMD! Exploiting another way to get to that function. Maybe you shall remove it altogether because the only thing you achieved that a big player who bundles his closed source firmware into the kernel use this exploit and I spent a 48 hours of my work figuring out that it does not work in my use case producing that BUG!
So finally I am forced either to downgrade to <3.7 kernel or to add EXPORT_SYMBOL_GPL(kallsyms_lookup_name); to kallsyms.c and hope that they parse well that macro to define HAVE_KALLSYMS_LOOKUP_NAME to have it running in 3.9 kernel. Because in 3.10 its broken also from another reason.
