Skip to contentSkip to conversation

Remove bpf_dump_raw_ok() check for func_info and line_info

PATCH Applied Martin KaFai Lau 3 participants 5 messages Dec 12, 2018 – Dec 13, 2018

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

cover Remove bpf_dump_raw_ok() check for func_info and line_info

This patch set removes the bpf_dump_raw_ok() guard for the func_info and line_info during bpf_prog_get_info_by_fd().

Please see individual patch for details.

Martin KaFai Lau (2):
bpf: Remove bpf_dump_raw_ok() check for func_info and line_info
bpf: Remove !func_info and !line_info check from test_btf and bpftool

 kernel/bpf/syscall.c                   | 32 ++++++++++----------------
 tools/bpf/bpftool/prog.c               |  7 ------
 tools/lib/bpf/bpf_prog_linfo.c         |  6 +----
 tools/testing/selftests/bpf/test_btf.c |  7 ------
 4 files changed, 13 insertions(+), 39 deletions(-)
Signature · 1 line
2.17.1
#2 lore raw

PATCH 2/2 bpf: Remove !func_info and !line_info check from test_btf and bpftool

kernel can provide the func_info and line_info even it fails the btf_dump_raw_ok() test because they don't contain kernel address. This patch removes the corresponding '== 0' test.

---
 tools/bpf/bpftool/prog.c               | 7 -------
 tools/lib/bpf/bpf_prog_linfo.c         | 6 +-----
 tools/testing/selftests/bpf/test_btf.c | 7 -------
 3 files changed, 1 insertion(+), 19 deletions(-)
tools/bpf/bpftool/prog.c +0 -7
index b73b4e473948..ccf462d5c655 100644
@@ -626,13 +626,6 @@ static int do_dump(int argc, char **argv)
 		goto err_free;
 	}
 
-	if (func_info && !info.func_info) {
-		/* kernel.kptr_restrict is set.  No func_info available. */
-		free(func_info);
-		func_info = NULL;
-		nr_finfo = 0;
-	}
-
 	if (linfo && info.nr_line_info != nr_linfo) {
 		p_err("incorrect nr_line_info %u vs. expected %u",
 		      info.nr_line_info, nr_linfo);
tools/lib/bpf/bpf_prog_linfo.c +1 -5
index addd6e9971cc..6978314ea7f6 100644
@@ -107,11 +107,7 @@ struct bpf_prog_linfo *bpf_prog_linfo__new(const struct bpf_prog_info *info)
 
 	nr_linfo = info->nr_line_info;
 
-	/*
-	 * Test !info->line_info because the kernel may NULL
-	 * the ptr if kernel.kptr_restrict is set.
-	 */
-	if (!nr_linfo || !info->line_info)
+	if (!nr_linfo)
 		return NULL;
 
 	/*
tools/testing/selftests/bpf/test_btf.c +0 -7
index f570e0a39959..8478316aaf9a 100644
@@ -3948,12 +3948,6 @@ static int test_get_finfo(const struct prog_info_raw_test *test,
 		goto done;
 	}
 
-	if (CHECK(!info.func_info,
-		  "info.func_info == 0. kernel.kptr_restrict is set?")) {
-		err = -1;
-		goto done;
-	}
-
 	finfo = func_info;
 	for (i = 0; i < test->func_info_cnt; i++) {
 		if (CHECK(finfo->type_id != test->func_info[i][1],
@@ -4077,7 +4071,6 @@ static int test_get_linfo(const struct prog_info_raw_test *test,
 	 * Other fields are not the concern of this test.
 	 */
 	if (CHECK(err == -1 ||
-		  !info.line_info ||
 		  info.nr_line_info != cnt ||
 		  (jited_cnt && !info.jited_line_info) ||
 		  info.nr_jited_line_info != jited_cnt ||
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 bpf: Remove bpf_dump_raw_ok() check for func_info and line_info

In reply to Martin KaFai Lau

The func_info and line_info have the bpf insn offset but they do not contain kernel address. They will still be useful for the userspace tool to annotate the xlated insn.

This patch removes the bpf_dump_raw_ok() guard for the func_info and line_info during bpf_prog_get_info_by_fd().

The guard stays for jited_line_info which contains the kernel address.

Although this bpf_dump_raw_ok() guard behavior has started since the earlier func_info patch series, I marked the Fixes tag to the latest line_info patch series which contains both func_info and line_info and this patch is fixing for both of them.

Fixes c454a46b5efd ("bpf: Add bpf_line_info support")
---
 kernel/bpf/syscall.c | 32 ++++++++++++--------------------
 1 file changed, 12 insertions(+), 20 deletions(-)
kernel/bpf/syscall.c +12 -20
index 70fb11106fc2..b7c585838c72 100644
@@ -2272,33 +2272,25 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
 	ulen = info.nr_func_info;
 	info.nr_func_info = prog->aux->func_info_cnt;
 	if (info.nr_func_info && ulen) {
-		if (bpf_dump_raw_ok()) {
-			char __user *user_finfo;
+		char __user *user_finfo;
 
-			user_finfo = u64_to_user_ptr(info.func_info);
-			ulen = min_t(u32, info.nr_func_info, ulen);
-			if (copy_to_user(user_finfo, prog->aux->func_info,
-					 info.func_info_rec_size * ulen))
-				return -EFAULT;
-		} else {
-			info.func_info = 0;
-		}
+		user_finfo = u64_to_user_ptr(info.func_info);
+		ulen = min_t(u32, info.nr_func_info, ulen);
+		if (copy_to_user(user_finfo, prog->aux->func_info,
+				 info.func_info_rec_size * ulen))
+			return -EFAULT;
 	}
 
 	ulen = info.nr_line_info;
 	info.nr_line_info = prog->aux->nr_linfo;
 	if (info.nr_line_info && ulen) {
-		if (bpf_dump_raw_ok()) {
-			__u8 __user *user_linfo;
+		__u8 __user *user_linfo;
 
-			user_linfo = u64_to_user_ptr(info.line_info);
-			ulen = min_t(u32, info.nr_line_info, ulen);
-			if (copy_to_user(user_linfo, prog->aux->linfo,
-					 info.line_info_rec_size * ulen))
-				return -EFAULT;
-		} else {
-			info.line_info = 0;
-		}
+		user_linfo = u64_to_user_ptr(info.line_info);
+		ulen = min_t(u32, info.nr_line_info, ulen);
+		if (copy_to_user(user_linfo, prog->aux->linfo,
+				 info.line_info_rec_size * ulen))
+			return -EFAULT;
 	}
 
 	ulen = info.nr_jited_line_info;
Signature · 1 line
2.17.1
Acked-by on the v1 series
#3 lore raw
In reply to Martin KaFai Lau
Quoted 9 lines · Martin KaFai Lau

This patch set removes the bpf_dump_raw_ok() guard for the func_info and line_info during bpf_prog_get_info_by_fd().

Please see individual patch for details.

Martin KaFai Lau (2):
bpf: Remove bpf_dump_raw_ok() check for func_info and line_info
bpf: Remove !func_info and !line_info check from test_btf and bpftool

Quoted 6 lines
  kernel/bpf/syscall.c                   | 32 ++++++++++----------------
  tools/bpf/bpftool/prog.c               |  7 ------
  tools/lib/bpf/bpf_prog_linfo.c         |  6 +----
  tools/testing/selftests/bpf/test_btf.c |  7 ------
  4 files changed, 13 insertions(+), 39 deletions(-)

Thanks for the fix! For the whole series,

maintainer Applied
#4 lore raw
In reply to Martin KaFai Lau
Quoted 9 lines · Martin KaFai Lau

This patch set removes the bpf_dump_raw_ok() guard for the func_info and line_info during bpf_prog_get_info_by_fd().

Please see individual patch for details.

Martin KaFai Lau (2):
bpf: Remove bpf_dump_raw_ok() check for func_info and line_info
bpf: Remove !func_info and !line_info check from test_btf and bpftool

Quoted 6 lines
 kernel/bpf/syscall.c                   | 32 ++++++++++----------------
 tools/bpf/bpftool/prog.c               |  7 ------
 tools/lib/bpf/bpf_prog_linfo.c         |  6 +----
 tools/testing/selftests/bpf/test_btf.c |  7 ------
 4 files changed, 13 insertions(+), 39 deletions(-)

Applied, thanks!