All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad@kernel.org>
To: xen-devel@lists.xenproject.org, ross.lagerwall@citrix.com,
	m.a.young@durham.ac.uk
Cc: Konrad Rzeszutek Wilk <konrad@kernel.org>
Subject: [PATCH LIVEPATCH-BUILD-TOOLS] create-diff-object: Update fixup offsets in .rela.ex_table
Date: Wed, 23 Nov 2016 20:08:37 -0500	[thread overview]
Message-ID: <20161124010837.18077-2-konrad@kernel.org> (raw)
In-Reply-To: <20161124010837.18077-1-konrad@kernel.org>

From: Ross Lagerwall <ross.lagerwall@citrix.com>

When pruning entries from the fixup table, update the offsets in
.rela.ex_table otherwise the relas might point to the wrong fixup entry
or even out of the .fixup section.

Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Konrad Rzeszutek Wilk <konrad@kernel.org>
---
v2: Squashed fix from kpatch upstream
   [see https://github.com/dynup/kpatch/pull/616]
---
 create-diff-object.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/create-diff-object.c b/create-diff-object.c
index 69bcd88..58f7c4c 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -1057,6 +1057,34 @@ static int should_keep_rela_group(struct section *sec, int start, int size)
 	return found;
 }
 
+/*
+ * When updating .fixup, the corresponding addends in .ex_table need to be
+ * updated too. Stash the result in rela.r_addend so that the calculation in
+ * fixup_group_size() is not affected.
+ */
+void kpatch_update_ex_table_addend(struct kpatch_elf *kelf,
+				   struct special_section *special,
+				   int src_offset, int dest_offset,
+				   int group_size)
+{
+	struct rela *rela;
+	struct section *sec;
+
+	if (strcmp(special->name, ".fixup"))
+		return;
+
+	sec = find_section_by_name(&kelf->sections, ".rela.ex_table");
+	if (!sec)
+		ERROR("missing .rela.ex_table section");
+
+	list_for_each_entry(rela, &sec->relas, list) {
+		if (!strcmp(rela->sym->name, ".fixup") &&
+		    rela->addend >= src_offset &&
+		    rela->addend < src_offset + group_size)
+			rela->rela.r_addend = rela->addend - (src_offset - dest_offset);
+	}
+}
+
 static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
 				              struct special_section *special,
 				              struct section *sec)
@@ -1073,6 +1101,14 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
 	if (!dest)
 		ERROR("malloc");
 
+	/* Restore the stashed r_addend from kpatch_update_ex_table_addend. */
+	if (!strcmp(special->name, ".ex_table")) {
+		list_for_each_entry(rela, &sec->relas, list) {
+			if (!strcmp(rela->sym->name, ".fixup"))
+				rela->addend = rela->rela.r_addend;
+		}
+	}
+
 	group_size = 0;
 	src_offset = 0;
 	dest_offset = 0;
@@ -1100,6 +1136,11 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf,
 				rela->rela.r_offset = rela->offset;
 
 				rela->sym->include = 1;
+
+				kpatch_update_ex_table_addend(kelf, special,
+							      src_offset,
+							      dest_offset,
+							      group_size);
 			}
 		}
 
-- 
2.9.3


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

  reply	other threads:[~2016-11-24  1:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-23 23:06 Problems with livepatching M A Young
2016-11-23 23:35 ` Andrew Cooper
2016-11-24  0:13   ` M A Young
2016-11-24  1:08     ` Konrad Rzeszutek Wilk
2016-11-24  1:08       ` Konrad Rzeszutek Wilk [this message]
2016-11-24  8:05         ` [PATCH LIVEPATCH-BUILD-TOOLS] create-diff-object: Update fixup offsets in .rela.ex_table Ross Lagerwall
2016-11-24  8:52       ` Problems with livepatching Ross Lagerwall
2016-11-24  9:24       ` Lars Kurth
2016-11-24  9:55         ` Ross Lagerwall

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=20161124010837.18077-2-konrad@kernel.org \
    --to=konrad@kernel.org \
    --cc=m.a.young@durham.ac.uk \
    --cc=ross.lagerwall@citrix.com \
    --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.