All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf] bpftool: Don't crash on missing xlated program instructions
@ 2020-02-06 10:29 Toke Høiland-Jørgensen
  2020-02-06 17:52 ` Quentin Monnet
  2020-02-07 21:50 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Toke Høiland-Jørgensen @ 2020-02-06 10:29 UTC (permalink / raw)
  To: daniel, ast; +Cc: Toke Høiland-Jørgensen, bpf, netdev

Turns out the xlated program instructions can also be missing if
kptr_restrict sysctl is set. This means that the previous fix to check the
jited_prog_insns pointer was insufficient; add another check of the
xlated_prog_insns pointer as well.

Fixes: 5b79bcdf0362 ("bpftool: Don't crash on missing jited insns or ksyms")
Fixes: cae73f233923 ("bpftool: use bpf_program__get_prog_info_linear() in prog.c:do_dump()")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
---
 tools/bpf/bpftool/prog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index a3521deca869..b352ab041160 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -536,7 +536,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
 		buf = (unsigned char *)(info->jited_prog_insns);
 		member_len = info->jited_prog_len;
 	} else {	/* DUMP_XLATED */
-		if (info->xlated_prog_len == 0) {
+		if (info->xlated_prog_len == 0 || !info->xlated_prog_insns) {
 			p_err("error retrieving insn dump: kernel.kptr_restrict set?");
 			return -1;
 		}
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpftool: Don't crash on missing xlated program instructions
  2020-02-06 10:29 [PATCH bpf] bpftool: Don't crash on missing xlated program instructions Toke Høiland-Jørgensen
@ 2020-02-06 17:52 ` Quentin Monnet
  2020-02-07 21:50 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Quentin Monnet @ 2020-02-06 17:52 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen, daniel, ast; +Cc: bpf, netdev

2020-02-06 11:29 UTC+0100 ~ Toke Høiland-Jørgensen <toke@redhat.com>
> Turns out the xlated program instructions can also be missing if
> kptr_restrict sysctl is set. This means that the previous fix to check the
> jited_prog_insns pointer was insufficient; add another check of the
> xlated_prog_insns pointer as well.
> 
> Fixes: 5b79bcdf0362 ("bpftool: Don't crash on missing jited insns or ksyms")
> Fixes: cae73f233923 ("bpftool: use bpf_program__get_prog_info_linear() in prog.c:do_dump()")
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
>   tools/bpf/bpftool/prog.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
> index a3521deca869..b352ab041160 100644
> --- a/tools/bpf/bpftool/prog.c
> +++ b/tools/bpf/bpftool/prog.c
> @@ -536,7 +536,7 @@ prog_dump(struct bpf_prog_info *info, enum dump_mode mode,
>   		buf = (unsigned char *)(info->jited_prog_insns);
>   		member_len = info->jited_prog_len;
>   	} else {	/* DUMP_XLATED */
> -		if (info->xlated_prog_len == 0) {
> +		if (info->xlated_prog_len == 0 || !info->xlated_prog_insns) {
>   			p_err("error retrieving insn dump: kernel.kptr_restrict set?");
>   			return -1;
>   		}
> 

The fix looks good, thanks!

Reviewed-by: Quentin Monnet <quentin@isovalent.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf] bpftool: Don't crash on missing xlated program instructions
  2020-02-06 10:29 [PATCH bpf] bpftool: Don't crash on missing xlated program instructions Toke Høiland-Jørgensen
  2020-02-06 17:52 ` Quentin Monnet
@ 2020-02-07 21:50 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2020-02-07 21:50 UTC (permalink / raw)
  To: Toke Høiland-Jørgensen, ast; +Cc: bpf, netdev

On 2/6/20 11:29 AM, Toke Høiland-Jørgensen wrote:
> Turns out the xlated program instructions can also be missing if
> kptr_restrict sysctl is set. This means that the previous fix to check the
> jited_prog_insns pointer was insufficient; add another check of the
> xlated_prog_insns pointer as well.
> 
> Fixes: 5b79bcdf0362 ("bpftool: Don't crash on missing jited insns or ksyms")
> Fixes: cae73f233923 ("bpftool: use bpf_program__get_prog_info_linear() in prog.c:do_dump()")
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>

Applied, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-07 21:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-06 10:29 [PATCH bpf] bpftool: Don't crash on missing xlated program instructions Toke Høiland-Jørgensen
2020-02-06 17:52 ` Quentin Monnet
2020-02-07 21:50 ` Daniel Borkmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.