[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/2] livepatch: avoid relocations referencing ignored section symbols
- To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Thu, 17 Mar 2022 12:08:54 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ThI7FNLNj1qjzQJ85InJ5XwxtR+RxYNzUMMHvZI+Xew=; b=c2n1vAhBtjbvFq0pzUDZ4xTqD2eWCadALKWopb73NVqIOuAlgSRVHU91A4/B2AjIx3v4BFxOqf1iulIQ9wR8a5W/HbyOh3OssavggInXUbgZ7j2PRUvONZ1eJL/+7TsUSqBuYIQGnJYBU9mBY0+rlx6dj187KI4lefSN6cK6L2XCg4IfbVEsrs8ntY1/F0KVe8BBJW5hdH8U1zmbSc5rsfpaOuurMd5PyH/1qsiid2eZcgLj7uEn6Kty7XeWXOz65zM5rb0yirkvdLA4cUpnCav0R43dhHH8ybW9lquKZyQgw1DCrFpkT5h+WdK654Pp/jgie4XC31zAPIEPJUPJpQ==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xn2LMnkCgqbd1tMp4K/L4L5ni8CsCeu2FZcrK8C0In4KiBb8ESTsaXunzZYaxWQcUx3xHxrWhdB33aRW/Z/qs6XMGlEkDsFDdsxq5DRt9GgRcb23aQVdJXD6RxXadP/eRHOExbXwabE+eVBS/eXDPl/bkjssSRQmjaNG6/LJSJBIz+2Ju0aRv/DrQdnRH56lBZAnATEKi+4FE89F8i7UIkARL1jgGzgPc5BfsZSOipgg7tXEoL78dDuge76ZgXBK7kZc7E7QWLiEwYWlUwU/M0BeH1EcVd64hldqIz8O5Y3gE4fY31XSb7gX41MF05qatXMC0qRGHCB0w3hpHGRIPQ==
- Authentication-results: esa2.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: Roger Pau Monne <roger.pau@xxxxxxxxxx>, Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, "Stefano Stabellini" <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, "Bertrand Marquis" <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
- Delivery-date: Thu, 17 Mar 2022 11:09:24 +0000
- Ironport-data: A9a23:xAxTwK8imfBwi2eYLQAADrUDDX6TJUtcMsCJ2f8bNWPcYEJGY0x3n WYeCz3TPKzfZjHwf9x+b4zl8UoPu8fQnNQ3Hgpk+X88E34SpcT7XtnIdU2Y0wF+jyHgoOCLy +1EN7Es+ehtFie0Si+Fa+Sn9T8mvU2xbuKU5NTsY0idfic5DnZ54f5fs7Rh2NQw2oHmW1nlV e7a+KUzBnf0g1aYDUpMg06zgEsHUCPa4W5wUvQWPJinjXeG/5UnJMt3yZKZdhMUdrJ8DO+iL 9sv+Znilo/vE7XBPfv++lrzWhVirrc/pmFigFIOM0SpqkAqSiDfTs/XnRfTAKtao2zhojx/9 DlCnYaiRTszHojRpNQceRJBFTFPOaFi+JaSdBBTseTLp6HHW37lwvEoB0AqJ4wIvO1wBAmi9 9RBdmpLNErawbvrnvTrEYGAhex6RCXvFJkYtXx6iynQEN4tQIzZQrWM7thdtNs1rp4QQaeAP ZVBAdZpREybOzlRHAwPM5IVu/uQj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QGLyRel8qTzHRS01goXF2on+8ZuzU H11yjCoomzufCyzRHRk0fV8pRtgdPkjv9OHtaFhMQ5IijlziyoeINicbufuy1dmpDk1H8a1P 335zswNcV67H3cOkmzvBvWwgHllA0j7nfzoGXo90fLkIjcfnYXGsBBjYVWfl/y8Ew7puxx16 pNwiawq4dXJQmoplWy2/H4EzVR0makq3srluAey1ZFV5EFVbNXpYsDuGtIDZY7Gj7g4oxPKp ggMCjl3ocXTbqmVQGbgoE2q+bcHEjbXy32DnTqg/blkgS/xxtCvg4lLM92pAZ2yHtycegB2w 3+CNUbqFh/dL5kUUtDPpZ1fSLOMB23ffvtChPaHb21LtBOB5ryw6SHlIndotvaP6A18A==
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
Track whether symbols belong to ignored sections in order to avoid
applying relocations referencing those symbols. The address of such
symbols won't be resolved and thus the relocation will likely fail or
write garbage to the destination.
Return an error in that case, as leaving unresolved relocations would
lead to malfunctioning payload code.
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
xen/arch/arm/arm32/livepatch.c | 7 +++++++
xen/arch/arm/arm64/livepatch.c | 7 +++++++
xen/arch/x86/livepatch.c | 7 +++++++
xen/common/livepatch_elf.c | 6 ++++++
xen/include/xen/livepatch_elf.h | 1 +
5 files changed, 28 insertions(+)
diff --git a/xen/arch/arm/arm32/livepatch.c b/xen/arch/arm/arm32/livepatch.c
index 5a06467008..6aed227818 100644
--- a/xen/arch/arm/arm32/livepatch.c
+++ b/xen/arch/arm/arm32/livepatch.c
@@ -272,6 +272,13 @@ int arch_livepatch_perform(struct livepatch_elf *elf,
elf->name, symndx);
return -EINVAL;
}
+ else if ( elf->sym[symndx].ignored )
+ {
+ printk(XENLOG_ERR LIVEPATCH
+ "%s: Relocation against ignored symbol %s cannot be
resolved\n",
+ elf->name, elf->sym[symndx].name);
+ return -EINVAL;
+ }
val = elf->sym[symndx].sym->st_value; /* S */
diff --git a/xen/arch/arm/arm64/livepatch.c b/xen/arch/arm/arm64/livepatch.c
index 6ec8dc60f0..655ded33d2 100644
--- a/xen/arch/arm/arm64/livepatch.c
+++ b/xen/arch/arm/arm64/livepatch.c
@@ -270,6 +270,13 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
elf->name, symndx);
return -EINVAL;
}
+ else if ( elf->sym[symndx].ignored )
+ {
+ printk(XENLOG_ERR LIVEPATCH
+ "%s: Relocation against ignored symbol %s cannot be
resolved\n",
+ elf->name, elf->sym[symndx].name);
+ return -EINVAL;
+ }
val = elf->sym[symndx].sym->st_value + r->r_addend; /* S+A */
diff --git a/xen/arch/x86/livepatch.c b/xen/arch/x86/livepatch.c
index 37c9b8435e..a928e5bfcd 100644
--- a/xen/arch/x86/livepatch.c
+++ b/xen/arch/x86/livepatch.c
@@ -262,6 +262,13 @@ int arch_livepatch_perform_rela(struct livepatch_elf *elf,
elf->name, symndx);
return -EINVAL;
}
+ else if ( elf->sym[symndx].ignored )
+ {
+ printk(XENLOG_ERR LIVEPATCH
+ "%s: Relocation against ignored symbol %s cannot be
resolved\n",
+ elf->name, elf->sym[symndx].name);
+ return -EINVAL;
+ }
val = r->r_addend + elf->sym[symndx].sym->st_value;
diff --git a/xen/common/livepatch_elf.c b/xen/common/livepatch_elf.c
index b089cacb1c..45d73912a3 100644
--- a/xen/common/livepatch_elf.c
+++ b/xen/common/livepatch_elf.c
@@ -334,7 +334,13 @@ int livepatch_elf_resolve_symbols(struct livepatch_elf
*elf)
}
if ( livepatch_elf_ignore_section(elf->sec[idx].sec) )
+ {
+ dprintk(XENLOG_DEBUG, LIVEPATCH
+ "%s: Symbol %s from section %s ignored\n",
+ elf->name, elf->sym[i].name, elf->sec[idx].name);
+ elf->sym[i].ignored = true;
break;
+ }
st_value += (unsigned long)elf->sec[idx].load_addr;
if ( elf->sym[i].name )
diff --git a/xen/include/xen/livepatch_elf.h b/xen/include/xen/livepatch_elf.h
index 5b1ec469da..7116deaddc 100644
--- a/xen/include/xen/livepatch_elf.h
+++ b/xen/include/xen/livepatch_elf.h
@@ -22,6 +22,7 @@ struct livepatch_elf_sec {
struct livepatch_elf_sym {
const Elf_Sym *sym;
const char *name;
+ bool ignored;
};
struct livepatch_elf {
--
2.34.1
|