bpftool: Don't crash on missing xlated program instructions
Subsystems (4)
PATCH 1/1 bpftool: Don't crash on missing xlated program instructions
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.
--- tools/bpf/bpftool/prog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/prog.c +1 -1
@@ -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 ; }
Signature · 1 line
2.25.0
2020-02-06 11:29 UTC+0100 ~ Toke Høiland-Jørgensen <[email protected]>
Quoted 18 lines
Turns out the xlated program instructions can also be missing if
kptr_restrictsysctl is set. This means that the previous fix to check thejited_prog_insnspointer was insufficient; add another check of thexlated_prog_insnspointer 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 <[email protected]>--- tools/bpf/bpftool/prog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/bpf/bpftool/prog.c +0
-0
tools/bpf/bpftool/prog.c prog_dump(struct bpf_prog_info *info, enum dump_mode mode, · line 542
Quoted 8 lines
tools/bpf/bpftool/prog.c +1
-1@@ -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!
Quoted 8 lines · Toke Høiland-Jørgensen
Turns out the xlated program instructions can also be missing if
kptr_restrictsysctl is set. This means that the previous fix to check thejited_prog_insnspointer was insufficient; add another check of thexlated_prog_insnspointer 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 <[email protected]>
Applied, thanks!