aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/syscall.c
diff options
context:
space:
mode:
authorDavid Miller <davem@davemloft.net>2018-12-01 00:08:14 -0500
committerAlexei Starovoitov <ast@kernel.org>2018-12-01 00:38:48 -0500
commite9ee9efc0d176512cdce9d27ff8549d7ffa2bfcd (patch)
tree94b32bfcaa32c3538810330370ed7cd4b07e15e4 /kernel/bpf/syscall.c
parent88945f460603ad8909b556c67a9229bb23188d41 (diff)
bpf: Add BPF_F_ANY_ALIGNMENT.
Often we want to write tests cases that check things like bad context offset accesses. And one way to do this is to use an odd offset on, for example, a 32-bit load. This unfortunately triggers the alignment checks first on platforms that do not set CONFIG_EFFICIENT_UNALIGNED_ACCESS. So the test case see the alignment failure rather than what it was testing for. It is often not completely possible to respect the original intention of the test, or even test the same exact thing, while solving the alignment issue. Another option could have been to check the alignment after the context and other validations are performed by the verifier, but that is a non-trivial change to the verifier. Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'kernel/bpf/syscall.c')
-rw-r--r--kernel/bpf/syscall.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 85cbeec06e50..f9554d9a14e1 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -1452,9 +1452,14 @@ static int bpf_prog_load(union bpf_attr *attr, union bpf_attr __user *uattr)
1452 if (CHECK_ATTR(BPF_PROG_LOAD)) 1452 if (CHECK_ATTR(BPF_PROG_LOAD))
1453 return -EINVAL; 1453 return -EINVAL;
1454 1454
1455 if (attr->prog_flags & ~BPF_F_STRICT_ALIGNMENT) 1455 if (attr->prog_flags & ~(BPF_F_STRICT_ALIGNMENT | BPF_F_ANY_ALIGNMENT))
1456 return -EINVAL; 1456 return -EINVAL;
1457 1457
1458 if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) &&
1459 (attr->prog_flags & BPF_F_ANY_ALIGNMENT) &&
1460 !capable(CAP_SYS_ADMIN))
1461 return -EPERM;
1462
1458 /* copy eBPF program license from user space */ 1463 /* copy eBPF program license from user space */
1459 if (strncpy_from_user(license, u64_to_user_ptr(attr->license), 1464 if (strncpy_from_user(license, u64_to_user_ptr(attr->license),
1460 sizeof(license) - 1) < 0) 1465 sizeof(license) - 1) < 0)