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()
124 bpf_prog_inc_misses_counters(rcu_dereference(call->prog_array)); in trace_call_bpf()
133 * whether call->prog_array is empty or not, which is in trace_call_bpf()
137 * non-NULL, we go into trace_call_bpf() and do the actual in trace_call_bpf()
146 ret = bpf_prog_run_array(rcu_dereference(call->prog_array), in trace_call_bpf()
209 * strncpy_from_user() does long-sized strides in the fast path. If the in bpf_probe_read_user_str_common()
333 * access_ok() should prevent writing to non-user memory, but in in BPF_CALL_3()
343 current->flags & (PF_KTHREAD | PF_EXITING))) in BPF_CALL_3()
344 return -EPERM; in BPF_CALL_3()
346 return -EPERM; in BPF_CALL_3()
366 current->comm, task_pid_nr(current)); in bpf_get_probe_write_proto()
437 return -EINVAL; in BPF_CALL_4()
479 return -EINVAL; in BPF_CALL_5()
490 return seq_has_overflowed(m) ? -EOVERFLOW : 0; in BPF_CALL_5()
509 return seq_write(m, data, len) ? -EOVERFLOW : 0; in BPF_CALL_3()
533 return btf_type_seq_show_flags(btf, btf_id, ptr->ptr, m, flags); in BPF_CALL_4()
557 return -EINVAL; in get_map_perf_counter()
560 if (unlikely(index >= array->map.max_entries)) in get_map_perf_counter()
561 return -E2BIG; in get_map_perf_counter()
563 ee = READ_ONCE(array->ptrs[index]); in get_map_perf_counter()
565 return -ENOENT; in get_map_perf_counter()
567 return perf_event_read_local(ee->event, value, enabled, running); in get_map_perf_counter()
577 * this api is ugly since we miss [-22..-2] range of valid in BPF_CALL_2()
596 int err = -EINVAL; in BPF_CALL_4()
600 err = get_map_perf_counter(map, flags, &buf->counter, &buf->enabled, in BPF_CALL_4()
601 &buf->running); in BPF_CALL_4()
632 if (unlikely(index >= array->map.max_entries)) in __bpf_perf_event_output()
633 return -E2BIG; in __bpf_perf_event_output()
635 ee = READ_ONCE(array->ptrs[index]); in __bpf_perf_event_output()
637 return -ENOENT; in __bpf_perf_event_output()
639 event = ee->event; in __bpf_perf_event_output()
640 if (unlikely(event->attr.type != PERF_TYPE_SOFTWARE || in __bpf_perf_event_output()
641 event->attr.config != PERF_COUNT_SW_BPF_OUTPUT)) in __bpf_perf_event_output()
642 return -EINVAL; in __bpf_perf_event_output()
644 if (unlikely(event->oncpu != cpu)) in __bpf_perf_event_output()
645 return -EOPNOTSUPP; in __bpf_perf_event_output()
677 if (WARN_ON_ONCE(nest_level > ARRAY_SIZE(sds->sds))) { in BPF_CALL_5()
678 err = -EBUSY; in BPF_CALL_5()
682 sd = &sds->sds[nest_level - 1]; in BPF_CALL_5()
685 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()
814 group_send_sig_info(work->sig, SEND_SIG_PRIV, work->task, work->type); in do_bpf_send_signal()
815 put_task_struct(work->task); in do_bpf_send_signal()
827 if (unlikely(current->flags & (PF_KTHREAD | PF_EXITING))) in bpf_send_signal_common()
828 return -EPERM; in bpf_send_signal_common()
830 return -EPERM; in bpf_send_signal_common()
833 return -EPERM; in bpf_send_signal_common()
840 return -EINVAL; in bpf_send_signal_common()
843 if (irq_work_is_busy(&work->irq_work)) in bpf_send_signal_common()
844 return -EBUSY; in bpf_send_signal_common()
850 work->task = get_task_struct(current); in bpf_send_signal_common()
851 work->sig = sig; in bpf_send_signal_common()
852 work->type = type; in bpf_send_signal_common()
853 irq_work_queue(&work->irq_work); in bpf_send_signal_common()
906 len = buf + sz - p; in BPF_CALL_3()
931 if (prog->type == BPF_PROG_TYPE_TRACING && in BTF_ID()
932 prog->expected_attach_type == BPF_TRACE_ITER) in BTF_ID()
935 if (prog->type == BPF_PROG_TYPE_LSM) in BTF_ID()
936 return bpf_lsm_is_sleepable_hook(prog->aux->attach_btf_id); in BTF_ID()
939 prog->aux->attach_btf_id); in BTF_ID()
965 return -EINVAL; in bpf_btf_printf_prepare()
968 return -EINVAL; in bpf_btf_printf_prepare()
973 return IS_ERR(*btf) ? PTR_ERR(*btf) : -EINVAL; in bpf_btf_printf_prepare()
975 if (ptr->type_id > 0) in bpf_btf_printf_prepare()
976 *btf_id = ptr->type_id; in bpf_btf_printf_prepare()
978 return -EINVAL; in bpf_btf_printf_prepare()
983 return -ENOENT; in bpf_btf_printf_prepare()
999 return btf_type_snprintf_show(btf, btf_id, ptr->ptr, str, str_size, in BPF_CALL_5()
1017 return ((u64 *)ctx)[-2]; in BPF_CALL_1()
1036 if (get_kernel_nofault(instr, (u32 *)(fentry_ip - ENDBR_INSN_SIZE))) in get_entry_ip()
1039 instr = *(u32 *)(fentry_ip - ENDBR_INSN_SIZE); in get_entry_ip()
1042 fentry_ip -= ENDBR_INSN_SIZE; in get_entry_ip()
1055 run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx); in BPF_CALL_1()
1056 if (run_ctx->is_uprobe) in BPF_CALL_1()
1057 return ((struct uprobe_dispatch_data *)current->utask->vaddr)->bp_addr; in BPF_CALL_1()
1062 if (!kp || !(kp->flags & KPROBE_FLAG_ON_FUNC_ENTRY)) in BPF_CALL_1()
1065 return get_entry_ip((uintptr_t)kp->addr); in BPF_CALL_1()
1077 return bpf_kprobe_multi_entry_ip(current->bpf_ctx); in BPF_CALL_1()
1089 return bpf_kprobe_multi_cookie(current->bpf_ctx); in BPF_CALL_1()
1101 return bpf_uprobe_multi_entry_ip(current->bpf_ctx); in BPF_CALL_1()
1113 return bpf_uprobe_multi_cookie(current->bpf_ctx); in BPF_CALL_1()
1127 run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx); in BPF_CALL_1()
1128 return run_ctx->bpf_cookie; in BPF_CALL_1()
1140 return ctx->event->bpf_cookie; in BPF_CALL_1()
1154 run_ctx = container_of(current->bpf_ctx, struct bpf_trace_run_ctx, run_ctx); in BPF_CALL_1()
1155 return run_ctx->bpf_cookie; in BPF_CALL_1()
1173 return -EINVAL; in BPF_CALL_3()
1176 return -ENOENT; in BPF_CALL_3()
1192 u64 nr_args = ((u64 *)ctx)[-1]; in BPF_CALL_3()
1195 return -EINVAL; in BPF_CALL_3()
1212 u64 nr_args = ((u64 *)ctx)[-1]; in BPF_CALL_2()
1229 return ((u64 *)ctx)[-1]; in BPF_CALL_1()
1242 * bpf_lookup_user_key - lookup a key by its serial
1244 * @flags: lookup-specific flags
1255 * one of the available key-specific kfuncs.
1288 bkey->key = key_ref_to_ptr(key_ref); in bpf_lookup_user_key()
1289 bkey->has_ref = true; in bpf_lookup_user_key()
1295 * bpf_lookup_system_key - lookup a key by a system-defined ID
1313 * pre-determined ID on success, a NULL pointer otherwise
1326 bkey->key = (struct key *)(unsigned long)id; in bpf_lookup_system_key()
1327 bkey->has_ref = false; in bpf_lookup_system_key()
1333 * bpf_key_put - decrement key reference count if key is valid and free bpf_key
1341 if (bkey->has_ref) in bpf_key_put()
1342 key_put(bkey->key); in bpf_key_put()
1349 * bpf_verify_pkcs7_signature - verify a PKCS#7 signature
1369 if (trusted_keyring->has_ref) { in bpf_verify_pkcs7_signature()
1378 ret = key_validate(trusted_keyring->key); in bpf_verify_pkcs7_signature()
1389 trusted_keyring->key, in bpf_verify_pkcs7_signature()
1512 return prog->sleepable ? &bpf_get_task_stack_sleepable_proto in bpf_tracing_func_proto()
1551 return prog->expected_attach_type == BPF_TRACE_KPROBE_MULTI || in is_kprobe_multi()
1552 prog->expected_attach_type == BPF_TRACE_KPROBE_SESSION; in is_kprobe_multi()
1557 return prog->expected_attach_type == BPF_TRACE_KPROBE_SESSION; in is_kprobe_session()
1569 return prog->sleepable ? &bpf_get_stack_sleepable_proto : &bpf_get_stack_proto; in kprobe_prog_func_proto()
1577 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI) in kprobe_prog_func_proto()
1583 if (prog->expected_attach_type == BPF_TRACE_UPROBE_MULTI) in kprobe_prog_func_proto()
1729 int err = -EINVAL; in BPF_CALL_3()
1733 err = perf_event_read_local(ctx->event, &buf->counter, &buf->enabled, in BPF_CALL_3()
1734 &buf->running); in BPF_CALL_3()
1756 struct perf_branch_stack *br_stack = ctx->data->br_stack; in BPF_CALL_4()
1760 return -EINVAL; in BPF_CALL_4()
1762 if (unlikely(!(ctx->data->sample_flags & PERF_SAMPLE_BRANCH_STACK))) in BPF_CALL_4()
1763 return -ENOENT; in BPF_CALL_4()
1766 return -ENOENT; in BPF_CALL_4()
1769 return br_stack->nr * br_entry_size; in BPF_CALL_4()
1772 return -EINVAL; in BPF_CALL_4()
1774 to_copy = min_t(u32, br_stack->nr * br_entry_size, size); in BPF_CALL_4()
1775 memcpy(buf, br_stack->entries, to_copy); in BPF_CALL_4()
1829 if (WARN_ON_ONCE(nest_level > ARRAY_SIZE(tp_regs->regs))) { in get_bpf_raw_tp_regs()
1831 return ERR_PTR(-EBUSY); in get_bpf_raw_tp_regs()
1834 return &tp_regs->regs[nest_level - 1]; in get_bpf_raw_tp_regs()
1979 return prog->expected_attach_type == BPF_TRACE_ITER ? in tracing_prog_func_proto()
1983 return prog->expected_attach_type == BPF_TRACE_ITER ? in tracing_prog_func_proto()
1987 return prog->expected_attach_type == BPF_TRACE_ITER ? in tracing_prog_func_proto()
1999 if (prog->type == BPF_PROG_TYPE_TRACING && in tracing_prog_func_proto()
2000 prog->expected_attach_type == BPF_TRACE_RAW_TP) in tracing_prog_func_proto()
2005 if (!fn && prog->expected_attach_type == BPF_TRACE_ITER) in tracing_prog_func_proto()
2031 return -ENOTSUPP; in bpf_prog_test_run_tracing()
2062 info->reg_type = PTR_TO_TP_BUFFER; in raw_tp_writable_prog_is_valid_access()
2120 switch (si->off) { in pe_prog_convert_ctx_access()
2123 data), si->dst_reg, si->src_reg, in pe_prog_convert_ctx_access()
2125 *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, in pe_prog_convert_ctx_access()
2131 data), si->dst_reg, si->src_reg, in pe_prog_convert_ctx_access()
2133 *insn++ = BPF_LDX_MEM(BPF_DW, si->dst_reg, si->dst_reg, in pe_prog_convert_ctx_access()
2139 regs), si->dst_reg, si->src_reg, in pe_prog_convert_ctx_access()
2141 *insn++ = BPF_LDX_MEM(BPF_SIZEOF(long), si->dst_reg, si->dst_reg, in pe_prog_convert_ctx_access()
2142 si->off); in pe_prog_convert_ctx_access()
2146 return insn - insn_buf; in pe_prog_convert_ctx_access()
2168 int ret = -EEXIST; in perf_event_attach_bpf_prog()
2172 * and only if they are on the opt-in list. in perf_event_attach_bpf_prog()
2174 if (prog->kprobe_override && in perf_event_attach_bpf_prog()
2175 (!trace_kprobe_on_func_entry(event->tp_event) || in perf_event_attach_bpf_prog()
2176 !trace_kprobe_error_injectable(event->tp_event))) in perf_event_attach_bpf_prog()
2177 return -EINVAL; in perf_event_attach_bpf_prog()
2181 if (event->prog) in perf_event_attach_bpf_prog()
2184 old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); in perf_event_attach_bpf_prog()
2187 ret = -E2BIG; in perf_event_attach_bpf_prog()
2195 /* set the new array to event->tp_event and set event->prog */ in perf_event_attach_bpf_prog()
2196 event->prog = prog; in perf_event_attach_bpf_prog()
2197 event->bpf_cookie = bpf_cookie; in perf_event_attach_bpf_prog()
2198 rcu_assign_pointer(event->tp_event->prog_array, new_array); in perf_event_attach_bpf_prog()
2214 if (!event->prog) in perf_event_detach_bpf_prog()
2217 old_array = bpf_event_rcu_dereference(event->tp_event->prog_array); in perf_event_detach_bpf_prog()
2218 ret = bpf_prog_array_copy(old_array, event->prog, NULL, 0, &new_array); in perf_event_detach_bpf_prog()
2220 bpf_prog_array_delete_safe(old_array, event->prog); in perf_event_detach_bpf_prog()
2222 rcu_assign_pointer(event->tp_event->prog_array, new_array); in perf_event_detach_bpf_prog()
2226 bpf_prog_put(event->prog); in perf_event_detach_bpf_prog()
2227 event->prog = NULL; in perf_event_detach_bpf_prog()
2242 return -EPERM; in perf_event_query_prog_array()
2243 if (event->attr.type != PERF_TYPE_TRACEPOINT) in perf_event_query_prog_array()
2244 return -EINVAL; in perf_event_query_prog_array()
2246 return -EFAULT; in perf_event_query_prog_array()
2250 return -E2BIG; in perf_event_query_prog_array()
2253 return -ENOMEM; in perf_event_query_prog_array()
2256 * is required when user only wants to check for uquery->prog_cnt. in perf_event_query_prog_array()
2262 progs = bpf_event_rcu_dereference(event->tp_event->prog_array); in perf_event_query_prog_array()
2266 if (copy_to_user(&uquery->prog_cnt, &prog_cnt, sizeof(prog_cnt)) || in perf_event_query_prog_array()
2267 copy_to_user(uquery->ids, ids, ids_len * sizeof(u32))) in perf_event_query_prog_array()
2268 ret = -EFAULT; in perf_event_query_prog_array()
2277 struct bpf_raw_event_map *bpf_get_raw_tracepoint(const char *name) in bpf_get_raw_tracepoint() argument
2282 if (!strcmp(btp->tp->name, name)) in bpf_get_raw_tracepoint()
2286 return bpf_get_raw_tracepoint_module(name); in bpf_get_raw_tracepoint()
2302 struct bpf_prog *prog = link->link.prog; in __bpf_trace_run()
2307 if (unlikely(this_cpu_inc_return(*(prog->active)) != 1)) { in __bpf_trace_run()
2312 run_ctx.bpf_cookie = link->cookie; in __bpf_trace_run()
2321 this_cpu_dec(*(prog->active)); in __bpf_trace_run()
2371 struct tracepoint *tp = btp->tp; in bpf_probe_register()
2372 struct bpf_prog *prog = link->link.prog; in bpf_probe_register()
2378 if (prog->aux->max_ctx_offset > btp->num_args * sizeof(u64)) in bpf_probe_register()
2379 return -EINVAL; in bpf_probe_register()
2381 if (prog->aux->max_tp_access > btp->writable_size) in bpf_probe_register()
2382 return -EINVAL; in bpf_probe_register()
2384 return tracepoint_probe_register_may_exist(tp, (void *)btp->bpf_func, link); in bpf_probe_register()
2389 return tracepoint_probe_unregister(btp->tp, (void *)btp->bpf_func, link); in bpf_probe_unregister()
2401 prog = event->prog; in bpf_get_perf_event_info()
2403 return -ENOENT; in bpf_get_perf_event_info()
2406 if (prog->type == BPF_PROG_TYPE_PERF_EVENT) in bpf_get_perf_event_info()
2407 return -EOPNOTSUPP; in bpf_get_perf_event_info()
2409 *prog_id = prog->aux->id; in bpf_get_perf_event_info()
2410 flags = event->tp_event->flags; in bpf_get_perf_event_info()
2412 is_syscall_tp = is_syscall_trace_event(event->tp_event); in bpf_get_perf_event_info()
2415 *buf = is_tracepoint ? event->tp_event->tp->name in bpf_get_perf_event_info()
2416 : event->tp_event->name; in bpf_get_perf_event_info()
2426 err = -EOPNOTSUPP; in bpf_get_perf_event_info()
2431 event->attr.type == PERF_TYPE_TRACEPOINT); in bpf_get_perf_event_info()
2437 event->attr.type == PERF_TYPE_TRACEPOINT); in bpf_get_perf_event_info()
2451 init_irq_work(&work->irq_work, do_bpf_send_signal); in send_signal_irq_work_init()
2466 if (mod->num_bpf_raw_events == 0 || in bpf_event_notify()
2476 btm->module = module; in bpf_event_notify()
2477 list_add(&btm->list, &bpf_trace_modules); in bpf_event_notify()
2479 ret = -ENOMEM; in bpf_event_notify()
2484 if (btm->module == module) { in bpf_event_notify()
2485 list_del(&btm->list); in bpf_event_notify()
2524 u32 cnt; member
2541 static int copy_user_syms(struct user_syms *us, unsigned long __user *usyms, u32 cnt) in copy_user_syms() argument
2546 int err = -ENOMEM; in copy_user_syms()
2549 syms = kvmalloc_array(cnt, sizeof(*syms), GFP_KERNEL); in copy_user_syms()
2553 buf = kvmalloc_array(cnt, KSYM_NAME_LEN, GFP_KERNEL); in copy_user_syms()
2557 for (p = buf, i = 0; i < cnt; i++) { in copy_user_syms()
2559 err = -EFAULT; in copy_user_syms()
2564 err = -E2BIG; in copy_user_syms()
2571 us->syms = syms; in copy_user_syms()
2572 us->buf = buf; in copy_user_syms()
2583 static void kprobe_multi_put_modules(struct module **mods, u32 cnt) in kprobe_multi_put_modules() argument
2587 for (i = 0; i < cnt; i++) in kprobe_multi_put_modules()
2593 kvfree(us->syms); in free_user_syms()
2594 kvfree(us->buf); in free_user_syms()
2602 unregister_fprobe(&kmulti_link->fp); in bpf_kprobe_multi_link_release()
2603 kprobe_multi_put_modules(kmulti_link->mods, kmulti_link->mods_cnt); in bpf_kprobe_multi_link_release()
2611 kvfree(kmulti_link->addrs); in bpf_kprobe_multi_link_dealloc()
2612 kvfree(kmulti_link->cookies); in bpf_kprobe_multi_link_dealloc()
2613 kfree(kmulti_link->mods); in bpf_kprobe_multi_link_dealloc()
2620 u64 __user *ucookies = u64_to_user_ptr(info->kprobe_multi.cookies); in bpf_kprobe_multi_link_fill_link_info()
2621 u64 __user *uaddrs = u64_to_user_ptr(info->kprobe_multi.addrs); in bpf_kprobe_multi_link_fill_link_info()
2623 u32 ucount = info->kprobe_multi.count; in bpf_kprobe_multi_link_fill_link_info()
2627 return -EINVAL; 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()
2634 info->kprobe_multi.missed = kmulti_link->fp.nmissed; in bpf_kprobe_multi_link_fill_link_info()
2638 if (ucount < kmulti_link->cnt) in bpf_kprobe_multi_link_fill_link_info()
2639 err = -ENOSPC; in bpf_kprobe_multi_link_fill_link_info()
2641 ucount = kmulti_link->cnt; in bpf_kprobe_multi_link_fill_link_info()
2644 if (kmulti_link->cookies) { in bpf_kprobe_multi_link_fill_link_info()
2645 if (copy_to_user(ucookies, kmulti_link->cookies, ucount * sizeof(u64))) in bpf_kprobe_multi_link_fill_link_info()
2646 return -EFAULT; in bpf_kprobe_multi_link_fill_link_info()
2650 return -EFAULT; in bpf_kprobe_multi_link_fill_link_info()
2656 if (copy_to_user(uaddrs, kmulti_link->addrs, ucount * sizeof(u64))) in bpf_kprobe_multi_link_fill_link_info()
2657 return -EFAULT; in bpf_kprobe_multi_link_fill_link_info()
2661 return -EFAULT; in bpf_kprobe_multi_link_fill_link_info()
2679 cookie_a = link->cookies + (addr_a - link->addrs); in bpf_kprobe_multi_cookie_swap()
2680 cookie_b = link->cookies + (addr_b - link->addrs); in bpf_kprobe_multi_cookie_swap()
2693 return *addr_a < *addr_b ? -1 : 1; in bpf_kprobe_multi_addrs_cmp()
2710 run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx, in bpf_kprobe_multi_cookie()
2712 link = run_ctx->link; in bpf_kprobe_multi_cookie()
2713 if (!link->cookies) in bpf_kprobe_multi_cookie()
2715 entry_ip = run_ctx->entry_ip; in bpf_kprobe_multi_cookie()
2716 addr = bsearch(&entry_ip, link->addrs, link->cnt, sizeof(entry_ip), in bpf_kprobe_multi_cookie()
2720 cookie = link->cookies + (addr - link->addrs); in bpf_kprobe_multi_cookie()
2728 run_ctx = container_of(current->bpf_ctx, struct bpf_kprobe_multi_run_ctx, in bpf_kprobe_multi_entry_ip()
2730 return run_ctx->entry_ip; in bpf_kprobe_multi_entry_ip()
2750 bpf_prog_inc_misses_counter(link->link.prog); in kprobe_multi_link_prog_run()
2758 err = bpf_prog_run(link->link.prog, regs); in kprobe_multi_link_prog_run()
2778 return is_kprobe_session(link->link.prog) ? err : 0; in kprobe_multi_link_handler()
2813 if (data->cookies) { in symbols_swap_r()
2816 cookie_a = data->cookies + (name_a - data->funcs); in symbols_swap_r()
2817 cookie_b = data->cookies + (name_b - data->funcs); in symbols_swap_r()
2832 if (arr->mods_cnt == arr->mods_cap) { in add_module()
2833 arr->mods_cap = max(16, arr->mods_cap * 3 / 2); in add_module()
2834 mods = krealloc_array(arr->mods, arr->mods_cap, sizeof(*mods), GFP_KERNEL); in add_module()
2836 return -ENOMEM; in add_module()
2837 arr->mods = mods; in add_module()
2840 arr->mods[arr->mods_cnt] = mod; in add_module()
2841 arr->mods_cnt++; in add_module()
2849 for (i = arr->mods_cnt - 1; i >= 0; i--) { in has_module()
2850 if (arr->mods[i] == mod) in has_module()
2872 err = -EINVAL; in get_modules_for_addrs()
2895 static int addrs_check_error_injection_list(unsigned long *addrs, u32 cnt) in addrs_check_error_injection_list() argument
2899 for (i = 0; i < cnt; i++) { in addrs_check_error_injection_list()
2901 return -EINVAL; in addrs_check_error_injection_list()
2906 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_kprobe_multi_link_attach() argument
2912 u32 flags, cnt, size; in bpf_kprobe_multi_link_attach() local
2920 return -EOPNOTSUPP; in bpf_kprobe_multi_link_attach()
2923 return -EINVAL; in bpf_kprobe_multi_link_attach()
2925 flags = attr->link_create.kprobe_multi.flags; in bpf_kprobe_multi_link_attach()
2927 return -EINVAL; in bpf_kprobe_multi_link_attach()
2929 uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); in bpf_kprobe_multi_link_attach()
2930 usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms); in bpf_kprobe_multi_link_attach()
2932 return -EINVAL; in bpf_kprobe_multi_link_attach()
2934 cnt = attr->link_create.kprobe_multi.cnt; in bpf_kprobe_multi_link_attach()
2935 if (!cnt) in bpf_kprobe_multi_link_attach()
2936 return -EINVAL; in bpf_kprobe_multi_link_attach()
2937 if (cnt > MAX_KPROBE_MULTI_CNT) in bpf_kprobe_multi_link_attach()
2938 return -E2BIG; in bpf_kprobe_multi_link_attach()
2940 size = cnt * sizeof(*addrs); in bpf_kprobe_multi_link_attach()
2941 addrs = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); in bpf_kprobe_multi_link_attach()
2943 return -ENOMEM; in bpf_kprobe_multi_link_attach()
2945 ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); in bpf_kprobe_multi_link_attach()
2947 cookies = kvmalloc_array(cnt, sizeof(*addrs), GFP_KERNEL); in bpf_kprobe_multi_link_attach()
2949 err = -ENOMEM; in bpf_kprobe_multi_link_attach()
2953 err = -EFAULT; in bpf_kprobe_multi_link_attach()
2960 err = -EFAULT; in bpf_kprobe_multi_link_attach()
2969 err = copy_user_syms(&us, usyms, cnt); in bpf_kprobe_multi_link_attach()
2976 sort_r(us.syms, cnt, sizeof(*us.syms), symbols_cmp_r, in bpf_kprobe_multi_link_attach()
2979 err = ftrace_lookup_symbols(us.syms, cnt, addrs); in bpf_kprobe_multi_link_attach()
2985 if (prog->kprobe_override && addrs_check_error_injection_list(addrs, cnt)) { in bpf_kprobe_multi_link_attach()
2986 err = -EINVAL; in bpf_kprobe_multi_link_attach()
2992 err = -ENOMEM; in bpf_kprobe_multi_link_attach()
2996 bpf_link_init(&link->link, BPF_LINK_TYPE_KPROBE_MULTI, in bpf_kprobe_multi_link_attach()
2999 err = bpf_link_prime(&link->link, &link_primer); in bpf_kprobe_multi_link_attach()
3004 link->fp.entry_handler = kprobe_multi_link_handler; in bpf_kprobe_multi_link_attach()
3006 link->fp.exit_handler = kprobe_multi_link_exit_handler; in bpf_kprobe_multi_link_attach()
3008 link->fp.entry_data_size = sizeof(u64); in bpf_kprobe_multi_link_attach()
3010 link->addrs = addrs; in bpf_kprobe_multi_link_attach()
3011 link->cookies = cookies; in bpf_kprobe_multi_link_attach()
3012 link->cnt = cnt; in bpf_kprobe_multi_link_attach()
3013 link->flags = flags; in bpf_kprobe_multi_link_attach()
3022 sort_r(addrs, cnt, sizeof(*addrs), in bpf_kprobe_multi_link_attach()
3028 err = get_modules_for_addrs(&link->mods, addrs, cnt); in bpf_kprobe_multi_link_attach()
3033 link->mods_cnt = err; in bpf_kprobe_multi_link_attach()
3035 err = register_fprobe_ips(&link->fp, addrs, cnt); in bpf_kprobe_multi_link_attach()
3037 kprobe_multi_put_modules(link->mods, link->mods_cnt); in bpf_kprobe_multi_link_attach()
3051 int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_kprobe_multi_link_attach() argument
3053 return -EOPNOTSUPP; in bpf_kprobe_multi_link_attach()
3080 u32 cnt; member
3092 static void bpf_uprobe_unregister(struct bpf_uprobe *uprobes, u32 cnt) in bpf_uprobe_unregister() argument
3096 for (i = 0; i < cnt; i++) in bpf_uprobe_unregister()
3099 if (cnt) in bpf_uprobe_unregister()
3108 bpf_uprobe_unregister(umulti_link->uprobes, umulti_link->cnt); in bpf_uprobe_multi_link_release()
3109 if (umulti_link->task) in bpf_uprobe_multi_link_release()
3110 put_task_struct(umulti_link->task); in bpf_uprobe_multi_link_release()
3111 path_put(&umulti_link->path); in bpf_uprobe_multi_link_release()
3119 kvfree(umulti_link->uprobes); in bpf_uprobe_multi_link_dealloc()
3126 u64 __user *uref_ctr_offsets = u64_to_user_ptr(info->uprobe_multi.ref_ctr_offsets); in bpf_uprobe_multi_link_fill_link_info()
3127 u64 __user *ucookies = u64_to_user_ptr(info->uprobe_multi.cookies); in bpf_uprobe_multi_link_fill_link_info()
3128 u64 __user *uoffsets = u64_to_user_ptr(info->uprobe_multi.offsets); in bpf_uprobe_multi_link_fill_link_info()
3129 u64 __user *upath = u64_to_user_ptr(info->uprobe_multi.path); in bpf_uprobe_multi_link_fill_link_info()
3130 u32 upath_size = info->uprobe_multi.path_size; in bpf_uprobe_multi_link_fill_link_info()
3132 u32 ucount = info->uprobe_multi.count; in bpf_uprobe_multi_link_fill_link_info()
3138 return -EINVAL; in bpf_uprobe_multi_link_fill_link_info()
3141 return -EINVAL; in bpf_uprobe_multi_link_fill_link_info()
3144 info->uprobe_multi.count = umulti_link->cnt; in bpf_uprobe_multi_link_fill_link_info()
3145 info->uprobe_multi.flags = umulti_link->flags; in bpf_uprobe_multi_link_fill_link_info()
3146 info->uprobe_multi.pid = umulti_link->task ? in bpf_uprobe_multi_link_fill_link_info()
3147 task_pid_nr_ns(umulti_link->task, task_active_pid_ns(current)) : 0; in bpf_uprobe_multi_link_fill_link_info()
3152 return -ENOMEM; in bpf_uprobe_multi_link_fill_link_info()
3153 p = d_path(&umulti_link->path, buf, upath_size); in bpf_uprobe_multi_link_fill_link_info()
3158 upath_size = buf + upath_size - p; in bpf_uprobe_multi_link_fill_link_info()
3164 return -EFAULT; in bpf_uprobe_multi_link_fill_link_info()
3165 info->uprobe_multi.path_size = upath_size; in bpf_uprobe_multi_link_fill_link_info()
3170 if (ucount < umulti_link->cnt) in bpf_uprobe_multi_link_fill_link_info()
3171 err = -ENOSPC; in bpf_uprobe_multi_link_fill_link_info()
3173 ucount = umulti_link->cnt; in bpf_uprobe_multi_link_fill_link_info()
3177 put_user(umulti_link->uprobes[i].offset, uoffsets + i)) in bpf_uprobe_multi_link_fill_link_info()
3178 return -EFAULT; in bpf_uprobe_multi_link_fill_link_info()
3180 put_user(umulti_link->uprobes[i].ref_ctr_offset, uref_ctr_offsets + i)) in bpf_uprobe_multi_link_fill_link_info()
3181 return -EFAULT; in bpf_uprobe_multi_link_fill_link_info()
3183 put_user(umulti_link->uprobes[i].cookie, ucookies + i)) in bpf_uprobe_multi_link_fill_link_info()
3184 return -EFAULT; in bpf_uprobe_multi_link_fill_link_info()
3200 struct bpf_uprobe_multi_link *link = uprobe->link; in uprobe_prog_run()
3205 struct bpf_prog *prog = link->link.prog; in uprobe_prog_run()
3206 bool sleepable = prog->sleepable; in uprobe_prog_run()
3210 if (link->task && !same_thread_group(current, link->task)) in uprobe_prog_run()
3221 err = bpf_prog_run(link->link.prog, regs); in uprobe_prog_run()
3239 return uprobe->link->task->mm == mm; in uprobe_multi_link_filter()
3264 run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx); in bpf_uprobe_multi_entry_ip()
3265 return run_ctx->entry_ip; in bpf_uprobe_multi_entry_ip()
3272 run_ctx = container_of(current->bpf_ctx, struct bpf_uprobe_multi_run_ctx, run_ctx); in bpf_uprobe_multi_cookie()
3273 return run_ctx->uprobe->cookie; in bpf_uprobe_multi_cookie()
3276 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_uprobe_multi_link_attach() argument
3286 u32 flags, cnt, i; in bpf_uprobe_multi_link_attach() local
3288 char *name; in bpf_uprobe_multi_link_attach() local
3294 return -EOPNOTSUPP; in bpf_uprobe_multi_link_attach()
3296 if (prog->expected_attach_type != BPF_TRACE_UPROBE_MULTI) in bpf_uprobe_multi_link_attach()
3297 return -EINVAL; in bpf_uprobe_multi_link_attach()
3299 flags = attr->link_create.uprobe_multi.flags; in bpf_uprobe_multi_link_attach()
3301 return -EINVAL; in bpf_uprobe_multi_link_attach()
3304 * path, offsets and cnt are mandatory, in bpf_uprobe_multi_link_attach()
3307 upath = u64_to_user_ptr(attr->link_create.uprobe_multi.path); in bpf_uprobe_multi_link_attach()
3308 uoffsets = u64_to_user_ptr(attr->link_create.uprobe_multi.offsets); in bpf_uprobe_multi_link_attach()
3309 cnt = attr->link_create.uprobe_multi.cnt; in bpf_uprobe_multi_link_attach()
3310 pid = attr->link_create.uprobe_multi.pid; in bpf_uprobe_multi_link_attach()
3312 if (!upath || !uoffsets || !cnt || pid < 0) in bpf_uprobe_multi_link_attach()
3313 return -EINVAL; in bpf_uprobe_multi_link_attach()
3314 if (cnt > MAX_UPROBE_MULTI_CNT) in bpf_uprobe_multi_link_attach()
3315 return -E2BIG; in bpf_uprobe_multi_link_attach()
3317 uref_ctr_offsets = u64_to_user_ptr(attr->link_create.uprobe_multi.ref_ctr_offsets); in bpf_uprobe_multi_link_attach()
3318 ucookies = u64_to_user_ptr(attr->link_create.uprobe_multi.cookies); in bpf_uprobe_multi_link_attach()
3320 name = strndup_user(upath, PATH_MAX); in bpf_uprobe_multi_link_attach()
3321 if (IS_ERR(name)) { in bpf_uprobe_multi_link_attach()
3322 err = PTR_ERR(name); in bpf_uprobe_multi_link_attach()
3326 err = kern_path(name, LOOKUP_FOLLOW, &path); in bpf_uprobe_multi_link_attach()
3327 kfree(name); in bpf_uprobe_multi_link_attach()
3332 err = -EBADF; in bpf_uprobe_multi_link_attach()
3339 err = -ESRCH; in bpf_uprobe_multi_link_attach()
3344 err = -ENOMEM; in bpf_uprobe_multi_link_attach()
3347 uprobes = kvcalloc(cnt, sizeof(*uprobes), GFP_KERNEL); in bpf_uprobe_multi_link_attach()
3352 for (i = 0; i < cnt; i++) { in bpf_uprobe_multi_link_attach()
3354 err = -EFAULT; in bpf_uprobe_multi_link_attach()
3358 err = -EINVAL; in bpf_uprobe_multi_link_attach()
3362 err = -EFAULT; in bpf_uprobe_multi_link_attach()
3366 err = -EFAULT; in bpf_uprobe_multi_link_attach()
3381 link->cnt = cnt; in bpf_uprobe_multi_link_attach()
3382 link->uprobes = uprobes; in bpf_uprobe_multi_link_attach()
3383 link->path = path; in bpf_uprobe_multi_link_attach()
3384 link->task = task; in bpf_uprobe_multi_link_attach()
3385 link->flags = flags; in bpf_uprobe_multi_link_attach()
3387 bpf_link_init(&link->link, BPF_LINK_TYPE_UPROBE_MULTI, in bpf_uprobe_multi_link_attach()
3390 for (i = 0; i < cnt; i++) { in bpf_uprobe_multi_link_attach()
3391 uprobes[i].uprobe = uprobe_register(d_real_inode(link->path.dentry), in bpf_uprobe_multi_link_attach()
3397 link->cnt = i; in bpf_uprobe_multi_link_attach()
3402 err = bpf_link_prime(&link->link, &link_primer); in bpf_uprobe_multi_link_attach()
3409 bpf_uprobe_unregister(uprobes, link->cnt); in bpf_uprobe_multi_link_attach()
3421 int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *prog) in bpf_uprobe_multi_link_attach() argument
3423 return -EOPNOTSUPP; in bpf_uprobe_multi_link_attach()
3441 session_ctx = container_of(current->bpf_ctx, struct bpf_session_run_ctx, run_ctx); in bpf_session_is_return()
3442 return session_ctx->is_return; in bpf_session_is_return()
3449 session_ctx = container_of(current->bpf_ctx, struct bpf_session_run_ctx, run_ctx); in bpf_session_cookie()
3450 return session_ctx->data; in bpf_session_cookie()
3466 return -EACCES; in BTF_ID_FLAGS()