xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Jan Beulich <JBeulich@suse.com>
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations
Date: Fri, 23 Jun 2017 11:13:49 +0100	[thread overview]
Message-ID: <4ebab764-5489-9302-e57c-5afaadbbd719@citrix.com> (raw)
In-Reply-To: <594D007F0200007800166303@prv-mh.provo.novell.com>

On 23/06/17 10:50, Jan Beulich wrote:
>>>> On 22.06.17 at 20:15, <andrew.cooper3@citrix.com> wrote:
>> A symndx of STN_UNDEF is special, and means a symbol value of 0.  While
>> legitimate in the ELF standard, its existance in a livepatch is questionable
>> at best.  Until a plausible usecase presents itself, reject such a relocation
>> with -EOPNOTSUPP.
>>
>> Additionally, fix an off-by-one error while range checking symndx, and perform
>> a safety check on elf->sym[symndx].sym before derefencing it, to avoid
>> tripping over a NULL pointer when calculating val.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
> with two remarks:
>
>> --- a/xen/arch/x86/livepatch.c
>> +++ b/xen/arch/x86/livepatch.c
>> @@ -170,12 +170,24 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
>>          uint8_t *dest = base->load_addr + r->r_offset;
>>          uint64_t val;
>>  
>> -        if ( symndx > elf->nsym )
>> +        if ( symndx == STN_UNDEF )
>> +        {
>> +            dprintk(XENLOG_ERR, LIVEPATCH "%s: Encountered STN_UNDEF\n",
>> +                    elf->name);
>> +            return -EOPNOTSUPP;
>> +        }
>> +        else if ( symndx >= elf->nsym )
>>          {
>>              dprintk(XENLOG_ERR, LIVEPATCH "%s: Relative relocation wants symbol@%u which is past end!\n",
>>                      elf->name, symndx);
>>              return -EINVAL;
>>          }
>> +        else if ( !elf->sym[symndx].sym )
> Neither of the two "else" is really necessary, and elsewhere we've
> been telling people to avoid such.

I see two logically different scenarios.

Per the style, if I were to use fully separate if() statements, I'd need
a newline between each.  This expands the code, and separates a chain of
logically-related checks.

IMO, its better to keep logically related checks more obviously
together, while I would definitely agree that unrelated chains (which
could in principle be if/else like this) should be separated.

>
>> +        {
>> +            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",
> Symbol tables can grow large, and for large numbers I generally
> find hex representation preferable of dec. Otoh the other
> (pre-existing) message uses dec too ...

I'll stay consistent with everything else.

~Andrew

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

  reply	other threads:[~2017-06-23 10:13 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-22 18:15 [PATCH for-4.9 v3 0/3] Fixes for livepatching Andrew Cooper
2017-06-22 18:15 ` [PATCH for-4.9 v3 1/3] xen/livepatch: Clean up arch relocation handling Andrew Cooper
2017-06-22 18:15 ` [PATCH for-4.9 v3 2/3] xen/livepatch: Use zeroed memory allocations for arrays Andrew Cooper
2017-06-23  2:55   ` Konrad Rzeszutek Wilk
2017-06-23 12:31   ` Ross Lagerwall
2017-06-22 18:15 ` [PATCH for-4.9 v3 3/3] xen/livepatch: Don't crash on encountering STN_UNDEF relocations Andrew Cooper
2017-06-22 21:10   ` Stefano Stabellini
2017-06-23  2:56   ` Konrad Rzeszutek Wilk
2017-06-23  9:50   ` Jan Beulich
2017-06-23 10:13     ` Andrew Cooper [this message]
2017-06-23 12:35   ` Ross Lagerwall
2017-06-23 13:32   ` Julien Grall
2017-06-23 13:33     ` Andrew Cooper
2017-06-23 13:43       ` Julien Grall
2017-06-23 13:45         ` Andrew Cooper
2017-06-23 13:47           ` Julien Grall
2017-06-23 14:35           ` Konrad Rzeszutek Wilk
2017-06-23 14:36             ` Julien Grall
2017-06-23 14:46               ` Konrad Rzeszutek Wilk
2017-06-24 17:28                 ` Julien Grall
2017-06-26  1:02                   ` Konrad Rzeszutek Wilk
2017-06-26  9:34                     ` Julien Grall

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=4ebab764-5489-9302-e57c-5afaadbbd719@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=julien.grall@arm.com \
    --cc=ross.lagerwall@citrix.com \
    --cc=sstabellini@kernel.org \
    --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).