Commit 0837907
committed
bpf: Normalize accessing netfilter ctx fields
BPF netfilter programs are currently not portable across 32-bit and 64-bit
systems: within 'struct bpf_nf_ctx' size and offsets vary with system word
size; the .is_valid_access() verifier hook rejects u64 loads on 32-bit
hosts; and no .convert_ctx_access hook exists to rewrite such loads as u32.
Update 'struct bpf_nf_ctx' ptr fields with __bpf_md_ptr() to gain stable
sizing and offsets. In nf_is_valid_access() use bpf_ctx_range_ptr() for
handling ptr field offsets, and create common bpf_ctx_ptr_size_valid() to
check load sizes. Finally, add the verifier hook nf_convert_ctx_access()
which rewrites loads according to system ptr size.
Before:
libbpf: prog 'with_invalid_return_code_test1': BPF program load failed: -EACCES
libbpf: prog 'with_invalid_return_code_test1': failed to load: -EACCES
libbpf: failed to load object 'verifier_netfilter_retcode'
run_subtest:PASS:unexpected_load_success 0 nsec
validate_msgs:FAIL:748 expect_msg
VERIFIER LOG:
=============
Global function with_invalid_return_code_test1() doesn't return scalar. Only those are supported.
0: R1=ctx() R10=fp0
; asm volatile (" \ @ verifier_netfilter_retcode.c:12
0: (79) r0 = *(u64 *)(r1 +0)
invalid bpf_context access off=0 size=8 is_valid_access=nf_is_valid_access
processed 1 insns (limit 1000000) max_states_per_insn 0 total_states 0 peak_states 0 mark_read 0
=============
EXPECTED SUBSTR: 'R0 is not a known value'
torvalds#534/1 verifier_netfilter_retcode/bpf_exit with invalid return code. test1:FAIL
After:
torvalds#534/1 verifier_netfilter_retcode/bpf_exit with invalid return code. test1:OK
torvalds#534/2 verifier_netfilter_retcode/bpf_exit with valid return code. test2:OK
torvalds#534/3 verifier_netfilter_retcode/bpf_exit with valid return code. test3:OK
torvalds#534/4 verifier_netfilter_retcode/bpf_exit with invalid return code. test4:OK
torvalds#534 verifier_netfilter_retcode:OK
Summary: 1/4 PASSED, 0 SKIPPED, 0 FAILED
Signed-off-by: Tony Ambardar <[email protected]>1 parent 13ae5a6 commit 0837907
File tree
2 files changed
+32
-6
lines changed- include/net/netfilter
- net/netfilter
2 files changed
+32
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
303 | 303 | | |
304 | 304 | | |
305 | 305 | | |
306 | | - | |
307 | | - | |
| 306 | + | |
| 307 | + | |
308 | 308 | | |
309 | 309 | | |
310 | 310 | | |
311 | | - | |
312 | | - | |
| 311 | + | |
| 312 | + | |
313 | 313 | | |
314 | 314 | | |
315 | 315 | | |
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
323 | 348 | | |
324 | 349 | | |
325 | 350 | | |
| |||
328 | 353 | | |
329 | 354 | | |
330 | 355 | | |
| 356 | + | |
331 | 357 | | |
332 | 358 | | |
0 commit comments