]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
bpf: Revert bpf_overrid_function() helper changes.
authorDavid S. Miller <davem@davemloft.net>
Sat, 11 Nov 2017 09:24:55 +0000 (18:24 +0900)
committerDavid S. Miller <davem@davemloft.net>
Sat, 11 Nov 2017 09:24:55 +0000 (18:24 +0900)
NACK'd by x86 maintainer.

Signed-off-by: David S. Miller <davem@davemloft.net>
21 files changed:
arch/Kconfig
arch/x86/Kconfig
arch/x86/include/asm/kprobes.h
arch/x86/include/asm/ptrace.h
arch/x86/kernel/kprobes/ftrace.c
include/linux/filter.h
include/linux/trace_events.h
include/uapi/linux/bpf.h
kernel/bpf/core.c
kernel/bpf/verifier.c
kernel/events/core.c
kernel/trace/Kconfig
kernel/trace/bpf_trace.c
kernel/trace/trace_kprobe.c
kernel/trace/trace_probe.h
samples/bpf/Makefile
samples/bpf/test_override_return.sh [deleted file]
samples/bpf/tracex7_kern.c [deleted file]
samples/bpf/tracex7_user.c [deleted file]
tools/include/uapi/linux/bpf.h
tools/testing/selftests/bpf/bpf_helpers.h

index 6e8520f09bc18af96bb715ff6c0c476602eb8d87..057370a0ac4ec7cf133f6f4c2ee9106a1d576958 100644 (file)
@@ -196,9 +196,6 @@ config HAVE_OPTPROBES
 config HAVE_KPROBES_ON_FTRACE
        bool
 
-config HAVE_KPROBE_OVERRIDE
-       bool
-
 config HAVE_NMI
        bool
 
index 51458c1a0b4a95b474dcce78f1bc247f241983f6..2fdb23313dd55fa2d08fee3e15c47bde6ef632ac 100644 (file)
@@ -153,7 +153,6 @@ config X86
        select HAVE_KERNEL_XZ
        select HAVE_KPROBES
        select HAVE_KPROBES_ON_FTRACE
-       select HAVE_KPROBE_OVERRIDE
        select HAVE_KRETPROBES
        select HAVE_KVM
        select HAVE_LIVEPATCH                   if X86_64
index c6c3b1f4306abf69be70410e3712e46e9d4b962d..6cf65437b5e502194c9f4a354f755ee7b2a39102 100644 (file)
@@ -67,10 +67,6 @@ extern const int kretprobe_blacklist_size;
 void arch_remove_kprobe(struct kprobe *p);
 asmlinkage void kretprobe_trampoline(void);
 
-#ifdef CONFIG_KPROBES_ON_FTRACE
-extern void arch_ftrace_kprobe_override_function(struct pt_regs *regs);
-#endif
-
 /* Architecture specific copy of original instruction*/
 struct arch_specific_insn {
        /* copy of the original instruction */
index 2370bb0149ccbeef00efc386147f16f2d06c3647..c0e3c45cf6aba2a0f06c0e07a4642b9519364f03 100644 (file)
@@ -109,11 +109,6 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
        return regs->ax;
 }
 
-static inline void regs_set_return_value(struct pt_regs *regs, unsigned long rc)
-{
-       regs->ax = rc;
-}
-
 /*
  * user_mode(regs) determines whether a register set came from user
  * mode.  On x86_32, this is true if V8086 mode was enabled OR if the
index 3c455bf490cbfa7361b63fbd24cd69ba852dfe35..041f7b6dfa0fe00f9c6e6611451889d41dc006b9 100644 (file)
@@ -97,17 +97,3 @@ int arch_prepare_kprobe_ftrace(struct kprobe *p)
        p->ainsn.boostable = false;
        return 0;
 }
-
-asmlinkage void override_func(void);
-asm(
-       ".type override_func, @function\n"
-       "override_func:\n"
-       "       ret\n"
-       ".size override_func, .-override_func\n"
-);
-
-void arch_ftrace_kprobe_override_function(struct pt_regs *regs)
-{
-       regs->ip = (unsigned long)&override_func;
-}
-NOKPROBE_SYMBOL(arch_ftrace_kprobe_override_function);
index eaec066f99e8eb057eb912596de9bf1bc99d6531..0cd02ff4ae3083236ac6457ea154082126735e88 100644 (file)
@@ -459,8 +459,7 @@ struct bpf_prog {
                                locked:1,       /* Program image locked? */
                                gpl_compatible:1, /* Is filter GPL compatible? */
                                cb_access:1,    /* Is control block accessed? */
-                               dst_needed:1,   /* Do we need dst entry? */
-                               kprobe_override:1; /* Do we override a kprobe? */
+                               dst_needed:1;   /* Do we need dst entry? */
        kmemcheck_bitfield_end(meta);
        enum bpf_prog_type      type;           /* Type of BPF program */
        u32                     len;            /* Number of filter blocks */
index 17e5e820a84c7836044906052fccf6297997e8c6..84014ecfa67ff284fc6b657e565e57ea12d9c89e 100644 (file)
@@ -523,7 +523,6 @@ do {                                                                        \
 struct perf_event;
 
 DECLARE_PER_CPU(struct pt_regs, perf_trace_regs);
-DECLARE_PER_CPU(int, bpf_kprobe_override);
 
 extern int  perf_trace_init(struct perf_event *event);
 extern void perf_trace_destroy(struct perf_event *event);
index adb66f78b674205d4ba9c2d80d44721cca1d6ef6..e880ae6434eed9eb29db99169c716c94c7cf30aa 100644 (file)
@@ -677,10 +677,6 @@ union bpf_attr {
  *     @buf: buf to fill
  *     @buf_size: size of the buf
  *     Return : 0 on success or negative error code
- *
- * int bpf_override_return(pt_regs, rc)
- *     @pt_regs: pointer to struct pt_regs
- *     @rc: the return value to set
  */
 #define __BPF_FUNC_MAPPER(FN)          \
        FN(unspec),                     \
@@ -740,8 +736,7 @@ union bpf_attr {
        FN(xdp_adjust_meta),            \
        FN(perf_event_read_value),      \
        FN(perf_prog_read_value),       \
-       FN(getsockopt),                 \
-       FN(override_return),
+       FN(getsockopt),
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  * function eBPF program intends to call
index 271daad31f376b3ef5d12cd651ec94e9ffa746d7..8a6c37762330f5d8f49214061e733f93e3c6a217 100644 (file)
@@ -1326,9 +1326,6 @@ EVAL4(PROG_NAME_LIST, 416, 448, 480, 512)
 bool bpf_prog_array_compatible(struct bpf_array *array,
                               const struct bpf_prog *fp)
 {
-       if (fp->kprobe_override)
-               return false;
-
        if (!array->owner_prog_type) {
                /* There's no owner yet where we could check for
                 * compatibility.
index bc464b8ec91e49af156d9205449fa00ee0728bfc..4a942e2e753d71904d00b317011b5f6c4c14ca24 100644 (file)
@@ -4357,8 +4357,6 @@ static int fixup_bpf_calls(struct bpf_verifier_env *env)
                        prog->dst_needed = 1;
                if (insn->imm == BPF_FUNC_get_prandom_u32)
                        bpf_user_rnd_init_once();
-               if (insn->imm == BPF_FUNC_override_return)
-                       prog->kprobe_override = 1;
                if (insn->imm == BPF_FUNC_tail_call) {
                        /* If we tail call into other programs, we
                         * cannot make any assumptions since they can
index ac240d31b5bf1c77ef36dfbfc8f6d8da99557582..42d24bd64ea4676ba740495f58504918c6db315d 100644 (file)
@@ -8171,13 +8171,6 @@ static int perf_event_set_bpf_prog(struct perf_event *event, u32 prog_fd)
                return -EINVAL;
        }
 
-       /* Kprobe override only works for kprobes, not uprobes. */
-       if (prog->kprobe_override &&
-           !(event->tp_event->flags & TRACE_EVENT_FL_KPROBE)) {
-               bpf_prog_put(prog);
-               return -EINVAL;
-       }
-
        if (is_tracepoint || is_syscall_tp) {
                int off = trace_event_get_offsets(event->tp_event);
 
index 9dc0deeaad2bdf06717b02820dbe5653239652e0..434c840e2d82f64c127a5c13f1f6aa244544ed43 100644 (file)
@@ -518,17 +518,6 @@ config FUNCTION_PROFILER
 
          If in doubt, say N.
 
-config BPF_KPROBE_OVERRIDE
-       bool "Enable BPF programs to override a kprobed function"
-       depends on BPF_EVENTS
-       depends on KPROBES_ON_FTRACE
-       depends on HAVE_KPROBE_OVERRIDE
-       depends on DYNAMIC_FTRACE_WITH_REGS
-       default n
-       help
-        Allows BPF to override the execution of a probed function and
-        set a different return value.  This is used for error injection.
-
 config FTRACE_MCOUNT_RECORD
        def_bool y
        depends on DYNAMIC_FTRACE
index 1865b0d4cdebb7c9d68d4c8cad9e4a2931b00470..506efe6e8ed97290ee95c7d3297d0ded7756b55d 100644 (file)
 #include <linux/filter.h>
 #include <linux/uaccess.h>
 #include <linux/ctype.h>
-#include <linux/kprobes.h>
-#include <asm/kprobes.h>
-
-#include "trace_probe.h"
 #include "trace.h"
 
 u64 bpf_get_stackid(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5);
@@ -80,29 +76,6 @@ unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
 }
 EXPORT_SYMBOL_GPL(trace_call_bpf);
 
-#ifdef CONFIG_BPF_KPROBE_OVERRIDE
-BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
-{
-       __this_cpu_write(bpf_kprobe_override, 1);
-       regs_set_return_value(regs, rc);
-       arch_ftrace_kprobe_override_function(regs);
-       return 0;
-}
-#else
-BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
-{
-       return -EINVAL;
-}
-#endif
-
-static const struct bpf_func_proto bpf_override_return_proto = {
-       .func           = bpf_override_return,
-       .gpl_only       = true,
-       .ret_type       = RET_INTEGER,
-       .arg1_type      = ARG_PTR_TO_CTX,
-       .arg2_type      = ARG_ANYTHING,
-};
-
 BPF_CALL_3(bpf_probe_read, void *, dst, u32, size, const void *, unsafe_ptr)
 {
        int ret;
@@ -578,10 +551,6 @@ static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func
                return &bpf_get_stackid_proto;
        case BPF_FUNC_perf_event_read_value:
                return &bpf_perf_event_read_value_proto;
-       case BPF_FUNC_override_return:
-               pr_warn_ratelimited("%s[%d] is installing a program with bpf_override_return helper that may cause unexpected behavior!",
-                                   current->comm, task_pid_nr(current));
-               return &bpf_override_return_proto;
        default:
                return tracing_func_proto(func_id);
        }
@@ -797,10 +766,6 @@ int perf_event_attach_bpf_prog(struct perf_event *event,
        struct bpf_prog_array *new_array;
        int ret = -EEXIST;
 
-       /* Kprobe override only works for ftrace based kprobes. */
-       if (prog->kprobe_override && !trace_kprobe_ftrace(event->tp_event))
-               return -EINVAL;
-
        mutex_lock(&bpf_event_mutex);
 
        if (event->prog)
index 8e3c9ec1faf7568b586fd7ad25425cca260c9ba1..abf92e478cfb59e8b82c8851c7238e4f75669f2c 100644 (file)
@@ -42,7 +42,6 @@ struct trace_kprobe {
        (offsetof(struct trace_kprobe, tp.args) +       \
        (sizeof(struct probe_arg) * (n)))
 
-DEFINE_PER_CPU(int, bpf_kprobe_override);
 
 static nokprobe_inline bool trace_kprobe_is_return(struct trace_kprobe *tk)
 {
@@ -88,12 +87,6 @@ static nokprobe_inline unsigned long trace_kprobe_nhit(struct trace_kprobe *tk)
        return nhit;
 }
 
-int trace_kprobe_ftrace(struct trace_event_call *call)
-{
-       struct trace_kprobe *tk = (struct trace_kprobe *)call->data;
-       return kprobe_ftrace(&tk->rp.kp);
-}
-
 static int register_kprobe_event(struct trace_kprobe *tk);
 static int unregister_kprobe_event(struct trace_kprobe *tk);
 
@@ -1177,7 +1170,7 @@ static int kretprobe_event_define_fields(struct trace_event_call *event_call)
 #ifdef CONFIG_PERF_EVENTS
 
 /* Kprobe profile handler */
-static int
+static void
 kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
 {
        struct trace_event_call *call = &tk->tp.call;
@@ -1186,29 +1179,12 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
        int size, __size, dsize;
        int rctx;
 
-       if (bpf_prog_array_valid(call)) {
-               int ret;
-
-               ret = trace_call_bpf(call, regs);
-
-               /*
-                * We need to check and see if we modified the pc of the
-                * pt_regs, and if so clear the kprobe and return 1 so that we
-                * don't do the instruction skipping.  Also reset our state so
-                * we are clean the next pass through.
-                */
-               if (__this_cpu_read(bpf_kprobe_override)) {
-                       __this_cpu_write(bpf_kprobe_override, 0);
-                       reset_current_kprobe();
-                       return 1;
-               }
-               if (!ret)
-                       return 0;
-       }
+       if (bpf_prog_array_valid(call) && !trace_call_bpf(call, regs))
+               return;
 
        head = this_cpu_ptr(call->perf_events);
        if (hlist_empty(head))
-               return 0;
+               return;
 
        dsize = __get_data_size(&tk->tp, regs);
        __size = sizeof(*entry) + tk->tp.size + dsize;
@@ -1217,14 +1193,13 @@ kprobe_perf_func(struct trace_kprobe *tk, struct pt_regs *regs)
 
        entry = perf_trace_buf_alloc(size, NULL, &rctx);
        if (!entry)
-               return 0;
+               return;
 
        entry->ip = (unsigned long)tk->rp.kp.addr;
        memset(&entry[1], 0, dsize);
        store_trace_args(sizeof(*entry), &tk->tp, regs, (u8 *)&entry[1], dsize);
        perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs,
                              head, NULL, NULL);
-       return 0;
 }
 NOKPROBE_SYMBOL(kprobe_perf_func);
 
@@ -1300,7 +1275,6 @@ static int kprobe_register(struct trace_event_call *event,
 static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
 {
        struct trace_kprobe *tk = container_of(kp, struct trace_kprobe, rp.kp);
-       int ret = 0;
 
        raw_cpu_inc(*tk->nhit);
 
@@ -1308,9 +1282,9 @@ static int kprobe_dispatcher(struct kprobe *kp, struct pt_regs *regs)
                kprobe_trace_func(tk, regs);
 #ifdef CONFIG_PERF_EVENTS
        if (tk->tp.flags & TP_FLAG_PROFILE)
-               ret = kprobe_perf_func(tk, regs);
+               kprobe_perf_func(tk, regs);
 #endif
-       return ret;
+       return 0;       /* We don't tweek kernel, so just return 0 */
 }
 NOKPROBE_SYMBOL(kprobe_dispatcher);
 
index adbb3f7d1fb5fab10823b9bce2eb7321d6a2eccf..903273c93e6167afcbe2de99451a906c2e79ab1f 100644 (file)
@@ -253,7 +253,6 @@ struct symbol_cache;
 unsigned long update_symbol_cache(struct symbol_cache *sc);
 void free_symbol_cache(struct symbol_cache *sc);
 struct symbol_cache *alloc_symbol_cache(const char *sym, long offset);
-int trace_kprobe_ftrace(struct trace_event_call *call);
 #else
 /* uprobes do not support symbol fetch methods */
 #define fetch_symbol_u8                        NULL
@@ -279,11 +278,6 @@ alloc_symbol_cache(const char *sym, long offset)
 {
        return NULL;
 }
-
-static inline int trace_kprobe_ftrace(struct trace_event_call *call)
-{
-       return 0;
-}
 #endif /* CONFIG_KPROBE_EVENTS */
 
 struct probe_arg {
index 87db0f9a4c15451152151df2cd84efae2da66b2f..3b4945c1eab06aec48c326f6b1d822cb158461ff 100644 (file)
@@ -15,7 +15,6 @@ hostprogs-y += tracex3
 hostprogs-y += tracex4
 hostprogs-y += tracex5
 hostprogs-y += tracex6
-hostprogs-y += tracex7
 hostprogs-y += test_probe_write_user
 hostprogs-y += trace_output
 hostprogs-y += lathist
@@ -62,7 +61,6 @@ tracex3-objs := bpf_load.o $(LIBBPF) tracex3_user.o
 tracex4-objs := bpf_load.o $(LIBBPF) tracex4_user.o
 tracex5-objs := bpf_load.o $(LIBBPF) tracex5_user.o
 tracex6-objs := bpf_load.o $(LIBBPF) tracex6_user.o
-tracex7-objs := bpf_load.o $(LIBBPF) tracex7_user.o
 load_sock_ops-objs := bpf_load.o $(LIBBPF) load_sock_ops.o
 test_probe_write_user-objs := bpf_load.o $(LIBBPF) test_probe_write_user_user.o
 trace_output-objs := bpf_load.o $(LIBBPF) trace_output_user.o
@@ -106,7 +104,6 @@ always += tracex3_kern.o
 always += tracex4_kern.o
 always += tracex5_kern.o
 always += tracex6_kern.o
-always += tracex7_kern.o
 always += sock_flags_kern.o
 always += test_probe_write_user_kern.o
 always += trace_output_kern.o
@@ -161,7 +158,6 @@ HOSTLOADLIBES_tracex3 += -lelf
 HOSTLOADLIBES_tracex4 += -lelf -lrt
 HOSTLOADLIBES_tracex5 += -lelf
 HOSTLOADLIBES_tracex6 += -lelf
-HOSTLOADLIBES_tracex7 += -lelf
 HOSTLOADLIBES_test_cgrp2_sock2 += -lelf
 HOSTLOADLIBES_load_sock_ops += -lelf
 HOSTLOADLIBES_test_probe_write_user += -lelf
diff --git a/samples/bpf/test_override_return.sh b/samples/bpf/test_override_return.sh
deleted file mode 100755 (executable)
index e68b9ee..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/bin/bash
-
-rm -f testfile.img
-dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1
-DEVICE=$(losetup --show -f testfile.img)
-mkfs.btrfs -f $DEVICE
-mkdir tmpmnt
-./tracex7 $DEVICE
-if [ $? -eq 0 ]
-then
-       echo "SUCCESS!"
-else
-       echo "FAILED!"
-fi
-losetup -d $DEVICE
diff --git a/samples/bpf/tracex7_kern.c b/samples/bpf/tracex7_kern.c
deleted file mode 100644 (file)
index 1ab308a..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <uapi/linux/ptrace.h>
-#include <uapi/linux/bpf.h>
-#include <linux/version.h>
-#include "bpf_helpers.h"
-
-SEC("kprobe/open_ctree")
-int bpf_prog1(struct pt_regs *ctx)
-{
-       unsigned long rc = -12;
-
-       bpf_override_return(ctx, rc);
-       return 0;
-}
-
-char _license[] SEC("license") = "GPL";
-u32 _version SEC("version") = LINUX_VERSION_CODE;
diff --git a/samples/bpf/tracex7_user.c b/samples/bpf/tracex7_user.c
deleted file mode 100644 (file)
index 8a52ac4..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#define _GNU_SOURCE
-
-#include <stdio.h>
-#include <linux/bpf.h>
-#include <unistd.h>
-#include "libbpf.h"
-#include "bpf_load.h"
-
-int main(int argc, char **argv)
-{
-       FILE *f;
-       char filename[256];
-       char command[256];
-       int ret;
-
-       snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
-
-       if (load_bpf_file(filename)) {
-               printf("%s", bpf_log_buf);
-               return 1;
-       }
-
-       snprintf(command, 256, "mount %s tmpmnt/", argv[1]);
-       f = popen(command, "r");
-       ret = pclose(f);
-
-       return ret ? 0 : 1;
-}
index adb66f78b674205d4ba9c2d80d44721cca1d6ef6..e880ae6434eed9eb29db99169c716c94c7cf30aa 100644 (file)
@@ -677,10 +677,6 @@ union bpf_attr {
  *     @buf: buf to fill
  *     @buf_size: size of the buf
  *     Return : 0 on success or negative error code
- *
- * int bpf_override_return(pt_regs, rc)
- *     @pt_regs: pointer to struct pt_regs
- *     @rc: the return value to set
  */
 #define __BPF_FUNC_MAPPER(FN)          \
        FN(unspec),                     \
@@ -740,8 +736,7 @@ union bpf_attr {
        FN(xdp_adjust_meta),            \
        FN(perf_event_read_value),      \
        FN(perf_prog_read_value),       \
-       FN(getsockopt),                 \
-       FN(override_return),
+       FN(getsockopt),
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  * function eBPF program intends to call
index 33cb00e46c49f967d4144f0188333025ead64823..fd9a17fa8a8bd188aebbf2104dcb196c7dd6e2cf 100644 (file)
@@ -82,8 +82,7 @@ static int (*bpf_perf_event_read_value)(void *map, unsigned long long flags,
 static int (*bpf_perf_prog_read_value)(void *ctx, void *buf,
                                       unsigned int buf_size) =
        (void *) BPF_FUNC_perf_prog_read_value;
-static int (*bpf_override_return)(void *ctx, unsigned long rc) =
-       (void *) BPF_FUNC_override_return;
+
 
 /* llvm builtin functions that eBPF C program may use to
  * emit BPF_LD_ABS and BPF_LD_IND instructions