summaryrefslogtreecommitdiff
path: root/kernel/trace
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-06-14 14:56:26 -0400
committerDavid S. Miller <davem@davemloft.net>2017-06-14 14:56:26 -0400
commit2fae5d0e647c6470d206e72b5fc24972bb900f70 (patch)
treebc04b4c45c52a732e1d92c7348e3a1354bfd47f6 /kernel/trace
parenta88e2676a6cd3352c2f590f872233d83d8db289c (diff)
parent18f3d6be6be124316d3abfee667c5e8b88dec100 (diff)
Merge branch 'bpf-ctx-narrow'
Yonghong Song says: ==================== bpf: permit bpf program narrower loads for ctx fields Today, if users try to access a ctx field through a narrower load, e.g., __be16 prot = __sk_buff->protocol, verifier will fail. This set contains the verifier change to permit such loads for certain ctx fields as well as the new test cases in selftests/bpf. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/bpf_trace.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c
index 051d7fca0c09..9d3ec8253131 100644
--- a/kernel/trace/bpf_trace.c
+++ b/kernel/trace/bpf_trace.c
@@ -479,7 +479,7 @@ static const struct bpf_func_proto *kprobe_prog_func_proto(enum bpf_func_id func
/* bpf+kprobe programs can access fields of 'struct pt_regs' */
static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
- enum bpf_reg_type *reg_type)
+ enum bpf_reg_type *reg_type, int *ctx_field_size)
{
if (off < 0 || off >= sizeof(struct pt_regs))
return false;
@@ -562,7 +562,7 @@ static const struct bpf_func_proto *tp_prog_func_proto(enum bpf_func_id func_id)
}
static bool tp_prog_is_valid_access(int off, int size, enum bpf_access_type type,
- enum bpf_reg_type *reg_type)
+ enum bpf_reg_type *reg_type, int *ctx_field_size)
{
if (off < sizeof(void *) || off >= PERF_MAX_TRACE_SIZE)
return false;
@@ -581,17 +581,26 @@ const struct bpf_verifier_ops tracepoint_prog_ops = {
};
static bool pe_prog_is_valid_access(int off, int size, enum bpf_access_type type,
- enum bpf_reg_type *reg_type)
+ enum bpf_reg_type *reg_type, int *ctx_field_size)
{
+ int sample_period_off;
+
if (off < 0 || off >= sizeof(struct bpf_perf_event_data))
return false;
if (type != BPF_READ)
return false;
if (off % size != 0)
return false;
- if (off == offsetof(struct bpf_perf_event_data, sample_period)) {
- if (size != sizeof(u64))
- return false;
+
+ /* permit 1, 2, 4 byte narrower and 8 normal read access to sample_period */
+ sample_period_off = offsetof(struct bpf_perf_event_data, sample_period);
+ if (off >= sample_period_off && off < sample_period_off + sizeof(__u64)) {
+ *ctx_field_size = 8;
+#ifdef __LITTLE_ENDIAN
+ return (off & 0x7) == 0 && size <= 8 && (size & (size - 1)) == 0;
+#else
+ return ((off & 0x7) + size) == 8 && size <= 8 && (size & (size - 1)) == 0;
+#endif
} else {
if (size != sizeof(long))
return false;