bpf: Restrict kernel image access functions when the kernel is locked down
authorDavid Howells <dhowells@redhat.com>
Wed, 24 May 2017 13:56:05 +0000 (14:56 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Sun, 7 Oct 2018 20:57:06 +0000 (21:57 +0100)
There are some bpf functions can be used to read kernel memory:
bpf_probe_read, bpf_probe_write_user and bpf_trace_printk.  These allow
private keys in kernel memory (e.g. the hibernation image signing key) to
be read by an eBPF program and kernel memory to be altered without
restriction.

Completely prohibit the use of BPF when the kernel is locked down.

Suggested-by: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: netdev@vger.kernel.org
cc: Chun-Yi Lee <jlee@suse.com>
cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
[bwh: Adjust context to apply after commit dcab51f19b29
 "bpf: Expose check_uarg_tail_zero()"]

Gbp-Pq: Topic features/all/lockdown
Gbp-Pq: Name 0027-bpf-Restrict-kernel-image-access-functions-when-the-.patch

kernel/bpf/syscall.c

index a31a1ba0f8eada88e03dc4a73ad9c0305cc70198..a3006ef876620bdd2f1fa27ac63952f3ca46b312 100644 (file)
@@ -2274,6 +2274,9 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
        if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN))
                return -EPERM;
 
+       if (kernel_is_locked_down("BPF"))
+               return -EPERM;
+
        err = bpf_check_uarg_tail_zero(uattr, sizeof(attr), size);
        if (err)
                return err;