All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Anderson <anderson@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Andrew Jones <drjones@redhat.com>,
	bhe@redhat.com, Dave Young <dyoung@redhat.com>,
	qemu-devel@nongnu.org, qiaonuohan@cn.fujitsu.com,
	lersek@redhat.com
Subject: Re: [Qemu-devel] virsh dump (qemu guest memory dump?): KASLR enabled linux guest support
Date: Tue, 15 Nov 2016 09:41:48 -0500 (EST)	[thread overview]
Message-ID: <1751581928.15336894.1479220908854.JavaMail.zimbra@redhat.com> (raw)
In-Reply-To: <e229f31c-ea32-cf94-8769-5e3e496316f9@redhat.com>



----- Original Message -----
> 
> 
> On 09/11/2016 16:28, Dave Anderson wrote:
> > I'm not sure whether this "guest userspace agent" is still in play here,
> > but if there were such a thing, it could theoretically do the same
> > thing that crash currently does when running on a live system.
> > 
> > Both of those are available or calculatable from the contents of
> > a kdump header.  However, on a live system, it's done like this:
> > 
> > - /proc/kallsyms is queried for the symbol value of "_text", which would
> >   be relocated if KASLR is in play.  That value is compared against the
> >   "_text" symbol value compiled into the vmlinux file to determine the
> >   relocation value generated by CONFIG_RANDOMIZE_BASE.
> > 
> > [...] in order to read kernel symbols from the
> > statically-mapped kernel region based at __START_KERNEL_map, it
> > translates a (possibly relocated) kernel virtual address into a
> > physical address like this:
> > 
> >   physical-address = virtual-address - __START_KERNEL_map + phys_base
> > 
> > But it's a chicken-and-egg deal, because the contents of the "phys_base"
> > symbol are needed to calculate the physical address, but it can't
> > read the "phys_base" symbol contents without first knowing its contents.
> > 
> > So on a live system, the "phys_base" is calculated by reading
> > the "Kernel Code:" value from /proc/iomem, and then doing this:
> > 
> >   phys_base = [Kernel Code: value] - ["_text" symbol value] - __START_KERNEL_map
>                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Should there be parentheses around this?  

Yes, sorry, that's correct -- that's what the code does, and what I meant to express...

Dave


> The physical-address formula above is equivalent to
> 
>     phys_base = physical-address - (virtual-address - __START_KERNEL_map)
> 
> > 
> > So theoretically, the guest agent could read /proc/iomem and /proc/kallsyms
> > for the information required.  (I think...)
> 
> Then yes, the guest-agent could add a command get-kernel-text-start with an output like:
> 
> { 'virtual': 0xffffffff86000000, 'physical': 0xb6000000 }
> 
> and libvirt can expose it to crash.  In this case, phys_base would be 0xb0000000
> if I did the math right, and the relocation value is obtained by comparing the
> "virtual" address with the vmlinux "_text".
> 
> IIRC the guest agent runs as root, so reading /proc/iomem is not a problem.
> 
> Paolo
> 

  reply	other threads:[~2016-11-15 14:42 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-09  3:01 [Qemu-devel] virsh dump (qemu guest memory dump?): KASLR enabled linux guest support Dave Young
2016-11-09  3:17 ` Dave Young
2016-11-09  3:58   ` Wen Congyang
2016-11-09  5:02     ` Dave Young
2016-11-09  7:42       ` Wen Congyang
2016-11-09  8:25         ` Dave Young
2016-11-09 14:36       ` Dave Anderson
2016-11-09 14:42         ` Daniel P. Berrange
2016-11-09 10:40 ` Andrew Jones
2016-11-09 11:26   ` Laszlo Ersek
2016-11-09 11:37     ` Daniel P. Berrange
2016-11-09 11:48       ` Andrew Jones
2016-11-09 11:58         ` Daniel P. Berrange
2016-11-09 12:20           ` Andrew Jones
2016-11-09 14:47             ` Daniel P. Berrange
2016-11-09 15:38               ` Laszlo Ersek
2016-11-09 16:01                 ` Daniel P. Berrange
2016-11-14 10:27                   ` Paolo Bonzini
2016-11-14  5:32                 ` Dave Young
2016-11-14  9:47                   ` Andrew Jones
2016-11-16  2:48                     ` Dave Young
2016-11-14 10:10                   ` Daniel P. Berrange
2016-11-14 10:28                     ` Paolo Bonzini
2016-11-14 10:33                       ` Daniel P. Berrange
2016-11-14 11:08                         ` Laszlo Ersek
2016-11-14 11:55                         ` Paolo Bonzini
2016-11-09 15:28   ` Dave Anderson
2016-11-14 10:41     ` Paolo Bonzini
2016-11-15 14:41       ` Dave Anderson [this message]
2016-11-09 14:32 ` Dave Anderson

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=1751581928.15336894.1479220908854.JavaMail.zimbra@redhat.com \
    --to=anderson@redhat.com \
    --cc=bhe@redhat.com \
    --cc=drjones@redhat.com \
    --cc=dyoung@redhat.com \
    --cc=lersek@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qiaonuohan@cn.fujitsu.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.