Lines Matching +full:attr +full:- +full:cnt +full:- +full:name
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com
18 #include <linux/error-injection.h>
56 static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name) in bpf_get_raw_tracepoint_module() argument
64 for (i = 0; i < btm->module->num_bpf_raw_events; ++i) { in bpf_get_raw_tracepoint_module()
65 btp = &btm->module->bpf_raw_events[i]; in bpf_get_raw_tracepoint_module()
66 if (!strcmp(btp->tp->name, name)) { in bpf_get_raw_tracepoint_module()
67 if (try_module_get(btm->module)) in bpf_get_raw_tracepoint_module()
78 static struct bpf_raw_event_map *bpf_get_raw_tracepoint_module(const char *name) in bpf_get_raw_tracepoint_module() argument
97 * trace_call_bpf - invoke BPF program
106 * 0 - return from kprobe (event is filtered out)
107 * 1 - store kprobe event into ring buffer
120 * and don't send kprobe event into ring-buffer, in trace_call_bpf()
130 * whether call->prog_array is empty or not, which is in trace_call_bpf()
134 * non-NULL, we go into trace_call_bpf() and do the actual in trace_call_bpf()
143 ret = bpf_prog_run_array(rcu_dereference(call->prog_array), in trace_call_bpf()
206 * strncpy_from_user() does long-sized strides in the fast path. If the in bpf_probe_read_user_str_common()
330 * access_ok() should prevent writing to non-user memory, but in in BPF_CALL_3()
340 current->flags & (PF_KTHREAD | PF_EXITING))) in BPF_CALL_3()
341 return -EPERM; in BPF_CALL_3()
343 return -EPERM; in BPF_CALL_3()
363 current->comm, task_pid_nr(current)); in bpf_get_probe_write_proto()
435 return -EINVAL; in BPF_CALL_4()
477 return -EINVAL; in BPF_CALL_5()
488 return seq_has_overflowed(m) ? -EOVERFLOW : 0; in BPF_CALL_5()
507 return seq_write(m, data, len) ? -EOVERFLOW : 0; in BPF_CALL_3()
531 return btf_type_seq_show_flags(btf, btf_id, ptr->ptr, m, flags); in BPF_CALL_4()
555 return -EINVAL; in get_map_perf_counter()
558 if (unlikely(index >= array->map.max_entries)) in get_map_perf_counter()
559 return -E2BIG; in get_map_perf_counter()
561 ee = READ_ONCE(array->ptrs[index]); in get_map_perf_counter()
563 return -ENOENT; in get_map_perf_counter()
565 return perf_event_read_local(ee->event, value, enabled, running); in get_map_perf_counter()
575 * this api is ugly since we miss [-22..-2] range of valid in BPF_CALL_2()
594 int err = -EINVAL; in BPF_CALL_4()
598 err = get_map_perf_counter(map, flags, &buf->counter, &buf->enabled, in BPF_CALL_4()
599 &buf->running); in BPF_CALL_4()
631 if (unlikely(index >= array->map.max_entries)) in __bpf_perf_event_output()
632 return -E2BIG; in __bpf_perf_event_output()
634 ee = READ_ONCE(array->ptrs[index]); in __bpf_perf_event_output()
636 return -ENOENT; in __bpf_perf_event_output()
638 event = ee->event; in __bpf_perf_event_output()
639 if (unlikely(event->attr.type != PERF_TYPE_SOFTWARE || in __bpf_perf_event_output()
640 event->attr.config != PERF_COUNT_SW_BPF_OUTPUT)) in __bpf_perf_event_output()
641 return -EINVAL; in __bpf_perf_event_output()
643 if (unlikely(event->oncpu != cpu)) in __bpf_perf_event_output()
644 return -EOPNOTSUPP; in __bpf_perf_event_output()
678 if (WARN_ON_ONCE(nest_level > ARRAY_SIZE(sds->sds))) { in BPF_CALL_5()
679 err = -EBUSY; in BPF_CALL_5()
683 sd = &sds->sds[nest_level - 1]; in BPF_CALL_5()
686 err = -EINVAL; in BPF_CALL_5()
743 ret = -EBUSY; in bpf_event_output()
746 sd = this_cpu_ptr(&bpf_misc_sds.sds[nest_level - 1]); in bpf_event_output()
747 regs = this_cpu_ptr(&bpf_pt_regs.regs[nest_level - 1]); in bpf_event_output()
804 if (unlikely(idx >= array->map.max_entries)) in BPF_CALL_2()
805 return -E2BIG; in BPF_CALL_2()
807 cgrp = READ_ONCE(array->ptrs[idx]); in BPF_CALL_2()
809 return -EAGAIN; in BPF_CALL_2()
836 group_send_sig_info(work->sig, SEND_SIG_PRIV, work->task, work->type); in do_bpf_send_signal()
837 put_task_struct(work->task); in do_bpf_send_signal()
849 if (unlikely(current->flags & (PF_KTHREAD | PF_EXITING))) in bpf_send_signal_common()
850 return -EPERM; in bpf_send_signal_common()
852 return -EPERM; in bpf_send_signal_common()
855 return -EPERM; in bpf_send_signal_common()
862 return -EINVAL; in bpf_send_signal_common()
865 if (irq_work_is_busy(&work->irq_work)) in bpf_send_signal_common()
866 return -EBUSY; in bpf_send_signal_common()
872 work->task = get_task_struct(current); in bpf_send_signal_common()
873 work->sig = sig; in bpf_send_signal_common()
874 work->type = type; in bpf_send_signal_common()
875 irq_work_queue(&work->irq_work); in bpf_send_signal_common()
928 len = buf + sz - p; in BPF_CALL_3()
953 if (prog->type == BPF_PROG_TYPE_TRACING && in BTF_ID()
954 prog->expected_attach_type == BPF_TRACE_ITER) in BTF_ID()
957 if (prog->type == BPF_PROG_TYPE_LSM) in BTF_ID()
958 return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id); in BTF_ID()
961 prog->aux->attach_btf_id); in BTF_ID()
987 return -EINVAL; in bpf_btf_printf_prepare()
990 return -EINVAL; in bpf_btf_printf_prepare()
995 return IS_ERR(*btf) ? PTR_ERR(*btf) : -EINVAL; in bpf_btf_printf_prepare()
997 if (ptr->type_id > 0) in bpf_btf_printf_prepare()
998 *btf_id = ptr->type_id; in bpf_btf_printf_prepare()
1000 return -EINVAL; in bpf_btf_printf_prepare()
1005 return -ENOENT; in bpf_btf_printf_prepare()
1021 return btf_type_snprintf_show(btf, btf_id, ptr->ptr, str, str_size, in BPF_CALL_5()
1039 return ((u64 *)ctx)[-2]; in BPF_CALL_1()
1054 /* Being extra safe in here in case entry ip is on the page-edge. */ in get_entry_ip()
1055 if (get_kernel_nofault(instr, (u32 *) fentry_ip - 1)) in get_entry_ip()
1058 fentry_ip -= ENDBR_INSN_SIZE; in get_entry_ip()
1071 run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx); in BPF_CALL_1()
1072 if (run_ctx->is_uprobe) in BPF_CALL_1()
1073 return ((struct uprobe_dispatch_data *)current->utask->vaddr)->bp_addr; in BPF_CALL_1()
1078 if (!kp || !(kp->flags & KPROBE_FLAG_ON_FUNC_ENTRY)) in BPF_CALL_1()
1081 return get_entry_ip((uintptr_t)kp->addr); in BPF_CALL_1()
1093 return bpf_kprobe_multi_entry_ip(current->bpf_ctx); in BPF_CALL_1()
1105 return bpf_kprobe_multi_cookie(current->bpf_ctx); in BPF_CALL_1()
1117 return bpf_uprobe_multi_entry_ip(current->bpf_ctx); in BPF_CALL_1()
1129 return bpf_uprobe_multi_cookie(current->bpf_ctx); in BPF_CALL_1()
1143 run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx); in BPF_CALL_1()
1144 return run_ctx->bpf_cookie; in BPF_CALL_1()
1156 return ctx->event->bpf_cookie; in BPF_CALL_1()
1170 run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx); in BPF_CALL_1()
1171 return run_ctx->bpf_cookie; in BPF_CALL_1()
1184 return -ENOENT; in BPF_CALL_3()
1192 return -EINVAL; in BPF_CALL_3()
1195 return -ENOENT; in BPF_CALL_3()
1212 u64 nr_args = ((u64 *)ctx)[-1]; in BPF_CALL_3()
1215 return -EINVAL; in BPF_CALL_3()
1232 u64 nr_args = ((u64 *)ctx)[-1]; in BPF_CALL_2()
1249 return ((u64 *)ctx)[-1]; in BPF_CALL_1()
1260 __diag_ignore_all("-Wmissing-prototypes",
1264 * bpf_lookup_user_key - lookup a key by its serial
1266 * @flags: lookup-specific flags
1277 * one of the available key-specific kfuncs.
1310 bkey->key = key_ref_to_ptr(key_ref); in bpf_lookup_user_key()
1311 bkey->has_ref = true; in bpf_lookup_user_key()
1317 * bpf_lookup_system_key - lookup a key by a system-defined ID
1335 * pre-determined ID on success, a NULL pointer otherwise
1348 bkey->key = (struct key *)(unsigned long)id; in bpf_lookup_system_key()
1349 bkey->has_ref = false; in bpf_lookup_system_key()
1355 * bpf_key_put - decrement key reference count if key is valid and free bpf_key
1363 if (bkey->has_ref) in bpf_key_put()
1364 key_put(bkey->key); in bpf_key_put()
1371 * bpf_verify_pkcs7_signature - verify a PKCS#7 signature
1387 if (trusted_keyring->has_ref) { in bpf_verify_pkcs7_signature()
1396 ret = key_validate(trusted_keyring->key); in bpf_verify_pkcs7_signature()
1401 return verify_pkcs7_signature(data_ptr->data, in bpf_verify_pkcs7_signature()
1403 sig_ptr->data, in bpf_verify_pkcs7_signature()
1405 trusted_keyring->key, in bpf_verify_pkcs7_signature()
1583 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI) in kprobe_prog_func_proto()
1585 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI) in kprobe_prog_func_proto()
1589 if (prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI) in kprobe_prog_func_proto()
1591 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI) in kprobe_prog_func_proto()
1737 int err = -EINVAL; in BPF_CALL_3()
1741 err = perf_event_read_local(ctx->event, &buf->counter, &buf->enabled, in BPF_CALL_3()
1742 &buf->running); in BPF_CALL_3()
1764 struct perf_branch_stack *br_stack = ctx->data->br_stack; in BPF_CALL_4()
1768 return -EINVAL; in BPF_CALL_4()
1770 if (unlikely(!(ctx->data->sample_flags & PERF_SAMPLE_BRANCH_STACK))) in BPF_CALL_4()
1771 return -ENOENT; in BPF_CALL_4()
1774 return -ENOENT; in BPF_CALL_4()
1777 return br_stack->nr * br_entry_size; in BPF_CALL_4()
1780 return -EINVAL; in BPF_CALL_4()
1782 to_copy = min_t(u32, br_stack->nr * br_entry_size, size); in BPF_CALL_4()
1783 memcpy(buf, br_stack->entries, to_copy); in BPF_CALL_4()
1837 if (nest_level > ARRAY_SIZE(tp_regs->regs)) { in get_bpf_raw_tp_regs()
1839 return ERR_PTR(-EBUSY); in get_bpf_raw_tp_regs()
1842 return &tp_regs->regs[nest_level - 1]; in get_bpf_raw_tp_regs()
1985 return prog->expected_attach_type == BPF_TRACE_ITER ? in tracing_prog_func_proto()
1989 return prog->expected_attach_type == BPF_TRACE_ITER ? in tracing_prog_func_proto()
1993 return prog->expected_attach_type == BPF_TRACE_ITER ? in tracing_prog_func_proto()
2008 if (!fn && prog->expected_attach_type == BPF_TRACE_ITER) in tracing_prog_func_proto()
2034 return -ENOTSUPP; in bpf_prog_test_run_tracing()
2065 info->reg_type = PTR_TO_TP_BUFFER; in raw_tp_writable_prog_is_valid_access()
2123 switch (si->off) { in pe_prog_convert_ctx_access()
2126 data), si->dst_reg, si->src_reg, in pe_prog_convert_ctx_access()
2128 *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, in pe_prog_convert_ctx_access()
2134 data), si->dst_reg, si->src_reg, in pe_prog_convert_ctx_access()
2136 *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, in pe_prog_convert_ctx_access()
2142 regs), si->dst_reg, si->src_reg, in pe_prog_convert_ctx_access()
2144 *insn++ = BPF_LDX_MEM(BPF_SIZEOF(long), si->dst_reg, si->dst_reg, in pe_prog_convert_ctx_access()
2145 si->off); in pe_prog_convert_ctx_access()
2149 return insn - insn_buf; in pe_prog_convert_ctx_access()
2171 int ret = -EEXIST; in perf_event_attach_bpf_prog()
2175 * and only if they are on the opt-in list. in perf_event_attach_bpf_prog()
2177 if (prog->kprobe_override && in perf_event_attach_bpf_prog()
2178 (!trace_kprobe_on_func_entry(event->tp_event) || in perf_event_attach_bpf_prog()
2179 !trace_kprobe_error_injectable(event->tp_event))) in perf_event_attach_bpf_prog()
2180 return -EINVAL; in perf_event_attach_bpf_prog()
2184 if (event->prog) in perf_event_attach_bpf_prog()
2187 old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); in perf_event_attach_bpf_prog()
2190 ret = -E2BIG; in perf_event_attach_bpf_prog()
2198 /* set the new array to event->tp_event and set event->prog */ in perf_event_attach_bpf_prog()
2199 event->prog = prog; in perf_event_attach_bpf_prog()
2200 event->bpf_cookie = bpf_cookie; in perf_event_attach_bpf_prog()
2201 rcu_assign_pointer(event->tp_event->prog_array, new_array); in perf_event_attach_bpf_prog()
2217 if (!event->prog) in perf_event_detach_bpf_prog()
2220 old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); in perf_event_detach_bpf_prog()
2224 ret = bpf_prog_array_copy(old_array, event->prog, NULL, 0, &new_array); in perf_event_detach_bpf_prog()
2226 bpf_prog_array_delete_safe(old_array, event->prog); in perf_event_detach_bpf_prog()
2228 rcu_assign_pointer(event->tp_event->prog_array, new_array); in perf_event_detach_bpf_prog()
2236 * programs and uses tasks-trace-RCU. in perf_event_detach_bpf_prog()
2240 bpf_prog_put(event->prog); in perf_event_detach_bpf_prog()
2241 event->prog = NULL; in perf_event_detach_bpf_prog()
2256 return -EPERM; in perf_event_query_prog_array()
2257 if (event->attr.type != PERF_TYPE_TRACEPOINT) in perf_event_query_prog_array()
2258 return -EINVAL; in perf_event_query_prog_array()
2260 return -EFAULT; in perf_event_query_prog_array()
2264 return -E2BIG; in perf_event_query_prog_array()
2267 return -ENOMEM; in perf_event_query_prog_array()
2270 * is required when user only wants to check for uquery->prog_cnt. in perf_event_query_prog_array()
2276 progs = bpf_event_rcu_dereference(event->tp_event->prog_array); in perf_event_query_prog_array()
2280 if (copy_to_user(&uquery->prog_cnt, &prog_cnt, sizeof(prog_cnt)) || in perf_event_query_prog_array()
2281 copy_to_user(uquery->ids, ids, ids_len * sizeof(u32))) in perf_event_query_prog_array()
2282 ret = -EFAULT; in perf_event_query_prog_array()
2291 struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name) in bpf_get_raw_tracepoint() argument
2296 if (!strcmp(btp->tp->name, name)) in bpf_get_raw_tracepoint()
2300 return bpf_get_raw_tracepoint_module(name); in bpf_get_raw_tracepoint()
2317 if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { in __bpf_trace_run()
2325 this_cpu_dec(*(prog->active)); in __bpf_trace_run()
2375 struct tracepoint *tp = btp->tp; in __bpf_probe_register()
2381 if (prog->aux->max_ctx_offset > btp->num_args * sizeof(u64)) in __bpf_probe_register()
2382 return -EINVAL; in __bpf_probe_register()
2384 if (prog->aux->max_tp_access > btp->writable_size) in __bpf_probe_register()
2385 return -EINVAL; in __bpf_probe_register()
2387 return tracepoint_probe_register_may_exist(tp, (void *)btp->bpf_func, in __bpf_probe_register()
2398 return tracepoint_probe_unregister(btp->tp, (void *)btp->bpf_func, prog); in bpf_probe_unregister()
2410 prog = event->prog; in bpf_get_perf_event_info()
2412 return -ENOENT; in bpf_get_perf_event_info()
2415 if (prog->type == BPF_PROG_TYPE_PERF_EVENT) in bpf_get_perf_event_info()
2416 return -EOPNOTSUPP; in bpf_get_perf_event_info()
2418 *prog_id = prog->aux->id; in bpf_get_perf_event_info()
2419 flags = event->tp_event->flags; in bpf_get_perf_event_info()
2421 is_syscall_tp = is_syscall_trace_event(event->tp_event); in bpf_get_perf_event_info()
2424 *buf = is_tracepoint ? event->tp_event->tp->name in bpf_get_perf_event_info()
2425 : event->tp_event->name; in bpf_get_perf_event_info()
2435 err = -EOPNOTSUPP; in bpf_get_perf_event_info()
2440 event->attr.type == PERF_TYPE_TRACEPOINT); in bpf_get_perf_event_info()
2446 event->attr.type == PERF_TYPE_TRACEPOINT); in bpf_get_perf_event_info()
2460 init_irq_work(&work->irq_work, do_bpf_send_signal); in send_signal_irq_work_init()
2475 if (mod->num_bpf_raw_events == 0 || in bpf_event_notify()
2485 btm->module = module; in bpf_event_notify()
2486 list_add(&btm->list, &bpf_trace_modules); in bpf_event_notify()
2488 ret = -ENOMEM; in bpf_event_notify()
2493 if (btm->module == module) { in bpf_event_notify()
2494 list_del(&btm->list); in bpf_event_notify()
2527 u32 cnt; member
2544 static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) in copy_user_syms() argument
2549 int err = -ENOMEM; in copy_user_syms()
2552 syms = kvmalloc_array(cnt, sizeof(*syms), GFP_KERNEL); in copy_user_syms()
2556 buf = kvmalloc_array(cnt, KSYM_NAME_LEN, GFP_KERNEL); in copy_user_syms()
2560 for (p = buf, i = 0; i < cnt; i++) { in copy_user_syms()
2562 err = -EFAULT; in copy_user_syms()
2567 err = -E2BIG; in copy_user_syms()
2574 us->syms = syms; in copy_user_syms()
2575 us->buf = buf; in copy_user_syms()
2586 static void kprobe_multi_put_modules(struct module **mods, u32 cnt) in kprobe_multi_put_modules() argument
2590 for (i = 0; i < cnt; i++) in kprobe_multi_put_modules()
2596 kvfree(us->syms); in free_user_syms()
2597 kvfree(us->buf); in free_user_syms()
2605 unregister_fprobe(&kmulti_link->fp); in bpf_kprobe_multi_link_release()
2606 kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt); in bpf_kprobe_multi_link_release()
2614 kvfree(kmulti_link->addrs); in bpf_kprobe_multi_link_dealloc()
2615 kvfree(kmulti_link->cookies); in bpf_kprobe_multi_link_dealloc()
2616 kfree(kmulti_link->mods); in bpf_kprobe_multi_link_dealloc()
2623 u64 __user *uaddrs = u64_to_user_ptr(info->kprobe_multi.addrs); in bpf_kprobe_multi_link_fill_link_info()
2625 u32 ucount = info->kprobe_multi.count; in bpf_kprobe_multi_link_fill_link_info()
2629 return -EINVAL; in bpf_kprobe_multi_link_fill_link_info()
2632 info->kprobe_multi.count = kmulti_link->cnt; in bpf_kprobe_multi_link_fill_link_info()
2633 info->kprobe_multi.flags = kmulti_link->flags; in bpf_kprobe_multi_link_fill_link_info()
2637 if (ucount < kmulti_link->cnt) in bpf_kprobe_multi_link_fill_link_info()
2638 err = -ENOSPC; in bpf_kprobe_multi_link_fill_link_info()
2640 ucount = kmulti_link->cnt; in bpf_kprobe_multi_link_fill_link_info()
2643 if (copy_to_user(uaddrs, kmulti_link->addrs, ucount * sizeof(u64))) in bpf_kprobe_multi_link_fill_link_info()
2644 return -EFAULT; in bpf_kprobe_multi_link_fill_link_info()
2648 return -EFAULT; in bpf_kprobe_multi_link_fill_link_info()
2666 cookie_a = link->cookies + (addr_a - link->addrs); in bpf_kprobe_multi_cookie_swap()
2667 cookie_b = link->cookies + (addr_b - link->addrs); in bpf_kprobe_multi_cookie_swap()
2680 return *addr_a < *addr_b ? -1 : 1; in bpf_kprobe_multi_addrs_cmp()
2697 run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx, run_ctx); in bpf_kprobe_multi_cookie()
2698 link = run_ctx->link; in bpf_kprobe_multi_cookie()
2699 if (!link->cookies) in bpf_kprobe_multi_cookie()
2701 entry_ip = run_ctx->entry_ip; in bpf_kprobe_multi_cookie()
2702 addr = bsearch(&entry_ip, link->addrs, link->cnt, sizeof(entry_ip), in bpf_kprobe_multi_cookie()
2706 cookie = link->cookies + (addr - link->addrs); in bpf_kprobe_multi_cookie()
2714 run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx, run_ctx); in bpf_kprobe_multi_entry_ip()
2715 return run_ctx->entry_ip; in bpf_kprobe_multi_entry_ip()
2737 err = bpf_prog_run(link->link.prog, regs); in kprobe_multi_link_prog_run()
2791 if (data->cookies) { in symbols_swap_r()
2794 cookie_a = data->cookies + (name_a - data->funcs); in symbols_swap_r()
2795 cookie_b = data->cookies + (name_b - data->funcs); in symbols_swap_r()
2810 if (arr->mods_cnt == arr->mods_cap) { in add_module()
2811 arr->mods_cap = max(16, arr->mods_cap * 3 / 2); in add_module()
2812 mods = krealloc_array(arr->mods, arr->mods_cap, sizeof(*mods), GFP_KERNEL); in add_module()
2814 return -ENOMEM; in add_module()
2815 arr->mods = mods; in add_module()
2818 arr->mods[arr->mods_cnt] = mod; in add_module()
2819 arr->mods_cnt++; in add_module()
2827 for (i = arr->mods_cnt - 1; i >= 0; i--) { in has_module()
2828 if (arr->mods[i] == mod) in has_module()
2850 err = -EINVAL; in get_modules_for_addrs()
2873 static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt) in addrs_check_error_injection_list() argument
2877 for (i = 0; i < cnt; i++) { in addrs_check_error_injection_list()
2879 return -EINVAL; in addrs_check_error_injection_list()
2884 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_kprobe_multi_link_attach() argument
2890 u32 flags, cnt, size; in bpf_kprobe_multi_link_attach() local
2898 return -EOPNOTSUPP; in bpf_kprobe_multi_link_attach()
2900 if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI) in bpf_kprobe_multi_link_attach()
2901 return -EINVAL; in bpf_kprobe_multi_link_attach()
2903 flags = attr->link_create.kprobe_multi.flags; in bpf_kprobe_multi_link_attach()
2905 return -EINVAL; in bpf_kprobe_multi_link_attach()
2907 uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); in bpf_kprobe_multi_link_attach()
2908 usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms); in bpf_kprobe_multi_link_attach()
2910 return -EINVAL; in bpf_kprobe_multi_link_attach()
2912 cnt = attr->link_create.kprobe_multi.cnt; in bpf_kprobe_multi_link_attach()
2913 if (!cnt) in bpf_kprobe_multi_link_attach()
2914 return -EINVAL; in bpf_kprobe_multi_link_attach()
2915 if (cnt > MAX_KPROBE_MULTI_CNT) in bpf_kprobe_multi_link_attach()
2916 return -E2BIG; in bpf_kprobe_multi_link_attach()
2918 size = cnt * sizeof(*addrs); in bpf_kprobe_multi_link_attach()
2919 addrs = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); in bpf_kprobe_multi_link_attach()
2921 return -ENOMEM; in bpf_kprobe_multi_link_attach()
2923 ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); in bpf_kprobe_multi_link_attach()
2925 cookies = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); in bpf_kprobe_multi_link_attach()
2927 err = -ENOMEM; in bpf_kprobe_multi_link_attach()
2931 err = -EFAULT; in bpf_kprobe_multi_link_attach()
2938 err = -EFAULT; in bpf_kprobe_multi_link_attach()
2947 err = copy_user_syms(&us, usyms, cnt); in bpf_kprobe_multi_link_attach()
2954 sort_r(us.syms, cnt, sizeof(*us.syms), symbols_cmp_r, in bpf_kprobe_multi_link_attach()
2957 err = ftrace_lookup_symbols(us.syms, cnt, addrs); in bpf_kprobe_multi_link_attach()
2963 if (prog->kprobe_override && addrs_check_error_injection_list(addrs, cnt)) { in bpf_kprobe_multi_link_attach()
2964 err = -EINVAL; in bpf_kprobe_multi_link_attach()
2970 err = -ENOMEM; in bpf_kprobe_multi_link_attach()
2974 bpf_link_init(&link->link, BPF_LINK_TYPE_KPROBE_MULTI, in bpf_kprobe_multi_link_attach()
2977 err = bpf_link_prime(&link->link, &link_primer); in bpf_kprobe_multi_link_attach()
2982 link->fp.exit_handler = kprobe_multi_link_exit_handler; in bpf_kprobe_multi_link_attach()
2984 link->fp.entry_handler = kprobe_multi_link_handler; in bpf_kprobe_multi_link_attach()
2986 link->addrs = addrs; in bpf_kprobe_multi_link_attach()
2987 link->cookies = cookies; in bpf_kprobe_multi_link_attach()
2988 link->cnt = cnt; in bpf_kprobe_multi_link_attach()
2989 link->flags = flags; in bpf_kprobe_multi_link_attach()
2998 sort_r(addrs, cnt, sizeof(*addrs), in bpf_kprobe_multi_link_attach()
3004 err = get_modules_for_addrs(&link->mods, addrs, cnt); in bpf_kprobe_multi_link_attach()
3009 link->mods_cnt = err; in bpf_kprobe_multi_link_attach()
3011 err = register_fprobe_ips(&link->fp, addrs, cnt); in bpf_kprobe_multi_link_attach()
3013 kprobe_multi_put_modules(link->mods, link->mods_cnt); in bpf_kprobe_multi_link_attach()
3027 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_kprobe_multi_link_attach() argument
3029 return -EOPNOTSUPP; in bpf_kprobe_multi_link_attach()
3055 u32 cnt; member
3067 u32 cnt) in bpf_uprobe_unregister() argument
3071 for (i = 0; i < cnt; i++) { in bpf_uprobe_unregister()
3072 uprobe_unregister(d_real_inode(path->dentry), uprobes[i].offset, in bpf_uprobe_unregister()
3082 bpf_uprobe_unregister(&umulti_link->path, umulti_link->uprobes, umulti_link->cnt); in bpf_uprobe_multi_link_release()
3083 if (umulti_link->task) in bpf_uprobe_multi_link_release()
3084 put_task_struct(umulti_link->task); in bpf_uprobe_multi_link_release()
3085 path_put(&umulti_link->path); in bpf_uprobe_multi_link_release()
3093 kvfree(umulti_link->uprobes); in bpf_uprobe_multi_link_dealloc()
3106 struct bpf_uprobe_multi_link *link = uprobe->link; in uprobe_prog_run()
3111 struct bpf_prog *prog = link->link.prog; in uprobe_prog_run()
3112 bool sleepable = prog->aux->sleepable; in uprobe_prog_run()
3115 if (link->task && current->mm != link->task->mm) in uprobe_prog_run()
3126 bpf_prog_run(link->link.prog, regs); in uprobe_prog_run()
3145 return uprobe->link->task->mm == mm; in uprobe_multi_link_filter()
3170 run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx); in bpf_uprobe_multi_entry_ip()
3171 return run_ctx->entry_ip; in bpf_uprobe_multi_entry_ip()
3178 run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx); in bpf_uprobe_multi_cookie()
3179 return run_ctx->uprobe->cookie; in bpf_uprobe_multi_cookie()
3182 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_uprobe_multi_link_attach() argument
3192 u32 flags, cnt, i; in bpf_uprobe_multi_link_attach() local
3194 char *name; in bpf_uprobe_multi_link_attach() local
3200 return -EOPNOTSUPP; in bpf_uprobe_multi_link_attach()
3202 if (prog->expected_attach_type != BPF_TRACE_UPROBE_MULTI) in bpf_uprobe_multi_link_attach()
3203 return -EINVAL; in bpf_uprobe_multi_link_attach()
3205 flags = attr->link_create.uprobe_multi.flags; in bpf_uprobe_multi_link_attach()
3207 return -EINVAL; in bpf_uprobe_multi_link_attach()
3210 * path, offsets and cnt are mandatory, in bpf_uprobe_multi_link_attach()
3213 upath = u64_to_user_ptr(attr->link_create.uprobe_multi.path); in bpf_uprobe_multi_link_attach()
3214 uoffsets = u64_to_user_ptr(attr->link_create.uprobe_multi.offsets); in bpf_uprobe_multi_link_attach()
3215 cnt = attr->link_create.uprobe_multi.cnt; in bpf_uprobe_multi_link_attach()
3216 pid = attr->link_create.uprobe_multi.pid; in bpf_uprobe_multi_link_attach()
3218 if (!upath || !uoffsets || !cnt || pid < 0) in bpf_uprobe_multi_link_attach()
3219 return -EINVAL; in bpf_uprobe_multi_link_attach()
3220 if (cnt > MAX_UPROBE_MULTI_CNT) in bpf_uprobe_multi_link_attach()
3221 return -E2BIG; in bpf_uprobe_multi_link_attach()
3223 uref_ctr_offsets = u64_to_user_ptr(attr->link_create.uprobe_multi.ref_ctr_offsets); in bpf_uprobe_multi_link_attach()
3224 ucookies = u64_to_user_ptr(attr->link_create.uprobe_multi.cookies); in bpf_uprobe_multi_link_attach()
3226 name = strndup_user(upath, PATH_MAX); in bpf_uprobe_multi_link_attach()
3227 if (IS_ERR(name)) { in bpf_uprobe_multi_link_attach()
3228 err = PTR_ERR(name); in bpf_uprobe_multi_link_attach()
3232 err = kern_path(name, LOOKUP_FOLLOW, &path); in bpf_uprobe_multi_link_attach()
3233 kfree(name); in bpf_uprobe_multi_link_attach()
3238 err = -EBADF; in bpf_uprobe_multi_link_attach()
3247 err = -ESRCH; in bpf_uprobe_multi_link_attach()
3252 err = -ENOMEM; in bpf_uprobe_multi_link_attach()
3255 uprobes = kvcalloc(cnt, sizeof(*uprobes), GFP_KERNEL); in bpf_uprobe_multi_link_attach()
3260 for (i = 0; i < cnt; i++) { in bpf_uprobe_multi_link_attach()
3262 err = -EFAULT; in bpf_uprobe_multi_link_attach()
3266 err = -EFAULT; in bpf_uprobe_multi_link_attach()
3270 err = -EFAULT; in bpf_uprobe_multi_link_attach()
3285 link->cnt = cnt; in bpf_uprobe_multi_link_attach()
3286 link->uprobes = uprobes; in bpf_uprobe_multi_link_attach()
3287 link->path = path; in bpf_uprobe_multi_link_attach()
3288 link->task = task; in bpf_uprobe_multi_link_attach()
3290 bpf_link_init(&link->link, BPF_LINK_TYPE_UPROBE_MULTI, in bpf_uprobe_multi_link_attach()
3293 for (i = 0; i < cnt; i++) { in bpf_uprobe_multi_link_attach()
3294 err = uprobe_register_refctr(d_real_inode(link->path.dentry), in bpf_uprobe_multi_link_attach()
3299 link->cnt = i; in bpf_uprobe_multi_link_attach()
3304 err = bpf_link_prime(&link->link, &link_primer); in bpf_uprobe_multi_link_attach()
3311 bpf_uprobe_unregister(&path, uprobes, link->cnt); in bpf_uprobe_multi_link_attach()
3323 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_uprobe_multi_link_attach() argument
3325 return -EOPNOTSUPP; in bpf_uprobe_multi_link_attach()