summary refs log tree commit diff
path: root/kernel/trace
diff options
context:
space:
mode:
authorYonghong Song <yhs@fb.com>2019-05-25 11:57:53 -0700
committerDaniel Borkmann <daniel@iogearbox.net>2019-05-28 10:51:33 +0200
commite1afb70252a8614e1ef7aec05ff1b84fd324b782 (patch)
treef8c6ffc8af4675f6e90878073ca03f59072ac420 /kernel/trace
parent0d97dacc46d9af2daba1af224747d452bd988365 (diff)
downloadlinux-e1afb70252a8614e1ef7aec05ff1b84fd324b782.tar.gz
bpf: check signal validity in nmi for bpf_send_signal() helper
Commit 8b401f9ed244 ("bpf: implement bpf_send_signal() helper")
introduced bpf_send_signal() helper. If the context is nmi,
the sending signal work needs to be deferred to irq_work.
If the signal is invalid, the error will appear in irq_work
and it won't be propagated to user.

This patch did an early check in the helper itself to notify
user invalid signal, as suggested by Daniel.

Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/bpf_trace.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 70029eafc71f..fe73926a07cd 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -600,6 +600,12 @@ BPF_CALL_1(bpf_send_signal, u32, sig)
 		return -EPERM;
 
 	if (in_nmi()) {
+		/* Do an early check on signal validity. Otherwise,
+		 * the error is lost in deferred irq_work.
+		 */
+		if (unlikely(!valid_signal(sig)))
+			return -EINVAL;
+
 		work = this_cpu_ptr(&send_signal_work);
 		if (work->irq_work.flags & IRQ_WORK_BUSY)
 			return -EBUSY;