kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: valdis.kletnieks@vt.edu (valdis.kletnieks at vt.edu)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Decoding Stack from kernel OOPS message
Date: Tue, 13 Feb 2018 10:49:38 -0500	[thread overview]
Message-ID: <10555.1518536978@turing-police.cc.vt.edu> (raw)
In-Reply-To: <CAJs94Eaaz5zFo6dkoHwBpzbUwbJGEBCVCkxHNFCc25y54VxChA@mail.gmail.com>

On Tue, 13 Feb 2018 14:47:32 +0300, "Matwey V. Kornilov" said:

> Well, It is not clear to me. First, what is the purpose to dump the
> stack? Second, when I use gdb with ordinary user-space applications,
> then for every execution step I can do commands to print variables or
> expressions. It is obvious that gdb has mapping between variables in
> the source code and memory/register locations for any specific step.
> Isn't this mapping derivable from debug info?

There's two places that the info can be found - when the kernel splats
the error message into the dmesg buffer, and in userspace when you're
looking at the wreckage.

Note that the info you're looking at is in a file on disk - and thus off-limits
to the kernel. Doing file I/O inside the kernel is ugly enough, but doing it
while processing an error condition is totally beyond the pale (it's able to
unwind the function names from the stack traceback because *that* info
is already loaded into memory for many configurations of the kernel).

The second time is when you're looking at gdb after the fact - at which point
you need to worry about stuff like KALSR and so on.  Also, you're no longer
looking at a live stack in memory, you're looking at the output of a bunch of
printf statements - that adds to the challenge.

Have you looked at using objdump?  You'll need to figure out which .o/.ko has
the function in it, but then.  (As always figuring out what asm lines up with what
C code is left as an exercise for the programmer, but 90% of the time once you
know what register has the bad value in it, you can work backwards to either
a global variable or a value passed in a function parameter).

[/usr/src/linux-next] objdump -d arch/x86/lib/usercopy_64.o | head -20

arch/x86/lib/usercopy_64.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <__clear_user>:
   0:	e8 00 00 00 00       	callq  5 <__clear_user+0x5>
   5:	55                   	push   %rbp
   6:	48 89 e5             	mov    %rsp,%rbp
   9:	41 54                	push   %r12
   b:	49 89 fc             	mov    %rdi,%r12
   e:	48 c7 c7 00 00 00 00 	mov    $0x0,%rdi
  15:	53                   	push   %rbx
  16:	48 89 f3             	mov    %rsi,%rbx
  19:	be 13 00 00 00       	mov    $0x13,%esi
  1e:	e8 00 00 00 00       	callq  23 <__clear_user+0x23>
  23:	90                   	nop
  24:	90                   	nop
  25:	90                   	nop

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 486 bytes
Desc: not available
URL: <http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20180213/8ac3186e/attachment.sig>

      reply	other threads:[~2018-02-13 15:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13  9:40 Decoding Stack from kernel OOPS message Matwey V. Kornilov
2018-02-13 10:03 ` Denis Kirjanov
2018-02-13 11:47   ` Matwey V. Kornilov
2018-02-13 15:49     ` valdis.kletnieks at vt.edu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=10555.1518536978@turing-police.cc.vt.edu \
    --to=valdis.kletnieks@vt.edu \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).