* [PATCH -fixes] bpf: resolve_btfids: Fix integer overflow when calling elf_update()
@ 2024-05-27 15:31 Alexandre Ghiti
2024-05-27 16:00 ` Jiri Olsa
0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Ghiti @ 2024-05-27 15:31 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
bpf, linux-kernel, linux-riscv
Cc: Alexandre Ghiti
The following error was encoutered in [1]:
FAILED elf_update(WRITE): no error
elf_update() returns the total size of the file which here happens to be
a ~2.5GB vmlinux file: this size overflows the integer used to hold the
return value of elf_update() and is then interpreted as being negative.
So fix this by using the correct type expected by elf_update() which is
off_t.
Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=218887 [1]
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
---
tools/bpf/resolve_btfids/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index d9520cb826b3..af393c7dee1f 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -728,7 +728,7 @@ static int sets_patch(struct object *obj)
static int symbols_patch(struct object *obj)
{
- int err;
+ off_t err;
if (__symbols_patch(obj, &obj->structs) ||
__symbols_patch(obj, &obj->unions) ||
--
2.39.2
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH -fixes] bpf: resolve_btfids: Fix integer overflow when calling elf_update()
2024-05-27 15:31 [PATCH -fixes] bpf: resolve_btfids: Fix integer overflow when calling elf_update() Alexandre Ghiti
@ 2024-05-27 16:00 ` Jiri Olsa
2024-05-28 5:12 ` Alexandre Ghiti
0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2024-05-27 16:00 UTC (permalink / raw)
To: Alexandre Ghiti
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, bpf,
linux-kernel, linux-riscv
On Mon, May 27, 2024 at 05:31:37PM +0200, Alexandre Ghiti wrote:
> The following error was encoutered in [1]:
>
> FAILED elf_update(WRITE): no error
hi,
this fix got already in, check this patch:
https://patchwork.kernel.org/project/netdevbpf/patch/20240514070931.199694-1-friedrich.vock@gmx.de/
thanks,
jirka
>
> elf_update() returns the total size of the file which here happens to be
> a ~2.5GB vmlinux file: this size overflows the integer used to hold the
> return value of elf_update() and is then interpreted as being negative.
>
> So fix this by using the correct type expected by elf_update() which is
> off_t.
>
> Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
> Link: https://bugzilla.kernel.org/show_bug.cgi?id=218887 [1]
> Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> ---
> tools/bpf/resolve_btfids/main.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> index d9520cb826b3..af393c7dee1f 100644
> --- a/tools/bpf/resolve_btfids/main.c
> +++ b/tools/bpf/resolve_btfids/main.c
> @@ -728,7 +728,7 @@ static int sets_patch(struct object *obj)
>
> static int symbols_patch(struct object *obj)
> {
> - int err;
> + off_t err;
>
> if (__symbols_patch(obj, &obj->structs) ||
> __symbols_patch(obj, &obj->unions) ||
> --
> 2.39.2
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH -fixes] bpf: resolve_btfids: Fix integer overflow when calling elf_update()
2024-05-27 16:00 ` Jiri Olsa
@ 2024-05-28 5:12 ` Alexandre Ghiti
0 siblings, 0 replies; 3+ messages in thread
From: Alexandre Ghiti @ 2024-05-28 5:12 UTC (permalink / raw)
To: Jiri Olsa
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, bpf,
linux-kernel, linux-riscv
Hi Jiri,
On Mon, May 27, 2024 at 6:00 PM Jiri Olsa <olsajiri@gmail.com> wrote:
>
> On Mon, May 27, 2024 at 05:31:37PM +0200, Alexandre Ghiti wrote:
> > The following error was encoutered in [1]:
> >
> > FAILED elf_update(WRITE): no error
>
> hi,
> this fix got already in, check this patch:
> https://patchwork.kernel.org/project/netdevbpf/patch/20240514070931.199694-1-friedrich.vock@gmx.de/
Damn, I missed this.
If possible, I think that adding the link to the bug report (or at
least the "FAILED elf_update(WRITE): no error" string) would make
sense, since it is not a "potential" overflow anymore.
Thanks,
Alex
>
> thanks,
> jirka
>
> >
> > elf_update() returns the total size of the file which here happens to be
> > a ~2.5GB vmlinux file: this size overflows the integer used to hold the
> > return value of elf_update() and is then interpreted as being negative.
> >
> > So fix this by using the correct type expected by elf_update() which is
> > off_t.
> >
> > Fixes: fbbb68de80a4 ("bpf: Add resolve_btfids tool to resolve BTF IDs in ELF object")
> > Link: https://bugzilla.kernel.org/show_bug.cgi?id=218887 [1]
> > Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
> > ---
> > tools/bpf/resolve_btfids/main.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
> > index d9520cb826b3..af393c7dee1f 100644
> > --- a/tools/bpf/resolve_btfids/main.c
> > +++ b/tools/bpf/resolve_btfids/main.c
> > @@ -728,7 +728,7 @@ static int sets_patch(struct object *obj)
> >
> > static int symbols_patch(struct object *obj)
> > {
> > - int err;
> > + off_t err;
> >
> > if (__symbols_patch(obj, &obj->structs) ||
> > __symbols_patch(obj, &obj->unions) ||
> > --
> > 2.39.2
> >
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-05-28 5:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-27 15:31 [PATCH -fixes] bpf: resolve_btfids: Fix integer overflow when calling elf_update() Alexandre Ghiti
2024-05-27 16:00 ` Jiri Olsa
2024-05-28 5:12 ` Alexandre Ghiti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox