Skip to content

Commit

Permalink
livepatch: avoid relocations referencing ignored section symbols
Browse files Browse the repository at this point in the history
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é <[email protected]>
Tested-by: Bjoern Doebel <[email protected]>
Reviewed-by: Jan Beulich <[email protected]>
Reviewed-by: Ross Lagerwall <[email protected]>
master commit: 9120b57
master date: 2022-04-08 10:27:11 +0200
  • Loading branch information
royger authored and jbeulich committed Apr 8, 2022
1 parent 46d80ba commit b953760
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions xen/arch/arm/arm32/livepatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
7 changes: 7 additions & 0 deletions xen/arch/arm/arm64/livepatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
7 changes: 7 additions & 0 deletions xen/arch/x86/livepatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,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;

Expand Down
6 changes: 6 additions & 0 deletions xen/common/livepatch_elf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand Down
1 change: 1 addition & 0 deletions xen/include/xen/livepatch_elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct livepatch_elf_sec {
struct livepatch_elf_sym {
const Elf_Sym *sym;
const char *name;
bool ignored;
};

struct livepatch_elf {
Expand Down

0 comments on commit b953760

Please sign in to comment.