Skip to contentSkip to conversation

bpftool: Don't crash on missing xlated program instructions

PATCH Applied Toke Høiland-Jørgensen 3 participants 3 messages Feb 6, 2020 – Feb 7, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

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.

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()")
---
 tools/bpf/bpftool/prog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/prog.c +1 -1
index a3521deca869..b352ab041160 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw

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_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()")
---
  tools/bpf/bpftool/prog.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/bpf/bpftool/prog.c +0 -0
index a3521deca869..b352ab041160 100644

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!

maintainer Applied
#2 lore raw
In reply to Toke Høiland-Jørgensen
Quoted 8 lines · Toke Høiland-Jørgensen

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()")

Applied, thanks!