All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>, jamie.iles@oracle.com
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>,
	Julien Grall <julien.grall@arm.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Jan Beulich <JBeulich@suse.com>,
	Xen-devel <xen-devel@lists.xen.org>
Subject: Re: [PATCH 2/2] xen/livepatch: Don't crash on encountering STN_UNDEF relocations
Date: Wed, 14 Jun 2017 15:08:47 -0400	[thread overview]
Message-ID: <20170614190847.GX15061@char.us.oracle.com> (raw)
In-Reply-To: <6d055740-eb51-cb9a-7fc9-ff70da5d3a0b@citrix.com>

On Wed, Jun 14, 2017 at 07:33:57PM +0100, Andrew Cooper wrote:
> On 14/06/17 15:18, Konrad Rzeszutek Wilk wrote:
> > On Wed, Jun 14, 2017 at 04:24:00AM -0600, Jan Beulich wrote:
> >>>>> On 14.06.17 at 12:13, <andrew.cooper3@citrix.com> wrote:
> >>> On 14/06/17 11:11, Jan Beulich wrote:
> >>>>>>> On 13.06.17 at 22:51, <andrew.cooper3@citrix.com> wrote:
> >>>>> --- a/xen/arch/x86/livepatch.c
> >>>>> +++ b/xen/arch/x86/livepatch.c
> >>>>> @@ -170,14 +170,22 @@ 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 )
> >>>>> +            val = 0;
> >>>>> +        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;
> >>>>>          }
> >>>>> -
> >>>>> -        val = r->r_addend + elf->sym[symndx].sym->st_value;
> >>>>> +        else if ( !elf->sym[symndx].sym )
> >>>>> +        {
> >>>>> +            dprintk(XENLOG_ERR, LIVEPATCH "%s: No symbol@%u\n",
> >>>>> +                    elf->name, symndx);
> >>>>> +            return -EINVAL;
> >>>>> +        }
> >>>>> +        else
> >>>>> +            val = r->r_addend + elf->sym[symndx].sym->st_value;
> >>>> I don't understand this: st_value for STN_UNDEF is going to be zero
> >>>> (so far there's also no extension defined for the first entry, afaict),
> >>>> so there should be no difference between hard-coding the zero and
> >>>> reading the symbol table entry. Furthermore r_addend would still
> >>>> need applying. And finally "val" is never being cast to a pointer, and
> >>>> hence I miss the connection to whatever crash you've been
> >>>> observing.
> >>> elf->sym[0].sym is the NULL pointer.
> >>>
> >>> ->st_value dereferences it.
> >> Ah, but that is then what you want to change (unless we decide
> >> to outright refuse STN_UNDEF, which still depends on why it's
> >> there in the first place).
> > That the !elf->sym[0].sym is very valid case.
> > And in that context the 'val=r->r_addend' makes sense.
> >
> > And from an EFI spec, the relocations can point to the SHN_UNDEF area (why
> > would it I have no clue) - but naturally we can't mess with that.
> >
> > But I am curious as Jan about this - and whether this is something that
> > could be constructed with a test-case?
> 
> Well - I've got a livepatch with such a relocation.  It is probably a
> livepatch build tools issue, but the question is whether Xen should ever
> accept such a livepatch or not (irrespective of whether this exact
> relocation is permitted within the ELF spec).

CC-ing Jamie

I would say no, as I can't find a good use-case for a relocation 
to point to the SHN_UNDEF symbol [0]. It feels to me as if somebody
would be mucking with a NULL pointer.

But perhaps if the addendum had a value it would make sense?

As in NULL + <offset>?


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

  parent reply	other threads:[~2017-06-14 19:08 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-13 20:51 [PATCH 1/2] xen/livepatch: Clean up arch relocation handling Andrew Cooper
2017-06-13 20:51 ` [PATCH 2/2] xen/livepatch: Don't crash on encountering STN_UNDEF relocations Andrew Cooper
2017-06-13 21:13   ` Andrew Cooper
2017-06-14 10:03     ` Jan Beulich
2017-06-14 10:11   ` Jan Beulich
2017-06-14 10:13     ` Andrew Cooper
2017-06-14 10:24       ` Jan Beulich
2017-06-14 14:18         ` Konrad Rzeszutek Wilk
2017-06-14 18:33           ` Andrew Cooper
2017-06-14 18:49             ` Jan Beulich
2017-06-19 18:30               ` Konrad Rzeszutek Wilk
2017-06-19 23:05                 ` Andrew Cooper
2017-06-20  7:15                   ` Jan Beulich
2017-06-20 13:30                     ` Konrad Rzeszutek Wilk
2017-06-14 19:08             ` Konrad Rzeszutek Wilk [this message]
2017-06-21 18:13   ` [PATCH for-4.9 v2] " Andrew Cooper
2017-06-22  1:26     ` Konrad Rzeszutek Wilk
2017-06-22 15:27       ` Konrad Rzeszutek Wilk
2017-06-22 16:10         ` Konrad Rzeszutek Wilk
2017-06-22 16:33           ` Konrad Rzeszutek Wilk
2017-06-22 17:05             ` Konrad Rzeszutek Wilk
2017-06-23  9:44               ` Jan Beulich
2017-06-22  7:40     ` Jan Beulich
2017-06-22  9:49     ` Ross Lagerwall
2017-06-14  9:25 ` [PATCH 1/2] xen/livepatch: Clean up arch relocation handling Jan Beulich
2017-06-14 13:44 ` Konrad Rzeszutek Wilk
2017-06-14 14:02   ` Jan Beulich
2017-06-14 18:28     ` Andrew Cooper
2017-06-19 18:18       ` Konrad Rzeszutek Wilk
2017-06-20  7:36         ` Jan Beulich
2017-06-20  7:39           ` Andrew Cooper
2017-06-20  7:41             ` Andrew Cooper
2017-06-20  7:56             ` Jan Beulich
2017-06-20 13:36               ` Konrad Rzeszutek Wilk
2017-06-22  1:27 ` Is [PATCH for-4.9] Was:Re: " Konrad Rzeszutek Wilk

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=20170614190847.GX15061@char.us.oracle.com \
    --to=konrad.wilk@oracle.com \
    --cc=JBeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=jamie.iles@oracle.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 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.