[PATCH 3/4] create-diff-object: don't include symbols for .livepatch.hooks.* sections

Roger Pau Monne posted 4 patches 12 months ago
[PATCH 3/4] create-diff-object: don't include symbols for .livepatch.hooks.* sections
Posted by Roger Pau Monne 12 months ago
Not all toolchains generate symbols for the .livepatch.hooks.* sections,
neither those symbols are required by the livepatch loading logic in Xen to
find and process the hooks.  Hooks in livepatch payloads are found and
processed based exclusively on section data.

The unconditional attempt to expect each hook serction to have a matching
symbol leads to a segmentation fault in create-diff-object when such symbol is
not present, as the code references a NULL pointer.

Fix this by not attempting to include symbols associated with hook sections.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
 create-diff-object.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/create-diff-object.c b/create-diff-object.c
index d8a2afbf2774..924059a1842b 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -1555,8 +1555,6 @@ static int kpatch_include_hook_elements(struct kpatch_elf *kelf)
 				sym->sec->sym = NULL;
 				/* use section symbol instead */
 				rela->sym = sym->sec->secsym;
-			} else {
-				sec->secsym->include = 1;
 			}
 		}
 	}
-- 
2.46.0


Re: [PATCH 3/4] create-diff-object: don't include symbols for .livepatch.hooks.* sections
Posted by Ross Lagerwall 9 months, 2 weeks ago
On Thu, Nov 7, 2024 at 3:15 PM Roger Pau Monne <roger.pau@citrix.com> wrote:
>
> Not all toolchains generate symbols for the .livepatch.hooks.* sections,
> neither those symbols are required by the livepatch loading logic in Xen to
> find and process the hooks.  Hooks in livepatch payloads are found and
> processed based exclusively on section data.
>
> The unconditional attempt to expect each hook serction to have a matching
> symbol leads to a segmentation fault in create-diff-object when such symbol is
> not present, as the code references a NULL pointer.
>
> Fix this by not attempting to include symbols associated with hook sections.
>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
>  create-diff-object.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/create-diff-object.c b/create-diff-object.c
> index d8a2afbf2774..924059a1842b 100644
> --- a/create-diff-object.c
> +++ b/create-diff-object.c
> @@ -1555,8 +1555,6 @@ static int kpatch_include_hook_elements(struct kpatch_elf *kelf)
>                                 sym->sec->sym = NULL;
>                                 /* use section symbol instead */
>                                 rela->sym = sym->sec->secsym;
> -                       } else {
> -                               sec->secsym->include = 1;
>                         }
>                 }
>         }
> --
> 2.46.0
>

Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>

Thanks