[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/3] livepatch: correctly handle altinstruction sections


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Date: Thu, 10 Mar 2022 16:08:34 +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=gqzJJP1ALgqRLG/SatpbTyBtpWv/Y8f9lPVlBNCrbsY=; b=Y/QGpdOP1CMwqBWicJbBqUpDLZlGsav5eyjICvUCBJuioxPUF9OO9W1gfXitP6BuhsFVq6yc2pGn59/DsEH/KXu0kDYpcuu1iDtf86L4zmNb4oFHlRfjf+Diks6pkjduIQD1b/X+KqHHvfS5EeYaaYcrHPVlDLhcOBoUMe8I4Y+Qrqad605U/zASzqet408d3ECq1WV0dRKuIl7VIRqthHnrdFFFH0cxTJSNl0i++VuX1PUUk0mPw9YqZrXuivG3R46ze7KH6YpUGwbW4LvvFlapSK5LQ1u9go439kF2SNwWczppUyV7Ts5eChkeZxQk6y0wy+GspGA4dBzSeJs38A==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UBpo6PVB2jyLE6M4awiWDiI0uG8BFy3k03EyAhxlrBtLk4vx3Gtcq3sLcFGF85MtqWljZBRoDpJuukbK81nlzjfbsf3pUW67bNxyB4kDENvs/TJGxaXKLaAHdD2aFYGOItrN20uO/z21l4IqPzdnM2GFKPtDpz+Yc2UKuoxrU3416n8weFZxv6SFZaBfCileDchGHW7Luk7bxV1nBcHrpUiyoCXEsw3v3mahKHJ/N6433XNuOZzhQs6Nk/8YJTHsy2o2Gl7THGdDnEpR05oKqStvcB3M0AnZsLE2y1j2wHHG26Mb1N07dS7OvtG2F/B4EANHv0MoAUjlCx2gpK3Org==
  • Authentication-results: esa5.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: Konrad Rzeszutek Wilk <konrad.wilk@xxxxxxxxxx>, Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>, <doebel@xxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 10 Mar 2022 15:11:58 +0000
  • Ironport-data: A9a23:Uri086nokhfe4AlT8JDcv9vo5gyaJkRdPkR7XQ2eYbSJt1+Wr1Gzt xIYWmqOM/eOYmT2f913Otm+8UgHvp7cx4JmGQQ9pHpgFyMWpZLJC+rCIxarNUt+DCFioGGLT Sk6QoOdRCzhZiaE/n9BCpC48T8kk/vgqoPUUIYoAAgoLeNfYHpn2EoLd9IR2NYy24DiWlvV4 7senuWEULOb828sWo4rw/rrRCNH5JwebxtB4zTSzdgS1LPvvyF94KA3fMldHFOhKmVgJcaoR v6r8V2M1jixEyHBqD+Suu2TnkUiGtY+NOUV45Zcc/DKbhNq/kTe3kunXRa1hIg+ZzihxrhMJ NtxWZOYcgMUPK6UsvwmVjYBCDsjMqkBpaWePi3q2SCT5xWun3rExvxvCAc9PJEC+/YxCmZLn RAaAGlTNFbZ3bvwme/lDLk37iggBJCD0Ic3oHZvwCufFf87aZvCX7/L9ZlT2zJYasVmQ6uFN ptHMmAHgBLofU1ta3BUEcwHzeKP3WDyLRtFsAqYjP9ii4TU5FMoi+W8WDbPQfSGQshfk0Kwr 2fP7WP/RB0XXPSczjyf+37qme7Lngv8QosZELD+/flv6HWDy2pWBBAIWF+TpfiillX4S99ZM 1YT+Cclse417kPDczXmd0Tm+jje5EdaAocOVb1hgO2Q9kbKyz2dO2oHFhRZU9kJ7dQsGDMuk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vyWqOLtBzB5uKke+y3IkI
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

The current handling of altinstructions sections by the livepatch
tools is incorrect, as on Xen those sections are part of .init and
thus discarded after load. Correctly handle them by just ignoring, as
it's done with other .init related sections.

While there also add .data.ro_after_init section as a read-only
section and introduce some syntactic sugar for comparing section
names.

Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
I assume this handling of .altinstr* sections was inherited from Linux
where the sections are not discarded after load in order to apply
alternative patching to the loaded modules after boot.
---
 common.c             |  7 +++++--
 create-diff-object.c | 26 --------------------------
 2 files changed, 5 insertions(+), 28 deletions(-)

diff --git a/common.c b/common.c
index 68a71f7..a148d8a 100644
--- a/common.c
+++ b/common.c
@@ -249,19 +249,22 @@ int is_text_section(struct section *sec)
                (sec->sh.sh_flags & SHF_EXECINSTR));
 }
 
+#define SEC_MATCH(n) !strncmp(sec->name, n, strlen(n) - 1)
 int is_rodata_section(struct section *sec)
 {
        return sec->sh.sh_type == SHT_PROGBITS &&
               !(sec->sh.sh_flags & (SHF_EXECINSTR | SHF_WRITE)) &&
-              !strncmp(sec->name, ".rodata", 7);
+              (SEC_MATCH(".rodata") || SEC_MATCH(".data.ro_after_init"));
 }
 
 int is_init_section(struct section *sec)
 {
        return sec->sh.sh_type == SHT_PROGBITS &&
               (sec->sh.sh_flags & SHF_ALLOC) &&
-              !strncmp(sec->name, ".init", 5);
+              (SEC_MATCH(".init") || SEC_MATCH(".text.startup") ||
+               SEC_MATCH(".altinstr") || SEC_MATCH(".ctors"));
 }
+#undef SEC_MATCH
 
 int is_debug_section(struct section *sec)
 {
diff --git a/create-diff-object.c b/create-diff-object.c
index a516670..ec2afb4 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -995,19 +995,6 @@ static int ex_table_group_size(struct kpatch_elf *kelf, 
int offset)
        return size;
 }
 
-static int altinstructions_group_size(struct kpatch_elf *kelf, int offset)
-{
-       static int size = 0;
-       char *str;
-       if (!size) {
-               str = getenv("ALT_STRUCT_SIZE");
-               size = str ? atoi(str) : 12;
-       }
-
-       log_debug("altinstr_size=%d\n", size);
-       return size;
-}
-
 static int livepatch_hooks_group_size(struct kpatch_elf *kelf, int offset)
 {
        static int size = 0;
@@ -1021,11 +1008,6 @@ static int livepatch_hooks_group_size(struct kpatch_elf 
*kelf, int offset)
        return size;
 }
 
-static int undefined_group_size(struct kpatch_elf *kelf, int offset)
-{
-       return 0;
-}
-
 /*
  * The rela groups in the .fixup section vary in size.  The beginning of each
  * .fixup rela group is referenced by the .ex_table section. To find the size
@@ -1099,14 +1081,6 @@ static struct special_section special_sections[] = {
                .name           = ".ex_table",
                .group_size     = ex_table_group_size,
        },
-       {
-               .name           = ".altinstructions",
-               .group_size     = altinstructions_group_size,
-       },
-       {
-               .name           = ".altinstr_replacement",
-               .group_size     = undefined_group_size,
-       },
        {
                .name           = ".livepatch.hooks.load",
                .group_size     = livepatch_hooks_group_size,
-- 
2.34.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.