提交 1e2d3c49 编写于 作者: D David S. Miller

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Daniel Borkmann says:

====================
pull-request: bpf 2018-11-03

The following pull-request contains BPF updates for your *net* tree.

The main changes are:

1) Fix BPF prog kallsyms and bpf_prog_get_info_by_fd() jited address export
   to not use page start but actual start instead to work correctly with
   profiling e.g. finding hot instructions from stack traces. Also fix latter
   with regards to dumping address and jited len for !multi prog, from Song.

2) Fix bpf_prog_get_info_by_fd() for !root to zero info.nr_jited_func_lens
   instead of leaving the user provided length, from Daniel.
====================
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
...@@ -553,7 +553,6 @@ bool is_bpf_text_address(unsigned long addr) ...@@ -553,7 +553,6 @@ bool is_bpf_text_address(unsigned long addr)
int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type, int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
char *sym) char *sym)
{ {
unsigned long symbol_start, symbol_end;
struct bpf_prog_aux *aux; struct bpf_prog_aux *aux;
unsigned int it = 0; unsigned int it = 0;
int ret = -ERANGE; int ret = -ERANGE;
...@@ -566,10 +565,9 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type, ...@@ -566,10 +565,9 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
if (it++ != symnum) if (it++ != symnum)
continue; continue;
bpf_get_prog_addr_region(aux->prog, &symbol_start, &symbol_end);
bpf_get_prog_name(aux->prog, sym); bpf_get_prog_name(aux->prog, sym);
*value = symbol_start; *value = (unsigned long)aux->prog->bpf_func;
*type = BPF_SYM_ELF_TYPE; *type = BPF_SYM_ELF_TYPE;
ret = 0; ret = 0;
......
...@@ -2078,6 +2078,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, ...@@ -2078,6 +2078,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
info.jited_prog_len = 0; info.jited_prog_len = 0;
info.xlated_prog_len = 0; info.xlated_prog_len = 0;
info.nr_jited_ksyms = 0; info.nr_jited_ksyms = 0;
info.nr_jited_func_lens = 0;
goto done; goto done;
} }
...@@ -2158,11 +2159,11 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, ...@@ -2158,11 +2159,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,10 +2171,17 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, ...@@ -2170,10 +2171,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);
for (i = 0; i < ulen; i++) { if (prog->aux->func_cnt) {
ksym_addr = (ulong) prog->aux->func[i]->bpf_func; for (i = 0; i < ulen; i++) {
ksym_addr &= PAGE_MASK; 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 {
...@@ -2182,7 +2190,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, ...@@ -2182,7 +2190,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;
...@@ -2191,9 +2199,16 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, ...@@ -2191,9 +2199,16 @@ 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);
for (i = 0; i < ulen; i++) { if (prog->aux->func_cnt) {
func_len = prog->aux->func[i]->jited_len; for (i = 0; i < ulen; i++) {
if (put_user(func_len, &user_lens[i])) func_len =
prog->aux->func[i]->jited_len;
if (put_user(func_len, &user_lens[i]))
return -EFAULT;
}
} else {
func_len = prog->jited_len;
if (put_user(func_len, &user_lens[0]))
return -EFAULT; return -EFAULT;
} }
} else { } else {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册