While running crash on KASLR enabled live arm64 kernels I noticed
that the crash would fail after printing the following error messages
if it cannot find vmlinux for the boot'ed system:

crash: invalid kernel virtual address: 8470  type: "possible"
WARNING: cannot read cpu_possible_map
crash: invalid kernel virtual address: 8270  type: "present"
WARNING: cannot read cpu_present_map
crash: invalid kernel virtual address: 8070  type: "online"
WARNING: cannot read cpu_online_map
crash: invalid kernel virtual address: 8670  type: "active"
WARNING: cannot read cpu_active_map

crash: cannot resolve "_stext"

Since vmlinux is not available at the standard expected location, i.e
'/usr/lib/debug/lib/modules/<kernel-version>' directory, so
_stext_vmlinux stays UNINITIALIZED inside 'derive_kaslr_offset()'
and 'relocate' becomes 0.

Later-on this can lead to 'cannot resolve "_stext"' error in
'symbol_value()' function.

We can go ahead and fix the same, but ideally since we are running
on a live system, we should be finding the vmlinux at the standard
location, otherwise we should do proper error handling.

So this patch errors out earlier, if we don't find a valid value for
'_stext_vmlinux' and prompts the user to refer to the 'usage'
banner.

Signed-off-by: Bhupesh Sharma <bhsha...@redhat.com>
---
 symbols.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/symbols.c b/symbols.c
index 4db9af7bf044..30669950635d 100644
--- a/symbols.c
+++ b/symbols.c
@@ -663,6 +663,24 @@ derive_kaslr_offset(bfd *abfd, int dynamic, bfd_byte 
*start, bfd_byte *end,
                        return;
        }
 
+       /* For KASLR enabled live kernels, if vmlinux is not available
+        * at the standard expected location, i.e
+        * '/usr/lib/debug/lib/modules/<kernel-version>' directory,
+        * then _stext_vmlinux will be set to NULL or UNINITIALIZED.
+        *
+        * Later-on this may lead to "_stext" symbol not being resolved
+        * properly (which may lead to an ambiguous error message).
+        *
+        * So, error out earlier here itself, in case _stext_vmlinux
+        * is NULL or UNINITIALIZED.
+        */
+       if (!st->_stext_vmlinux || (st->_stext_vmlinux == UNINITIALIZED)) {
+               error(INFO, "_stext not found in vmlinux :\n"
+                     "   if running a live system -- please provide a suitable 
vmlinux,\n"
+                     "   otherwise -- please enter namelist argument.\n");
+               program_usage(SHORT_FORM);
+       }
+
        /*
         * To avoid mistaking an mismatched kernel version with
         * a kaslr offset, we make sure that the offset is
-- 
2.7.4

--
Crash-utility mailing list
Crash-utility@redhat.com
https://www.redhat.com/mailman/listinfo/crash-utility

Reply via email to