Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create-diff-object: check NOP-padded instruction when symbol missing #1374

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion kpatch-build/create-diff-object.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,37 @@ static struct rela *toc_rela(const struct rela *rela)
(unsigned int)rela->addend);
}

static bool padding_is_all_nops(enum architecture arch, struct symbol *sym,
unsigned int expected_offset)
{
unsigned char *padding = NULL;
unsigned long len = sym->sym.st_value;
unsigned int i;
unsigned char nops_insn;

if (expected_offset != 0 || !sym->sec)
return false;

switch (arch) {
case X86_64:
nops_insn = (unsigned char)0x90;
break;
default:
return false;
}

padding = sym->sec->data->d_buf;
for (i = 0; i < len; i ++) {
/*
* For other architecture, len of nops may not be one char.
* In that case, we can compare two arrays.
*/
if (padding[i] != nops_insn)
return false;
}
return true;
}

/*
* When compiling with -ffunction-sections and -fdata-sections, almost every
* symbol gets its own dedicated section. We call such symbols "bundled"
Expand All @@ -247,7 +278,8 @@ static void kpatch_bundle_symbols(struct kpatch_elf *kelf)
else
expected_offset = 0;

if (sym->sym.st_value != expected_offset) {
if (sym->sym.st_value != expected_offset &&
!padding_is_all_nops(kelf->arch, sym, expected_offset)) {
ERROR("symbol %s at offset %lu within section %s, expected %u",
sym->name, sym->sym.st_value,
sym->sec->name, expected_offset);
Expand Down
Loading