aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-05-10 14:38:07 -0400
committerDavid S. Miller <davem@davemloft.net>2017-05-11 14:19:00 -0400
commite07b98d9bffe410019dfcf62c3428d4a96c56a2c (patch)
tree52a3aede39b1bac6a409586bcdd272d9aa958868 /include
parentc5fc9692d101d1318b0f53f9f691cd88ac029317 (diff)
bpf: Add strict alignment flag for BPF_PROG_LOAD.
Add a new field, "prog_flags", and an initial flag value BPF_F_STRICT_ALIGNMENT. When set, the verifier will enforce strict pointer alignment regardless of the setting of CONFIG_EFFICIENT_UNALIGNED_ACCESS. The verifier, in this mode, will also use a fixed value of "2" in place of NET_IP_ALIGN. This facilitates test cases that will exercise and validate this part of the verifier even when run on architectures where alignment doesn't matter. Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'include')
-rw-r--r--include/linux/bpf_verifier.h1
-rw-r--r--include/uapi/linux/bpf.h8
2 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index 7c6a51924afc..d5093b52b485 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -90,6 +90,7 @@ struct bpf_verifier_env {
90 struct bpf_prog *prog; /* eBPF program being verified */ 90 struct bpf_prog *prog; /* eBPF program being verified */
91 struct bpf_verifier_stack_elem *head; /* stack of verifier states to be processed */ 91 struct bpf_verifier_stack_elem *head; /* stack of verifier states to be processed */
92 int stack_size; /* number of states to be processed */ 92 int stack_size; /* number of states to be processed */
93 bool strict_alignment; /* perform strict pointer alignment checks */
93 struct bpf_verifier_state cur_state; /* current verifier state */ 94 struct bpf_verifier_state cur_state; /* current verifier state */
94 struct bpf_verifier_state_list **explored_states; /* search pruning optimization */ 95 struct bpf_verifier_state_list **explored_states; /* search pruning optimization */
95 const struct bpf_ext_analyzer_ops *analyzer_ops; /* external analyzer ops */ 96 const struct bpf_ext_analyzer_ops *analyzer_ops; /* external analyzer ops */
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 945a1f5f63c5..94dfa9def355 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -132,6 +132,13 @@ enum bpf_attach_type {
132 */ 132 */
133#define BPF_F_ALLOW_OVERRIDE (1U << 0) 133#define BPF_F_ALLOW_OVERRIDE (1U << 0)
134 134
135/* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
136 * verifier will perform strict alignment checking as if the kernel
137 * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
138 * and NET_IP_ALIGN defined to 2.
139 */
140#define BPF_F_STRICT_ALIGNMENT (1U << 0)
141
135#define BPF_PSEUDO_MAP_FD 1 142#define BPF_PSEUDO_MAP_FD 1
136 143
137/* flags for BPF_MAP_UPDATE_ELEM command */ 144/* flags for BPF_MAP_UPDATE_ELEM command */
@@ -177,6 +184,7 @@ union bpf_attr {
177 __u32 log_size; /* size of user buffer */ 184 __u32 log_size; /* size of user buffer */
178 __aligned_u64 log_buf; /* user supplied buffer */ 185 __aligned_u64 log_buf; /* user supplied buffer */
179 __u32 kern_version; /* checked when prog_type=kprobe */ 186 __u32 kern_version; /* checked when prog_type=kprobe */
187 __u32 prog_flags;
180 }; 188 };
181 189
182 struct { /* anonymous struct used by BPF_OBJ_* commands */ 190 struct { /* anonymous struct used by BPF_OBJ_* commands */