Skip to content

Commit 1e2d3c4

Browse files
committed
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: David S. Miller <[email protected]>
2 parents 9680155 + 28c2fae commit 1e2d3c4

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

kernel/bpf/core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ bool is_bpf_text_address(unsigned long addr)
553553
int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
554554
char *sym)
555555
{
556-
unsigned long symbol_start, symbol_end;
557556
struct bpf_prog_aux *aux;
558557
unsigned int it = 0;
559558
int ret = -ERANGE;
@@ -566,10 +565,9 @@ int bpf_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
566565
if (it++ != symnum)
567566
continue;
568567

569-
bpf_get_prog_addr_region(aux->prog, &symbol_start, &symbol_end);
570568
bpf_get_prog_name(aux->prog, sym);
571569

572-
*value = symbol_start;
570+
*value = (unsigned long)aux->prog->bpf_func;
573571
*type = BPF_SYM_ELF_TYPE;
574572

575573
ret = 0;

kernel/bpf/syscall.c

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,6 +2078,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
20782078
info.jited_prog_len = 0;
20792079
info.xlated_prog_len = 0;
20802080
info.nr_jited_ksyms = 0;
2081+
info.nr_jited_func_lens = 0;
20812082
goto done;
20822083
}
20832084

@@ -2158,22 +2159,29 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
21582159
}
21592160

21602161
ulen = info.nr_jited_ksyms;
2161-
info.nr_jited_ksyms = prog->aux->func_cnt;
2162+
info.nr_jited_ksyms = prog->aux->func_cnt ? : 1;
21622163
if (info.nr_jited_ksyms && ulen) {
21632164
if (bpf_dump_raw_ok()) {
2165+
unsigned long ksym_addr;
21642166
u64 __user *user_ksyms;
2165-
ulong ksym_addr;
21662167
u32 i;
21672168

21682169
/* copy the address of the kernel symbol
21692170
* corresponding to each function
21702171
*/
21712172
ulen = min_t(u32, info.nr_jited_ksyms, ulen);
21722173
user_ksyms = u64_to_user_ptr(info.jited_ksyms);
2173-
for (i = 0; i < ulen; i++) {
2174-
ksym_addr = (ulong) prog->aux->func[i]->bpf_func;
2175-
ksym_addr &= PAGE_MASK;
2176-
if (put_user((u64) ksym_addr, &user_ksyms[i]))
2174+
if (prog->aux->func_cnt) {
2175+
for (i = 0; i < ulen; i++) {
2176+
ksym_addr = (unsigned long)
2177+
prog->aux->func[i]->bpf_func;
2178+
if (put_user((u64) ksym_addr,
2179+
&user_ksyms[i]))
2180+
return -EFAULT;
2181+
}
2182+
} else {
2183+
ksym_addr = (unsigned long) prog->bpf_func;
2184+
if (put_user((u64) ksym_addr, &user_ksyms[0]))
21772185
return -EFAULT;
21782186
}
21792187
} else {
@@ -2182,7 +2190,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
21822190
}
21832191

21842192
ulen = info.nr_jited_func_lens;
2185-
info.nr_jited_func_lens = prog->aux->func_cnt;
2193+
info.nr_jited_func_lens = prog->aux->func_cnt ? : 1;
21862194
if (info.nr_jited_func_lens && ulen) {
21872195
if (bpf_dump_raw_ok()) {
21882196
u32 __user *user_lens;
@@ -2191,9 +2199,16 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
21912199
/* copy the JITed image lengths for each function */
21922200
ulen = min_t(u32, info.nr_jited_func_lens, ulen);
21932201
user_lens = u64_to_user_ptr(info.jited_func_lens);
2194-
for (i = 0; i < ulen; i++) {
2195-
func_len = prog->aux->func[i]->jited_len;
2196-
if (put_user(func_len, &user_lens[i]))
2202+
if (prog->aux->func_cnt) {
2203+
for (i = 0; i < ulen; i++) {
2204+
func_len =
2205+
prog->aux->func[i]->jited_len;
2206+
if (put_user(func_len, &user_lens[i]))
2207+
return -EFAULT;
2208+
}
2209+
} else {
2210+
func_len = prog->jited_len;
2211+
if (put_user(func_len, &user_lens[0]))
21972212
return -EFAULT;
21982213
}
21992214
} else {

0 commit comments

Comments
 (0)