Skip to content

Commit 7018d1b

Browse files
committed
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Daniel Borkmann says: ==================== pull-request: bpf-next 2018-01-17 The following pull-request contains BPF updates for your *net-next* tree. The main changes are: 1) Add initial BPF map offloading for nfp driver. Currently only programs were supported so far w/o being able to access maps. Offloaded programs are right now only allowed to perform map lookups, and control path is responsible for populating the maps. BPF core infrastructure along with nfp implementation is provided, from Jakub. 2) Various follow-ups to Josef's BPF error injections. More specifically that includes: properly check whether the error injectable event is on function entry or not, remove the percpu bpf_kprobe_override and rather compare instruction pointer with original one, separate error-injection from kprobes since it's not limited to it, add injectable error types in order to specify what is the expected type of failure, and last but not least also support the kernel's fault injection framework, all from Masami. 3) Various misc improvements and cleanups to the libbpf Makefile. That is, fix permissions when installing BPF header files, remove unused variables and functions, and also install the libbpf.h header, from Jesper. 4) When offloading to nfp JIT and the BPF insn is unsupported in the JIT, then reject right at verification time. Also fix libbpf with regards to ELF section name matching by properly treating the program type as prefix. Both from Quentin. 5) Add -DPACKAGE to bpftool when including bfd.h for the disassembler. This is needed, for example, when building libfd from source as bpftool doesn't supply a config.h for bfd.h. Fix from Jiong. 6) xdp_convert_ctx_access() is simplified since it doesn't need to set target size during verification, from Jesper. 7) Let bpftool properly recognize BPF_PROG_TYPE_CGROUP_DEVICE program types, from Roman. 8) Various functions in BPF cpumap were not declared static, from Wei. 9) Fix a double semicolon in BPF samples, from Luis. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents e7e70fa + e8a9d96 commit 7018d1b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2365
-402
lines changed

Documentation/fault-injection/fault-injection.txt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ o fail_mmc_request
3030
injects MMC data errors on devices permitted by setting
3131
debugfs entries under /sys/kernel/debug/mmc0/fail_mmc_request
3232

33+
o fail_function
34+
35+
injects error return on specific functions, which are marked by
36+
ALLOW_ERROR_INJECTION() macro, by setting debugfs entries
37+
under /sys/kernel/debug/fail_function. No boot option supported.
38+
3339
Configure fault-injection capabilities behavior
3440
-----------------------------------------------
3541

@@ -123,6 +129,29 @@ configuration of fault-injection capabilities.
123129
default is 'N', setting it to 'Y' will disable failure injections
124130
when dealing with private (address space) futexes.
125131

132+
- /sys/kernel/debug/fail_function/inject:
133+
134+
Format: { 'function-name' | '!function-name' | '' }
135+
specifies the target function of error injection by name.
136+
If the function name leads '!' prefix, given function is
137+
removed from injection list. If nothing specified ('')
138+
injection list is cleared.
139+
140+
- /sys/kernel/debug/fail_function/injectable:
141+
142+
(read only) shows error injectable functions and what type of
143+
error values can be specified. The error type will be one of
144+
below;
145+
- NULL: retval must be 0.
146+
- ERRNO: retval must be -1 to -MAX_ERRNO (-4096).
147+
- ERR_NULL: retval must be 0 or -1 to -MAX_ERRNO (-4096).
148+
149+
- /sys/kernel/debug/fail_function/<functiuon-name>/retval:
150+
151+
specifies the "error" return value to inject to the given
152+
function for given function. This will be created when
153+
user specifies new injection entry.
154+
126155
o Boot option
127156

128157
In order to inject faults while debugfs is not available (early boot time),
@@ -268,6 +297,45 @@ trap "echo 0 > /sys/kernel/debug/$FAILTYPE/probability" SIGINT SIGTERM EXIT
268297
echo "Injecting errors into the module $module... (interrupt to stop)"
269298
sleep 1000000
270299

300+
------------------------------------------------------------------------------
301+
302+
o Inject open_ctree error while btrfs mount
303+
304+
#!/bin/bash
305+
306+
rm -f testfile.img
307+
dd if=/dev/zero of=testfile.img bs=1M seek=1000 count=1
308+
DEVICE=$(losetup --show -f testfile.img)
309+
mkfs.btrfs -f $DEVICE
310+
mkdir -p tmpmnt
311+
312+
FAILTYPE=fail_function
313+
FAILFUNC=open_ctree
314+
echo $FAILFUNC > /sys/kernel/debug/$FAILTYPE/inject
315+
echo -12 > /sys/kernel/debug/$FAILTYPE/$FAILFUNC/retval
316+
echo N > /sys/kernel/debug/$FAILTYPE/task-filter
317+
echo 100 > /sys/kernel/debug/$FAILTYPE/probability
318+
echo 0 > /sys/kernel/debug/$FAILTYPE/interval
319+
echo -1 > /sys/kernel/debug/$FAILTYPE/times
320+
echo 0 > /sys/kernel/debug/$FAILTYPE/space
321+
echo 1 > /sys/kernel/debug/$FAILTYPE/verbose
322+
323+
mount -t btrfs $DEVICE tmpmnt
324+
if [ $? -ne 0 ]
325+
then
326+
echo "SUCCESS!"
327+
else
328+
echo "FAILED!"
329+
umount tmpmnt
330+
fi
331+
332+
echo > /sys/kernel/debug/$FAILTYPE/inject
333+
334+
rmdir tmpmnt
335+
losetup -d $DEVICE
336+
rm testfile.img
337+
338+
271339
Tool to run command with failslab or fail_page_alloc
272340
----------------------------------------------------
273341
In order to make it easier to accomplish the tasks mentioned above, we can use

arch/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ config HAVE_OPTPROBES
196196
config HAVE_KPROBES_ON_FTRACE
197197
bool
198198

199-
config HAVE_KPROBE_OVERRIDE
199+
config HAVE_FUNCTION_ERROR_INJECTION
200200
bool
201201

202202
config HAVE_NMI

arch/x86/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ config X86
154154
select HAVE_KERNEL_XZ
155155
select HAVE_KPROBES
156156
select HAVE_KPROBES_ON_FTRACE
157-
select HAVE_KPROBE_OVERRIDE
157+
select HAVE_FUNCTION_ERROR_INJECTION
158158
select HAVE_KRETPROBES
159159
select HAVE_KVM
160160
select HAVE_LIVEPATCH if X86_64
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _ASM_ERROR_INJECTION_H
3+
#define _ASM_ERROR_INJECTION_H
4+
5+
#include <linux/compiler.h>
6+
#include <linux/linkage.h>
7+
#include <asm/ptrace.h>
8+
#include <asm-generic/error-injection.h>
9+
10+
asmlinkage void just_return_func(void);
11+
void override_function_with_return(struct pt_regs *regs);
12+
13+
#endif /* _ASM_ERROR_INJECTION_H */

arch/x86/include/asm/kprobes.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ extern const int kretprobe_blacklist_size;
6767
void arch_remove_kprobe(struct kprobe *p);
6868
asmlinkage void kretprobe_trampoline(void);
6969

70-
#ifdef CONFIG_KPROBES_ON_FTRACE
71-
extern void arch_ftrace_kprobe_override_function(struct pt_regs *regs);
72-
#endif
70+
extern void arch_kprobe_override_function(struct pt_regs *regs);
7371

7472
/* Architecture specific copy of original instruction*/
7573
struct arch_specific_insn {

arch/x86/kernel/kprobes/ftrace.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,3 @@ int arch_prepare_kprobe_ftrace(struct kprobe *p)
9797
p->ainsn.boostable = false;
9898
return 0;
9999
}
100-
101-
asmlinkage void override_func(void);
102-
asm(
103-
".type override_func, @function\n"
104-
"override_func:\n"
105-
" ret\n"
106-
".size override_func, .-override_func\n"
107-
);
108-
109-
void arch_ftrace_kprobe_override_function(struct pt_regs *regs)
110-
{
111-
regs->ip = (unsigned long)&override_func;
112-
}
113-
NOKPROBE_SYMBOL(arch_ftrace_kprobe_override_function);

arch/x86/lib/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ lib-y += memcpy_$(BITS).o
2626
lib-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem.o
2727
lib-$(CONFIG_INSTRUCTION_DECODER) += insn.o inat.o insn-eval.o
2828
lib-$(CONFIG_RANDOMIZE_BASE) += kaslr.o
29+
lib-$(CONFIG_FUNCTION_ERROR_INJECTION) += error-inject.o
2930

3031
obj-y += msr.o msr-reg.o msr-reg-export.o hweight.o
3132

arch/x86/lib/error-inject.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/error-injection.h>
4+
#include <linux/kprobes.h>
5+
6+
asmlinkage void just_return_func(void);
7+
8+
asm(
9+
".type just_return_func, @function\n"
10+
"just_return_func:\n"
11+
" ret\n"
12+
".size just_return_func, .-just_return_func\n"
13+
);
14+
15+
void override_function_with_return(struct pt_regs *regs)
16+
{
17+
regs->ip = (unsigned long)&just_return_func;
18+
}
19+
NOKPROBE_SYMBOL(override_function_with_return);

drivers/net/ethernet/netronome/nfp/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ endif
4444

4545
ifeq ($(CONFIG_BPF_SYSCALL),y)
4646
nfp-objs += \
47+
bpf/cmsg.o \
4748
bpf/main.o \
4849
bpf/offload.o \
4950
bpf/verifier.o \

0 commit comments

Comments
 (0)