From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH v2 2/2] x86/traps: Dump instruction stream in show_execution_state()
Date: Thu, 11 Feb 2016 13:41:33 +0000 [thread overview]
Message-ID: <56BC8F8D.7070208@citrix.com> (raw)
In-Reply-To: <56BC921002000078000D102F@prv-mh.provo.novell.com>
On 11/02/16 12:52, Jan Beulich wrote:
>>>> On 11.02.16 at 13:12, <andrew.cooper3@citrix.com> wrote:
>> On 11/02/16 11:16, Jan Beulich wrote:
>>>>>> On 11.02.16 at 11:52, <andrew.cooper3@citrix.com> wrote:
>>>> --- a/xen/arch/x86/traps.c
>>>> +++ b/xen/arch/x86/traps.c
>>>> @@ -114,6 +114,56 @@ boolean_param("ler", opt_ler);
>>>> #define stack_words_per_line 4
>>>> #define ESP_BEFORE_EXCEPTION(regs) ((unsigned long *)regs->rsp)
>>>>
>>>> +static void show_code(const struct cpu_user_regs *regs)
>>>> +{
>>>> + unsigned char insns_before[8], insns_after[16];
>>>> + unsigned int i, missing_before, missing_after;
>>>> +
>>>> + if ( guest_mode(regs) )
>>>> + return;
>>>> +
>>>> + /*
>>>> + * This dance with {insns,missing}_{before,after} is to ensure that, if
>>>> + * %rip -8/+16 wraps around a bounday, we read a non-wrapped regs->rip
>>>> + * pointer, and calculate which bytes were not read so they may be
>>>> + * replaced with dashes in the printed output.
>>>> + */
>>>> + missing_before = __copy_from_user(
>>>> + insns_before, (void __user *)regs->rip - 8, ARRAY_SIZE(insns_before));
>>>> + missing_after = __copy_from_user(
>>>> + insns_after, (void __user *)regs->rip, ARRAY_SIZE(insns_after));
>>> ... iirc __copy_from_user() doesn't range check the addresses.
>>> Also reading the leading bytes is done in kind of a strange way: It'll
>>> read initial bytes (farther away from RIP) and perhaps not read
>>> later ones (closer to RIP), albeit clearly the ones closer are of more
>>> interest. In the extreme case, where RIP is only a few bytes into a
>>> page following an unmapped one, no leading bytes would be printed
>>> at all despite some actually being readable.
>> I think in this specific case, it might be best to hand roll some asm
>> using rep movs and the direction flag, with manual fault handling.
> That's certainly an option.
It is turning out to be much nicer.
>
>>> Avoiding actual wrapping could be easily done by extending the
>>> guest_mode() check above to also range check RIP against the
>>> hypervisor image boundaries (post-boot this could even be limited
>>> further, but perhaps using the full XEN_VIRT_{START,END} range is
>>> the better route with xSplice in mind.
>> I would like, where possible, to avoid omitting the instruction stream
>> if Xen is outside of its expected boundaries.
> Which is because of ...? What useful information do you think can
> be gained from the actual instruction when the mere fact of being
> outside the boundaries is a bug?
Wherever %rip is pointing, the code under %rip is directly relevant to
the exact values of the registers and stack dump printed.
It will be obvious from the numeric value of %rip whether it is bad
(also, whether symbol information is found), and making it work for all
cases is easier than restricting to the Xen-only case.
~Andrew
next prev parent reply other threads:[~2016-02-11 13:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-11 10:52 [PATCH v2 1/2] x86/traps: Prevent interleaving of concurrent cpu state dumps Andrew Cooper
2016-02-11 10:52 ` [PATCH v2 2/2] x86/traps: Dump instruction stream in show_execution_state() Andrew Cooper
2016-02-11 11:16 ` Jan Beulich
2016-02-11 12:12 ` Andrew Cooper
2016-02-11 12:52 ` Jan Beulich
2016-02-11 13:41 ` Andrew Cooper [this message]
2016-02-11 13:55 ` Jan Beulich
2016-02-11 14:33 ` [PATCH v3 " Andrew Cooper
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=56BC8F8D.7070208@citrix.com \
--to=andrew.cooper3@citrix.com \
--cc=JBeulich@suse.com \
--cc=xen-devel@lists.xen.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).