Skip to contentSkip to conversation

BPF: properly precedence of exclusive attr flags

PATCH New [email protected] 1 participant 1 message Apr 7, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 BPF: properly precedence of exclusive attr flags

From: zhongjun <[email protected]>

BPF_F_STRICT_ALIGNMENT and BPF_F_ANY_ALIGNMENT are exclusive flags. Intuitively the strict one should take higher precedence. Applying this patch, make semantics of flags more properly.

base-commit: 919e659ed12568b5b8ba6c2ffdd82d8d31fc28af

---
 kernel/bpf/verifier.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/bpf/verifier.c +2 -3
index d517d13878cf..ed912c0cedee 100644
@@ -17710,11 +17710,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr)
 		goto skip_full_check;
 	}
 
-	env->strict_alignment = !!(attr->prog_flags & BPF_F_STRICT_ALIGNMENT);
-	if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS))
-		env->strict_alignment = true;
+	env->strict_alignment = !IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS);
 	if (attr->prog_flags & BPF_F_ANY_ALIGNMENT)
 		env->strict_alignment = false;
+	env->strict_alignment |= !!(attr->prog_flags & BPF_F_STRICT_ALIGNMENT);
 
 	env->allow_ptr_leaks = bpf_allow_ptr_leaks();
 	env->allow_uninit_stack = bpf_allow_uninit_stack();
Signature · 1 line
2.20.1