aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorSong Liu <songliubraving@fb.com>2018-11-02 13:16:17 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-11-02 16:39:01 -0400
commitff1889fc531f582f902175c0acc80321af540b24 (patch)
tree83330b3be066e445313c856462efc8e11cdb71b8 /kernel
parentde57e99ceb65d0d7775cc14a8ba5931d7de1d708 (diff)
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>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/bpf/syscall.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 34a9eef5992c..9418174c276c 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -2158,11 +2158,11 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
2158 } 2158 }
2159 2159
2160 ulen = info.nr_jited_ksyms; 2160 ulen = info.nr_jited_ksyms;
2161 info.nr_jited_ksyms = prog->aux->func_cnt; 2161 info.nr_jited_ksyms = prog->aux->func_cnt ? : 1;
2162 if (info.nr_jited_ksyms && ulen) { 2162 if (info.nr_jited_ksyms && ulen) {
2163 if (bpf_dump_raw_ok()) { 2163 if (bpf_dump_raw_ok()) {
2164 unsigned long ksym_addr;
2164 u64 __user *user_ksyms; 2165 u64 __user *user_ksyms;
2165 ulong ksym_addr;
2166 u32 i; 2166 u32 i;
2167 2167
2168 /* copy the address of the kernel symbol 2168 /* copy the address of the kernel symbol
@@ -2170,9 +2170,17 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
2170 */ 2170 */
2171 ulen = min_t(u32, info.nr_jited_ksyms, ulen); 2171 ulen = min_t(u32, info.nr_jited_ksyms, ulen);
2172 user_ksyms = u64_to_user_ptr(info.jited_ksyms); 2172 user_ksyms = u64_to_user_ptr(info.jited_ksyms);
2173 for (i = 0; i < ulen; i++) { 2173 if (prog->aux->func_cnt) {
2174 ksym_addr = (ulong) prog->aux->func[i]->bpf_func; 2174 for (i = 0; i < ulen; i++) {
2175 if (put_user((u64) ksym_addr, &user_ksyms[i])) 2175 ksym_addr = (unsigned long)
2176 prog->aux->func[i]->bpf_func;
2177 if (put_user((u64) ksym_addr,
2178 &user_ksyms[i]))
2179 return -EFAULT;
2180 }
2181 } else {
2182 ksym_addr = (unsigned long) prog->bpf_func;
2183 if (put_user((u64) ksym_addr, &user_ksyms[0]))
2176 return -EFAULT; 2184 return -EFAULT;
2177 } 2185 }
2178 } else { 2186 } else {
@@ -2181,7 +2189,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
2181 } 2189 }
2182 2190
2183 ulen = info.nr_jited_func_lens; 2191 ulen = info.nr_jited_func_lens;
2184 info.nr_jited_func_lens = prog->aux->func_cnt; 2192 info.nr_jited_func_lens = prog->aux->func_cnt ? : 1;
2185 if (info.nr_jited_func_lens && ulen) { 2193 if (info.nr_jited_func_lens && ulen) {
2186 if (bpf_dump_raw_ok()) { 2194 if (bpf_dump_raw_ok()) {
2187 u32 __user *user_lens; 2195 u32 __user *user_lens;
@@ -2190,9 +2198,16 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog,
2190 /* copy the JITed image lengths for each function */ 2198 /* copy the JITed image lengths for each function */
2191 ulen = min_t(u32, info.nr_jited_func_lens, ulen); 2199 ulen = min_t(u32, info.nr_jited_func_lens, ulen);
2192 user_lens = u64_to_user_ptr(info.jited_func_lens); 2200 user_lens = u64_to_user_ptr(info.jited_func_lens);
2193 for (i = 0; i < ulen; i++) { 2201 if (prog->aux->func_cnt) {
2194 func_len = prog->aux->func[i]->jited_len; 2202 for (i = 0; i < ulen; i++) {
2195 if (put_user(func_len, &user_lens[i])) 2203 func_len =
2204 prog->aux->func[i]->jited_len;
2205 if (put_user(func_len, &user_lens[i]))
2206 return -EFAULT;
2207 }
2208 } else {
2209 func_len = prog->jited_len;
2210 if (put_user(func_len, &user_lens[0]))
2196 return -EFAULT; 2211 return -EFAULT;
2197 } 2212 }
2198 } else { 2213 } else {