mirror of
https://github.com/torvalds/linux
synced 2024-09-20 02:57:25 +00:00
bpf: show main program address and length in bpf_prog_info
Currently, when there is no subprog (prog->aux->func_cnt == 0), bpf_prog_info does not return any jited_ksyms or jited_func_lens. This patch adds main program address (prog->bpf_func) and main program length (prog->jited_len) to bpf_prog_info. Signed-off-by: Song Liu <songliubraving@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
de57e99ceb
commit
ff1889fc53
|
@ -2158,11 +2158,11 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
|
||||||
}
|
}
|
||||||
|
|
||||||
ulen = info.nr_jited_ksyms;
|
ulen = info.nr_jited_ksyms;
|
||||||
info.nr_jited_ksyms = prog->aux->func_cnt;
|
info.nr_jited_ksyms = prog->aux->func_cnt ? : 1;
|
||||||
if (info.nr_jited_ksyms && ulen) {
|
if (info.nr_jited_ksyms && ulen) {
|
||||||
if (bpf_dump_raw_ok()) {
|
if (bpf_dump_raw_ok()) {
|
||||||
|
unsigned long ksym_addr;
|
||||||
u64 __user *user_ksyms;
|
u64 __user *user_ksyms;
|
||||||
ulong ksym_addr;
|
|
||||||
u32 i;
|
u32 i;
|
||||||
|
|
||||||
/* copy the address of the kernel symbol
|
/* copy the address of the kernel symbol
|
||||||
|
@ -2170,9 +2170,17 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
|
||||||
*/
|
*/
|
||||||
ulen = min_t(u32, info.nr_jited_ksyms, ulen);
|
ulen = min_t(u32, info.nr_jited_ksyms, ulen);
|
||||||
user_ksyms = u64_to_user_ptr(info.jited_ksyms);
|
user_ksyms = u64_to_user_ptr(info.jited_ksyms);
|
||||||
|
if (prog->aux->func_cnt) {
|
||||||
for (i = 0; i < ulen; i++) {
|
for (i = 0; i < ulen; i++) {
|
||||||
ksym_addr = (ulong) prog->aux->func[i]->bpf_func;
|
ksym_addr = (unsigned long)
|
||||||
if (put_user((u64) ksym_addr, &user_ksyms[i]))
|
prog->aux->func[i]->bpf_func;
|
||||||
|
if (put_user((u64) ksym_addr,
|
||||||
|
&user_ksyms[i]))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ksym_addr = (unsigned long) prog->bpf_func;
|
||||||
|
if (put_user((u64) ksym_addr, &user_ksyms[0]))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2181,7 +2189,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
|
||||||
}
|
}
|
||||||
|
|
||||||
ulen = info.nr_jited_func_lens;
|
ulen = info.nr_jited_func_lens;
|
||||||
info.nr_jited_func_lens = prog->aux->func_cnt;
|
info.nr_jited_func_lens = prog->aux->func_cnt ? : 1;
|
||||||
if (info.nr_jited_func_lens && ulen) {
|
if (info.nr_jited_func_lens && ulen) {
|
||||||
if (bpf_dump_raw_ok()) {
|
if (bpf_dump_raw_ok()) {
|
||||||
u32 __user *user_lens;
|
u32 __user *user_lens;
|
||||||
|
@ -2190,11 +2198,18 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
|
||||||
/* copy the JITed image lengths for each function */
|
/* copy the JITed image lengths for each function */
|
||||||
ulen = min_t(u32, info.nr_jited_func_lens, ulen);
|
ulen = min_t(u32, info.nr_jited_func_lens, ulen);
|
||||||
user_lens = u64_to_user_ptr(info.jited_func_lens);
|
user_lens = u64_to_user_ptr(info.jited_func_lens);
|
||||||
|
if (prog->aux->func_cnt) {
|
||||||
for (i = 0; i < ulen; i++) {
|
for (i = 0; i < ulen; i++) {
|
||||||
func_len = prog->aux->func[i]->jited_len;
|
func_len =
|
||||||
|
prog->aux->func[i]->jited_len;
|
||||||
if (put_user(func_len, &user_lens[i]))
|
if (put_user(func_len, &user_lens[i]))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
func_len = prog->jited_len;
|
||||||
|
if (put_user(func_len, &user_lens[0]))
|
||||||
|
return -EFAULT;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
info.jited_func_lens = 0;
|
info.jited_func_lens = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue