Skip to content

Commit

Permalink
[squash] livepatch/klp-convert: fix klp-convert off-by-one sympos
Browse files Browse the repository at this point in the history
Note: squash with ("livepatch: Add klp-convert tool")

There is a small bug in valid_sympos() when sympos > 0 and when the
the position is the last obj:sym in the set.

When there is a lone obj:sym name, we should expect its sympos=0,
however, when there are multiple obj:sym names found, its sympos
specifies the symbol indexed from 1 (not 0).

Split these two cases up to clarify the code. In addition to fixing the
above case, also strengthen the sympos=0 case by verifying that there is
indeed only a single obj:sym name found.

[joe: separate and fix valid_sympos() sympos=0 and !=0 checks]

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
  • Loading branch information
joe-lawrence committed Mar 18, 2019
1 parent d7f4d26 commit 1ed8e5b
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions scripts/livepatch/klp-convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,19 +328,47 @@ static struct symbol_entry *find_sym_entry_by_name(char *name)
static bool valid_sympos(struct sympos *sp)
{
struct symbol_entry *e;
int counter = 0;

list_for_each_entry(e, &symbols, list) {
if ((strcmp(e->symbol_name, sp->symbol_name) == 0) &&
(strcmp(e->object_name, sp->object_name) == 0)) {
if (counter == sp->pos)
return true;
counter++;
if (sp->pos == 0) {

/*
* sympos of 0 is reserved for uniquely named obj:sym,
* verify that this is the case
*/
int counter = 0;
list_for_each_entry(e, &symbols, list) {
if ((strcmp(e->symbol_name, sp->symbol_name) == 0) &&
(strcmp(e->object_name, sp->object_name) == 0)) {
counter++;
}
}
if (counter == 1)
return true;

WARN("Provided KLP_SYMPOS of 0, but found %d symbols matching: %s.%s,%d",
counter, sp->object_name, sp->symbol_name,
sp->pos);

} else {

/*
* sympos > 0 indicates a specific commonly-named obj:sym,
* indexing starts with 1
*/
int index = 1;
list_for_each_entry(e, &symbols, list) {
if ((strcmp(e->symbol_name, sp->symbol_name) == 0) &&
(strcmp(e->object_name, sp->object_name) == 0)) {
if (index == sp->pos)
return true;
index++;
}
}

WARN("Provided KLP_SYMPOS does not match a symbol: %s.%s,%d",
sp->object_name, sp->symbol_name, sp->pos);
}

WARN("Provided KLP_SYMPOS does not match a symbol: %s.%s,%d",
sp->object_name, sp->symbol_name, sp->pos);
print_valid_module_relocs(sp->symbol_name);

return false;
Expand Down

0 comments on commit 1ed8e5b

Please sign in to comment.