History

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.

David S. Miller committed 9 years ago

Commit e07b98d1 parent c5fc9696 files · +40 −9Browse files

Showing the changes to include/uapi (1 of 6 files). Show all

Unified · Split

include/uapi/linux/bpf.h+8−0
@@ -132,6 +132,13 @@ enum bpf_attach_type { · 131 unmodified lines
132132 */
133133 #define BPF_F_ALLOW_OVERRIDE (1U << 0)
134134
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+
135142 #define BPF_PSEUDO_MAP_FD 1
136143
137144 /* flags for BPF_MAP_UPDATE_ELEM command */
@@ -177,6 +184,7 @@ union bpf_attr { · 39 unmodified lines
177184 __u32 log_size; /* size of user buffer */
178185 __aligned_u64 log_buf; /* user supplied buffer */
179186 __u32 kern_version; /* checked when prog_type=kprobe */
187+ __u32 prog_flags;
180188 };
181189
182190 struct { /* anonymous struct used by BPF_OBJ_* commands */