2020-04-03 13:20:33

by Julien Thierry

[permalink] [raw]
Subject: [PATCH] objtool: Fix off-by-one in symbol_by_offset()

Sometimes, WARN_FUNC() and other users of symbol_by_offset() will
associate the first instruction of a symbol with the symbol preceding
it.
This is because symbol->offset + symbol->len is already outside of the
symbol's range.

Signed-off-by: Julien Thierry <[email protected]>
---
tools/objtool/elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
index 09ddc8f1def3..c4857fa3f1d1 100644
--- a/tools/objtool/elf.c
+++ b/tools/objtool/elf.c
@@ -105,7 +105,7 @@ static int symbol_by_offset(const void *key, const struct rb_node *node)

if (*o < s->offset)
return -1;
- if (*o > s->offset + s->len)
+ if (*o >= s->offset + s->len)
return 1;

return 0;
--
2.21.1


2020-04-03 15:44:52

by Josh Poimboeuf

[permalink] [raw]
Subject: Re: [PATCH] objtool: Fix off-by-one in symbol_by_offset()

On Fri, Apr 03, 2020 at 02:17:30PM +0100, Julien Thierry wrote:
> Sometimes, WARN_FUNC() and other users of symbol_by_offset() will
> associate the first instruction of a symbol with the symbol preceding
> it.
> This is because symbol->offset + symbol->len is already outside of the
> symbol's range.
>
> Signed-off-by: Julien Thierry <[email protected]>
> ---
> tools/objtool/elf.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/objtool/elf.c b/tools/objtool/elf.c
> index 09ddc8f1def3..c4857fa3f1d1 100644
> --- a/tools/objtool/elf.c
> +++ b/tools/objtool/elf.c
> @@ -105,7 +105,7 @@ static int symbol_by_offset(const void *key, const struct rb_node *node)
>
> if (*o < s->offset)
> return -1;
> - if (*o > s->offset + s->len)
> + if (*o >= s->offset + s->len)
> return 1;
>
> return 0;

Thanks - looks like this fixes 2a362ecc3ec9 ("objtool: Optimize
find_symbol_*() and read_symbols()").

--
Josh

2020-04-06 09:11:37

by Miroslav Benes

[permalink] [raw]
Subject: Re: [PATCH] objtool: Fix off-by-one in symbol_by_offset()

On Fri, 3 Apr 2020, Julien Thierry wrote:

> Sometimes, WARN_FUNC() and other users of symbol_by_offset() will
> associate the first instruction of a symbol with the symbol preceding
> it.
> This is because symbol->offset + symbol->len is already outside of the
> symbol's range.
>
> Signed-off-by: Julien Thierry <[email protected]>

Reviewed-by: Miroslav Benes <[email protected]>