xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad@kernel.org>
To: xen-devel@lists.xenproject.org, julien.grall@arm.com,
	sstabellini@kernel.org, andrew.cooper3@citrix.com
Cc: jbeulich@suse.com
Subject: [PATCH v2 1/5] livepatch: Tighten alignment checks.
Date: Wed, 26 Jul 2017 15:47:52 -0400	[thread overview]
Message-ID: <20170726194756.20265-2-konrad@kernel.org> (raw)
In-Reply-To: <20170726194756.20265-1-konrad@kernel.org>

From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

The ELF specification mentions nothing about the sh_size being
modulo the sh_addralign. Only that sh_addr MUST be aligned on
sh_addralign if sh_addralign is not zero or one.

We on loading did not take this in-to account so this patch adds
a check on the ELF file as it is being parsed.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
v1: Initial patch
v2: Drop the check when loading it in memory
    Add check for alignment being anything but power of two (ignoring 0, and 1)
    Change dprintk to include hex values and print addr not size.
---
 xen/common/livepatch_elf.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c
index b69e2718dd..4dc1b68871 100644
--- a/xen/common/livepatch_elf.c
+++ b/xen/common/livepatch_elf.c
@@ -86,6 +86,19 @@ static int elf_resolve_sections(struct livepatch_elf *elf, const void *data)
                     delta < sizeof(Elf_Ehdr) ? "at ELF header" : "is past end");
             return -EINVAL;
         }
+        else if ( sec[i].sec->sh_addralign > 1 &&
+                  sec[i].sec->sh_addr % sec[i].sec->sh_addralign )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Section [%u] addr (%#"PRIxElfAddr") is not aligned properly (%#"PRIxElfAddr")\n",
+                    elf->name, i, sec[i].sec->sh_addr, sec[i].sec->sh_addralign);
+            return -EINVAL;
+        }
+        else if ( sec[i].sec->sh_addralign > 1 && sec[i].sec->sh_addralign % 2 )
+        {
+            dprintk(XENLOG_ERR, LIVEPATCH "%s: Section [%u] alignment (%#"PRIxElfAddr") is not supported\n",
+                    elf->name, i, sec[i].sec->sh_addralign);
+            return -EOPNOTSUPP;
+        }
         else if ( (sec[i].sec->sh_flags & (SHF_WRITE | SHF_ALLOC)) &&
                   sec[i].sec->sh_type == SHT_NOBITS &&
                   sec[i].sec->sh_size > LIVEPATCH_MAX_SIZE )
-- 
2.13.3


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

  reply	other threads:[~2017-07-26 19:48 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-26 19:47 [PATCH v2] Livepatch fixes for v4.10 (v2) Konrad Rzeszutek Wilk
2017-07-26 19:47 ` Konrad Rzeszutek Wilk [this message]
2017-07-31 13:46   ` [PATCH v2 1/5] livepatch: Tighten alignment checks Jan Beulich
2017-07-26 19:47 ` [PATCH v2 2/5] livepatch: Include sizes when an mismatch occurs Konrad Rzeszutek Wilk
2017-07-31 13:51   ` Jan Beulich
2017-07-26 19:47 ` [PATCH v2 3/5] xen/livepatch/ARM32: Don't load and crash on livepatches loaded with wrong alignment Konrad Rzeszutek Wilk
2017-07-26 22:27   ` Andrew Cooper
2017-07-31 13:55   ` Jan Beulich
2017-07-31 16:04     ` Konrad Rzeszutek Wilk
2017-08-02  9:20       ` Jan Beulich
2017-09-07 17:36         ` Konrad Rzeszutek Wilk
2017-09-08  9:30           ` Jan Beulich
2017-09-09 12:05             ` Konrad Rzeszutek Wilk
2017-09-11  9:01               ` Jan Beulich
2017-09-12  0:22                 ` Konrad Rzeszutek Wilk
2017-09-12  8:57                   ` Jan Beulich
2017-09-18 19:37                     ` Konrad Rzeszutek Wilk
2017-09-19 15:04                       ` Jan Beulich
2017-09-20 15:12                         ` Konrad Rzeszutek Wilk
2017-09-20 15:51                           ` Jan Beulich
2017-07-26 19:47 ` [PATCH v2 4/5] alternative/x86/arm32: Align altinstructions (and altinstr_replacement) sections Konrad Rzeszutek Wilk
2017-07-31 14:01   ` Jan Beulich
2017-09-11 18:59     ` Konrad Rzeszutek Wilk
2017-07-26 19:47 ` [PATCH v2 5/5] livepatch: Declare live patching as a supported feature Konrad Rzeszutek Wilk
2017-07-31 14:03   ` Jan Beulich

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=20170726194756.20265-2-konrad@kernel.org \
    --to=konrad@kernel.org \
    --cc=andrew.cooper3@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien.grall@arm.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 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).