From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: xen-devel@lists.xenproject.org,
Ross Lagerwall <ross.lagerwall@citrix.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Michal Orzel <michal.orzel@amd.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
Jan Beulich <jbeulich@suse.com>
Subject: Re: [PATCH v3 1/5] xen/livepatch: drop load_addr Elf section field
Date: Thu, 26 Sep 2024 13:27:39 +0200 [thread overview]
Message-ID: <ZvVFKyvY-lwXffAB@macbook.local> (raw)
In-Reply-To: <4d9da48c-00ba-476d-8915-96ed765cdfbe@citrix.com>
On Thu, Sep 26, 2024 at 12:04:06PM +0100, Andrew Cooper wrote:
> On 26/09/2024 11:14 am, Roger Pau Monne wrote:
> > The Elf loading logic will initially use the `data` section field to stash a
> > pointer to the temporary loaded data (from the buffer allocated in
> > livepatch_upload(), which is later relocated and the new pointer stashed in
> > `load_addr`.
> >
> > Remove this dual field usage and use an `addr` uniformly. Initially data will
> > point to the temporary buffer, until relocation happens, at which point the
> > pointer will be updated to the relocated address.
> >
> > This avoids leaking a dangling pointer in the `data` field once the temporary
> > buffer is freed by livepatch_upload().
> >
> > Note the `addr` field cannot retain the const attribute from the previous
> > `data`field, as there's logic that performs manipulations against the loaded
> > sections, like applying relocations or sorting the exception table.
> >
> > No functional change intended.
> >
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>
> Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
>
> > diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
> > index df41dcce970a..7e6bf58f4408 100644
> > --- a/xen/common/livepatch.c
> > +++ b/xen/common/livepatch.c
> > @@ -371,18 +371,21 @@ static int move_payload(struct payload *payload, struct livepatch_elf *elf)
> >
> > ASSERT(offset[i] != UINT_MAX);
> >
> > - elf->sec[i].load_addr = buf + offset[i];
> > + buf += offset[i];
> >
> > /* Don't copy NOBITS - such as BSS. */
> > if ( elf->sec[i].sec->sh_type != SHT_NOBITS )
> > {
> > - memcpy(elf->sec[i].load_addr, elf->sec[i].data,
> > + memcpy(buf, elf->sec[i].addr,
> > elf->sec[i].sec->sh_size);
> > dprintk(XENLOG_DEBUG, LIVEPATCH "%s: Loaded %s at %p\n",
> > - elf->name, elf->sec[i].name, elf->sec[i].load_addr);
> > + elf->name, elf->sec[i].name, buf);
> > }
> > else
> > - memset(elf->sec[i].load_addr, 0, elf->sec[i].sec->sh_size);
> > + memset(buf, 0, elf->sec[i].sec->sh_size);
> > +
> > + /* Replace the temporary buffer with the relocated one. */
> > + elf->sec[i].addr = buf;
>
> I'd suggest /* Update sec[] to refer to its final location. */
>
> Replace is technically the memcpy() above, and "relocate" means
> something else in ELF terms.
Sure, no strong opinion.
> Can fix on commit.
Thanks!
next prev parent reply other threads:[~2024-09-26 11:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-26 10:14 [PATCH v3 0/5] xen/livepatch: improvements to loading Roger Pau Monne
2024-09-26 10:14 ` [PATCH v3 1/5] xen/livepatch: drop load_addr Elf section field Roger Pau Monne
2024-09-26 11:04 ` Andrew Cooper
2024-09-26 11:27 ` Roger Pau Monné [this message]
2024-09-26 12:35 ` Michal Orzel
2024-09-26 15:35 ` Ross Lagerwall
2024-09-26 10:14 ` [PATCH v3 2/5] xen/livepatch: simplify and unify logic in prepare_payload() Roger Pau Monne
2024-09-26 15:52 ` Ross Lagerwall
2024-09-26 10:14 ` [PATCH v3 3/5] xen/livepatch: do Xen build-id check earlier Roger Pau Monne
2024-09-26 11:06 ` Andrew Cooper
2024-09-26 16:11 ` Ross Lagerwall
2024-09-26 16:59 ` Roger Pau Monné
2024-09-26 10:14 ` [PATCH v3 4/5] x86/alternatives: do not BUG during apply Roger Pau Monne
2024-09-26 11:09 ` Andrew Cooper
2024-09-26 11:28 ` Roger Pau Monné
2024-09-26 10:14 ` [PATCH v3 5/5] x86/alternative: build time check feature is in range Roger Pau Monne
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=ZvVFKyvY-lwXffAB@macbook.local \
--to=roger.pau@citrix.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=andrew.cooper3@citrix.com \
--cc=bertrand.marquis@arm.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=ross.lagerwall@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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.