[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 1/2] livepatch: do not ignore sections with 0 size
- To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
- Date: Thu, 17 Mar 2022 12:08:53 +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=x3+aTgeZKg2AgprDOZi02cilZw8eZZMU3TEy+Ao1rUk=; b=Q//jYNhZfHODPLNie+A5fJ/LELLpBoM7Bxw7ei6+WMFvReWjatn/gIbkHPHYMiKLdUzTF49ZMeDgVXEnG1Sa2UDkZXuKNBmJtfjM3vjPLr/3mTJzpKXNFA5BZ00qSsVGJ4BrCfZuVt4TCX4p0IrHrbSHsO8TV1dAn1CTy91tTsnrTHOE1e5HV6UlYaXlLJipAymKW0Ppdg3a7RYbis+J1bLyjUizw0or6FV3BD7RjcuGdIBjs10PqpZvfys0i1ariV5wtDy7V/Z/n7pU7soA8emxrYdDtZtmqtAFL+wrNy0qpdxHUFd/DfgLTHjBzNJ0EctD90TTwfiyXJHj9WHxgw==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VNFV2uhM0plfg7RVctUL964KvWj+H03331tOTTfNhss8TRLqb+cOSC0+Rzh6gcL8WMRGyEV9nuasNljgD0g+tFgwaxWiO25HW/mfea+ApU06EQOg1ppd0+I4ZNItV56k2hu5aE87DWHCYEcyQ5HTIEXiHDugtl2MWLnHXyyja1TQqCMzLGHTLotRgTf20RFXEqMl9nqSPxcSkuexaYb43mBfKt5xx63hgHiuc9BYiVn0TXmfA3pALiwMu95F5jkVA6wWRBc8nzNkTT6X5U+eF/EoXfqHqKE/uZ0xxkVB1WPod/CbdMFWemGhzGZKmJchN5AZSIFh+Xgo7HNnlmgDZA==
- Authentication-results: esa6.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>
- Delivery-date: Thu, 17 Mar 2022 11:09:43 +0000
- Ironport-data: A9a23:17lIz6CJMzfqLhVW/yfjw5YqxClBgxIJ4kV8jS/XYbTApDx31D0Ay zRNUD+DPq7YZGOnf9tzOt6y9koG6pHQy99lQQY4rX1jcSlH+JHPbTi7wuYcHM8wwunrFh8PA xA2M4GYRCwMZiaA4E/raNANlFEkvU2ybuOU5NXsZ2YgHWeIdA970Ug5w7Vg3dYy6TSEK1jlV e3a8pW31GCNg1aYAkpMg05UgEoy1BhakGpwUm0WPZinjneH/5UmJMt3yZWKB2n5WuFp8tuSH I4v+l0bElTxpH/BAvv9+lryn9ZjrrT6ZWBigVIOM0Sub4QrSoXfHc/XOdJFAXq7hQllkPgh2 tJ8i568QD0wP6nJutQHSQFxIzlHaPguFL/veRBTsOSWxkzCNXDt3+9vHAc9OohwFuRfWD8Us 6ZCcXZUM07F17neLLGTE4GAguw5K8bmJsUHs2xIxjDFF/c2B5vERs0m4PcGgmtp3JkeRZ4yY eIbNhlzVhH8UydON28ZVJcdw8Km3UDgJmgwRFW9+vNsvjm7IBZK+LvqNsDcdpqVRMFWtkGCr 2nC8iLyBRRyHMySz3+J/2yhgsfLnDjnQ8QCGbug7PlojVaPgGsJB3UruUCT+KfjzBTkApQGd hJSqnFGQbUOGFKDHsv6biO6rHe+px8YXvhgCfciwTGV8/+Bi+qGPVQsQjlEYd0gkcY5Qz02y 1OE9+/U6SxTXK69E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er discussion <xen-devel.lists.xenproject.org>
A side effect of ignoring such sections is that symbols belonging to
them won't be resolved, and that could make relocations belonging to
other sections that reference those symbols fail.
For example it's likely to have an empty .altinstr_replacement with
symbols pointing to it, and marking the section as ignored will
prevent the symbols from being resolved, which in turn will cause any
relocations against them to fail.
In order to solve this do not ignore sections with 0 size, only ignore
sections that don't have the SHF_ALLOC flag set.
Special case such empty sections in move_payload so they are not taken
into account in order to decide whether a livepatch can be safely
re-applied after a revert.
Fixes: 98b728a7b2 ('livepatch: Disallow applying after an revert')
Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
xen/common/livepatch.c | 16 +++++++++++-----
xen/include/xen/livepatch_elf.h | 2 +-
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/xen/common/livepatch.c b/xen/common/livepatch.c
index be2cf75c2d..abc1cae136 100644
--- a/xen/common/livepatch.c
+++ b/xen/common/livepatch.c
@@ -300,9 +300,6 @@ static int move_payload(struct payload *payload, struct
livepatch_elf *elf)
* and .shstrtab. For the non-relocate we allocate and copy these
* via other means - and the .rel we can ignore as we only use it
* once during loading.
- *
- * Also ignore sections with zero size. Those can be for example:
- * data, or .bss.
*/
if ( livepatch_elf_ignore_section(elf->sec[i].sec) )
offset[i] = UINT_MAX;
@@ -361,8 +358,17 @@ static int move_payload(struct payload *payload, struct
livepatch_elf *elf)
else if ( elf->sec[i].sec->sh_flags & SHF_WRITE )
{
buf = rw_buf;
- rw_buf_sec = i;
- rw_buf_cnt++;
+ if ( elf->sec[i].sec->sh_size )
+ {
+ /*
+ * Special handling of RW empty regions: do not account for
+ * them in order to decide whether a patch can safely be
+ * re-applied, but assign them a load address so symbol
+ * resolution and relocations work.
+ */
+ rw_buf_sec = i;
+ rw_buf_cnt++;
+ }
}
else
buf = ro_buf;
diff --git a/xen/include/xen/livepatch_elf.h b/xen/include/xen/livepatch_elf.h
index 9ad499ee8b..5b1ec469da 100644
--- a/xen/include/xen/livepatch_elf.h
+++ b/xen/include/xen/livepatch_elf.h
@@ -48,7 +48,7 @@ int livepatch_elf_perform_relocs(struct livepatch_elf *elf);
static inline bool livepatch_elf_ignore_section(const Elf_Shdr *sec)
{
- return !(sec->sh_flags & SHF_ALLOC) || sec->sh_size == 0;
+ return !(sec->sh_flags & SHF_ALLOC);
}
#endif /* __XEN_LIVEPATCH_ELF_H__ */
--
2.34.1
|