-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpf: avoid UB in usages of the __imm_insn macro #6985
Conversation
Upstream branch: 329a672 |
Upstream branch: 329a672 |
0f96339
to
4e1f58c
Compare
459d932
to
ba083f5
Compare
Upstream branch: 75b0fbf |
4e1f58c
to
ced6d0d
Compare
ba083f5
to
20150dc
Compare
Upstream branch: 93d1c2d |
ced6d0d
to
3b7fb40
Compare
20150dc
to
606f72a
Compare
Upstream branch: 7e2c7a3 |
3b7fb40
to
29aa300
Compare
Upstream branch: 7e2c7a3 |
29aa300
to
6a8e7fa
Compare
606f72a
to
041b1be
Compare
[Changes from V2: - no-strict-aliasing is only applied when building with GCC. - cpumask_failure.c is excluded, as it doesn't use __imm_insn.] The __imm_insn macro is defined in bpf_misc.h as: #define __imm_insn(name, expr) [name]"i"(*(long *)&(expr)) This may lead to type-punning and strict aliasing rules violations in it's typical usage where the address of a struct bpf_insn is passed as expr, like in: __imm_insn(st_mem, BPF_ST_MEM(BPF_W, BPF_REG_1, offsetof(struct __sk_buff, mark), 42)) Where: #define BPF_ST_MEM(SIZE, DST, OFF, IMM) \ ((struct bpf_insn) { \ .code = BPF_ST | BPF_SIZE(SIZE) | BPF_MEM, \ .dst_reg = DST, \ .src_reg = 0, \ .off = OFF, \ .imm = IMM }) In all the actual instances of this in the BPF selftests the value is fed to a volatile asm statement as soon as it gets read from memory, and thus it is unlikely anti-aliasing rules breakage may lead to misguided optimizations. However, GCC detects the potential problem (indirectly) by issuing a warning stating that a temporary <Uxxxxxx> is used uninitialized, where the temporary corresponds to the memory read by *(long *). This patch adds -fno-strict-aliasing to the compilation flags of the particular selftests that do type punning via __imm_insn, only for GCC. Tested in master bpf-next. No regressions. Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com> Cc: david.faust@oracle.com Cc: cupertino.miranda@oracle.com Cc: Yonghong Song <yonghong.song@linux.dev> Cc: Eduard Zingerman <eddyz87@gmail.com>
Upstream branch: e612b5c |
6a8e7fa
to
e43e59c
Compare
041b1be
to
63334d2
Compare
At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=851521 irrelevant now. Closing PR. |
Pull request for series with
subject: bpf: avoid UB in usages of the __imm_insn macro
version: 1
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=851140