Skip to contentSkip to conversation

docs: disable KASLR when debugging kernel

PATCH Superseded Zhouyi Zhou 2 participants 3 messages Jul 7, 2017

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 2/2 docs: disable KASLR when debugging kernel

commit 6807c84652b0 ("x86: Enable KASLR by default") enables KASLR by default on x86. While KASLR will confuse gdb which resolve kernel symbol address from symbol table of vmlinux. We should turn off KASLR for kernel debugging.

---
 Documentation/dev-tools/gdb-kernel-debugging.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/dev-tools/gdb-kernel-debugging.rst +4 -2
index 5e93c9b..fe2edcc 100644
@@ -31,12 +31,13 @@ Setup
   CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports
   CONFIG_FRAME_POINTER, keep it enabled.
 
-- Install that kernel on the guest.
+- Install that kernel on the guest, turn off KASLR by adding "nokaslr" to
+  the kernel command line .
   Alternatively, QEMU allows to boot the kernel directly using -kernel,
   -append, -initrd command line switches. This is generally only useful if
   you do not depend on modules. See QEMU documentation for more details on
-  this mode.
+  this mode. In this case, you should build the kernel with
+  CONFIG_RANDOMIZE_BASE disabled.
 
 - Enable the gdb stub of QEMU/KVM, either
 
Signature · 1 line
1.9.1
Reviewed-by on v1 2/2
#1 lore raw

Hi Zhouyi

Thankyou for the patch,

Quoted 4 lines · Zhouyi Zhou

commit 6807c84652b0 ("x86: Enable KASLR by default") enables KASLR by default on x86. While KASLR will confuse gdb which resolve kernel symbol address from symbol table of vmlinux. We should turn off KASLR for kernel debugging.

Yes, this is something I had come across and certainly should be documented.

Quoted 10 lines
---
 Documentation/dev-tools/gdb-kernel-debugging.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/dev-tools/gdb-kernel-debugging.rst +0 -0
index 5e93c9b..fe2edcc 100644

Documentation/dev-tools/gdb-kernel-debugging.rst Setup · line 35

Quoted 6 lines
Documentation/dev-tools/gdb-kernel-debugging.rst +2 -1
@@ -31,12 +31,13 @@ Setup
   CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports
   CONFIG_FRAME_POINTER, keep it enabled.
 
-- Install that kernel on the guest.
+- Install that kernel on the guest, turn off KASLR by adding "nokaslr" to
+  the kernel command line .

Is KASLR available on *all* supported architectures?

If not, then perhaps this should be "turn off KASLR if necessary by ..." But I don't think that's a big deal really.

Documentation/dev-tools/gdb-kernel-debugging.rst Setup · line 43

Quoted 9 lines
Documentation/dev-tools/gdb-kernel-debugging.rst +2 -1
   Alternatively, QEMU allows to boot the kernel directly using -kernel,
   -append, -initrd command line switches. This is generally only useful if
   you do not depend on modules. See QEMU documentation for more details on
-  this mode.
+  this mode. In this case, you should build the kernel with
+  CONFIG_RANDOMIZE_BASE disabled.
 
 - Enable the gdb stub of QEMU/KVM, either
 

--
Kieran

#2 lore raw

Hi Kieran,
Thanks for your review and invaluable advise, I will prepare a new
version immediately.

Quoted 47 lines · Kieran Bingham

Hi Zhouyi

Thankyou for the patch,

Quoted 4 lines · Zhouyi Zhou

commit 6807c84652b0 ("x86: Enable KASLR by default") enables KASLR by default on x86. While KASLR will confuse gdb which resolve kernel symbol address from symbol table of vmlinux. We should turn off KASLR for kernel debugging.

Yes, this is something I had come across and certainly should be documented.

Quoted 10 lines
---
 Documentation/dev-tools/gdb-kernel-debugging.rst | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/dev-tools/gdb-kernel-debugging.rst +0 -0
index 5e93c9b..fe2edcc 100644

Documentation/dev-tools/gdb-kernel-debugging.rst Setup · line 35

Quoted 6 lines
Documentation/dev-tools/gdb-kernel-debugging.rst +2 -1
@@ -31,12 +31,13 @@ Setup
   CONFIG_DEBUG_INFO_REDUCED off. If your architecture supports
   CONFIG_FRAME_POINTER, keep it enabled.
 
-- Install that kernel on the guest.
+- Install that kernel on the guest, turn off KASLR by adding "nokaslr" to
+  the kernel command line .

Is KASLR available on *all* supported architectures?

If not, then perhaps this should be "turn off KASLR if necessary by ..." But I don't think that's a big deal really.

Documentation/dev-tools/gdb-kernel-debugging.rst Setup · line 43

Quoted 9 lines
Documentation/dev-tools/gdb-kernel-debugging.rst +2 -1
   Alternatively, QEMU allows to boot the kernel directly using -kernel,
   -append, -initrd command line switches. This is generally only useful if
   you do not depend on modules. See QEMU documentation for more details on
-  this mode.
+  this mode. In this case, you should build the kernel with
+  CONFIG_RANDOMIZE_BASE disabled.
 
 - Enable the gdb stub of QEMU/KVM, either
 

--
Kieran