bpf_trace.c (9fb16955fb661945ddffce4504dcffbe55cd518a) bpf_trace.c (fc611f47f2188ade2b48ff6902d5cce8baac0c58)
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com
3 * Copyright (c) 2016 Facebook
4 */
5#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/slab.h>
8#include <linux/bpf.h>

--- 716 unchanged lines hidden (view full) ---

725 */
726 if (unlikely(current->flags & (PF_KTHREAD | PF_EXITING)))
727 return -EPERM;
728 if (unlikely(uaccess_kernel()))
729 return -EPERM;
730 if (unlikely(!nmi_uaccess_okay()))
731 return -EPERM;
732
1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2011-2015 PLUMgrid, http://plumgrid.com
3 * Copyright (c) 2016 Facebook
4 */
5#include <linux/kernel.h>
6#include <linux/types.h>
7#include <linux/slab.h>
8#include <linux/bpf.h>

--- 716 unchanged lines hidden (view full) ---

725 */
726 if (unlikely(current->flags & (PF_KTHREAD | PF_EXITING)))
727 return -EPERM;
728 if (unlikely(uaccess_kernel()))
729 return -EPERM;
730 if (unlikely(!nmi_uaccess_okay()))
731 return -EPERM;
732
733 if (irqs_disabled()) {
733 if (in_nmi()) {
734 /* Do an early check on signal validity. Otherwise,
735 * the error is lost in deferred irq_work.
736 */
737 if (unlikely(!valid_signal(sig)))
738 return -EINVAL;
739
740 work = this_cpu_ptr(&send_signal_work);
741 if (atomic_read(&work->irq_work.flags) & IRQ_WORK_BUSY)

--- 32 unchanged lines hidden (view full) ---

774
775static const struct bpf_func_proto bpf_send_signal_thread_proto = {
776 .func = bpf_send_signal_thread,
777 .gpl_only = false,
778 .ret_type = RET_INTEGER,
779 .arg1_type = ARG_ANYTHING,
780};
781
734 /* Do an early check on signal validity. Otherwise,
735 * the error is lost in deferred irq_work.
736 */
737 if (unlikely(!valid_signal(sig)))
738 return -EINVAL;
739
740 work = this_cpu_ptr(&send_signal_work);
741 if (atomic_read(&work->irq_work.flags) & IRQ_WORK_BUSY)

--- 32 unchanged lines hidden (view full) ---

774
775static const struct bpf_func_proto bpf_send_signal_thread_proto = {
776 .func = bpf_send_signal_thread,
777 .gpl_only = false,
778 .ret_type = RET_INTEGER,
779 .arg1_type = ARG_ANYTHING,
780};
781
782static const struct bpf_func_proto *
783tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
782const struct bpf_func_proto *
783bpf_tracing_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
784{
785 switch (func_id) {
786 case BPF_FUNC_map_lookup_elem:
787 return &bpf_map_lookup_elem_proto;
788 case BPF_FUNC_map_update_elem:
789 return &bpf_map_update_elem_proto;
790 case BPF_FUNC_map_delete_elem:
791 return &bpf_map_delete_elem_proto;

--- 68 unchanged lines hidden (view full) ---

860 return &bpf_get_stackid_proto;
861 case BPF_FUNC_get_stack:
862 return &bpf_get_stack_proto;
863#ifdef CONFIG_BPF_KPROBE_OVERRIDE
864 case BPF_FUNC_override_return:
865 return &bpf_override_return_proto;
866#endif
867 default:
784{
785 switch (func_id) {
786 case BPF_FUNC_map_lookup_elem:
787 return &bpf_map_lookup_elem_proto;
788 case BPF_FUNC_map_update_elem:
789 return &bpf_map_update_elem_proto;
790 case BPF_FUNC_map_delete_elem:
791 return &bpf_map_delete_elem_proto;

--- 68 unchanged lines hidden (view full) ---

860 return &bpf_get_stackid_proto;
861 case BPF_FUNC_get_stack:
862 return &bpf_get_stack_proto;
863#ifdef CONFIG_BPF_KPROBE_OVERRIDE
864 case BPF_FUNC_override_return:
865 return &bpf_override_return_proto;
866#endif
867 default:
868 return tracing_func_proto(func_id, prog);
868 return bpf_tracing_func_proto(func_id, prog);
869 }
870}
871
872/* bpf+kprobe programs can access fields of 'struct pt_regs' */
873static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
874 const struct bpf_prog *prog,
875 struct bpf_insn_access_aux *info)
876{

--- 93 unchanged lines hidden (view full) ---

970 switch (func_id) {
971 case BPF_FUNC_perf_event_output:
972 return &bpf_perf_event_output_proto_tp;
973 case BPF_FUNC_get_stackid:
974 return &bpf_get_stackid_proto_tp;
975 case BPF_FUNC_get_stack:
976 return &bpf_get_stack_proto_tp;
977 default:
869 }
870}
871
872/* bpf+kprobe programs can access fields of 'struct pt_regs' */
873static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
874 const struct bpf_prog *prog,
875 struct bpf_insn_access_aux *info)
876{

--- 93 unchanged lines hidden (view full) ---

970 switch (func_id) {
971 case BPF_FUNC_perf_event_output:
972 return &bpf_perf_event_output_proto_tp;
973 case BPF_FUNC_get_stackid:
974 return &bpf_get_stackid_proto_tp;
975 case BPF_FUNC_get_stack:
976 return &bpf_get_stack_proto_tp;
977 default:
978 return tracing_func_proto(func_id, prog);
978 return bpf_tracing_func_proto(func_id, prog);
979 }
980}
981
982static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
983 const struct bpf_prog *prog,
984 struct bpf_insn_access_aux *info)
985{
986 if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)

--- 90 unchanged lines hidden (view full) ---

1077 return &bpf_get_stackid_proto_tp;
1078 case BPF_FUNC_get_stack:
1079 return &bpf_get_stack_proto_tp;
1080 case BPF_FUNC_perf_prog_read_value:
1081 return &bpf_perf_prog_read_value_proto;
1082 case BPF_FUNC_read_branch_records:
1083 return &bpf_read_branch_records_proto;
1084 default:
979 }
980}
981
982static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
983 const struct bpf_prog *prog,
984 struct bpf_insn_access_aux *info)
985{
986 if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)

--- 90 unchanged lines hidden (view full) ---

1077 return &bpf_get_stackid_proto_tp;
1078 case BPF_FUNC_get_stack:
1079 return &bpf_get_stack_proto_tp;
1080 case BPF_FUNC_perf_prog_read_value:
1081 return &bpf_perf_prog_read_value_proto;
1082 case BPF_FUNC_read_branch_records:
1083 return &bpf_read_branch_records_proto;
1084 default:
1085 return tracing_func_proto(func_id, prog);
1085 return bpf_tracing_func_proto(func_id, prog);
1086 }
1087}
1088
1089/*
1090 * bpf_raw_tp_regs are separate from bpf_pt_regs used from skb/xdp
1091 * to avoid potential recursive reuse issue when/if tracepoints are added
1092 * inside bpf_*_event_output, bpf_get_stackid and/or bpf_get_stack.
1093 *

--- 111 unchanged lines hidden (view full) ---

1205 switch (func_id) {
1206 case BPF_FUNC_perf_event_output:
1207 return &bpf_perf_event_output_proto_raw_tp;
1208 case BPF_FUNC_get_stackid:
1209 return &bpf_get_stackid_proto_raw_tp;
1210 case BPF_FUNC_get_stack:
1211 return &bpf_get_stack_proto_raw_tp;
1212 default:
1086 }
1087}
1088
1089/*
1090 * bpf_raw_tp_regs are separate from bpf_pt_regs used from skb/xdp
1091 * to avoid potential recursive reuse issue when/if tracepoints are added
1092 * inside bpf_*_event_output, bpf_get_stackid and/or bpf_get_stack.
1093 *

--- 111 unchanged lines hidden (view full) ---

1205 switch (func_id) {
1206 case BPF_FUNC_perf_event_output:
1207 return &bpf_perf_event_output_proto_raw_tp;
1208 case BPF_FUNC_get_stackid:
1209 return &bpf_get_stackid_proto_raw_tp;
1210 case BPF_FUNC_get_stack:
1211 return &bpf_get_stack_proto_raw_tp;
1212 default:
1213 return tracing_func_proto(func_id, prog);
1213 return bpf_tracing_func_proto(func_id, prog);
1214 }
1215}
1216
1217static const struct bpf_func_proto *
1218tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
1219{
1220 switch (func_id) {
1221#ifdef CONFIG_NET

--- 496 unchanged lines hidden ---
1214 }
1215}
1216
1217static const struct bpf_func_proto *
1218tracing_prog_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
1219{
1220 switch (func_id) {
1221#ifdef CONFIG_NET

--- 496 unchanged lines hidden ---