Commit 23247da
* feat(net): implement BPF filter support for AF_PACKET (#2031)
Extract cBPF interpreter from seccomp.rs to bpf/classic.rs as shared
infrastructure. Generalize to accept &[u8] input for packet filtering.
Support: BPF_W/BPF_H/BPF_B load widths, BPF_ABS/BPF_IND addressing,
BPF_MSH (IP header length extraction), full ALU/JMP/RET/MISC ops.
Security: validate_cbpf checks program bounds (<=4096 insns), last
insn is RET, checked_add on jump targets, static div/mod k!=0 reject,
ST/STX k<16, LD/LDX mode whitelist. Runtime: OOB reads return a=0,
div/mod by zero returns a=0, fall-through returns 0 (drop).
AF_PACKET: SO_ATTACH_FILTER/SO_DETACH_FILTER/SO_LOCK_FILTER via
PSOL::SOCKET dispatch. Filter stored in RcuArcSlot (lock-free read),
AtomicBool fast-path skip when no filter attached. Filter runs on
frame[start..] (RAW: full frame, DGRAM: L3 payload).
Seccomp: refactored to use bpf::classic, seccomp-specific validation
layered on top of validate_cbpf. Big-endian serialization preserves
existing behavior.
Refs: #2031, #691
Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
* test: update af_packet_sockopt dunitest for SO_ATTACH_FILTER
The test AttachFilterIsNotSilentlyAccepted expected ENOPROTOOPT (option
unimplemented). Now that SO_ATTACH_FILTER is implemented (PR #2110),
update to expect success. Add DetachFilterReturnsEnoentWhenNoFilter test.
Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
* fix: correct TestSockFprog casing in dunitest (FProg→Fprog)
Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
* fix: pass dummy value to SO_DETACH_FILTER in dunitest
sys_setsockopt with optlen=0 may short-circuit before calling
set_option. Pass a dummy int to ensure the kernel handler runs.
Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
* fix(net): align AF_PACKET classic BPF with Linux
Harden the shared classic BPF validator and interpreter with exact opcode validation, definite scratch-memory initialization, fail-closed packet loads, and fallible user-controlled allocations. Keep seccomp on its Linux-compatible instruction subset without serializing seccomp_data for every filter.
Use a zero-copy packet view for AF_PACKET filtering, propagate real ingress metadata, implement the Linux ancillary and payload-offset semantics, and apply filter snaplen consistently to queue accounting and recv behavior.
Linearize filter attach, detach, and lock operations around one control lock and an optional RCU publication point. Preserve Linux optlen, errno, lock ordering, and ENOMEM behavior.
Extend AF_PACKET, seccomp, and RCU dunitests to cover validator boundaries, runtime failures, snaplen, ancillary offsets, socket option ABI behavior, and optional RCU slot lifetimes.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(net): preserve outgoing inline VLAN filters
Keep inline 802.1Q and 802.1ad headers visible to AF_PACKET SOCK_RAW filters for PACKET_OUTGOING frames, matching Linux dev_queue_xmit_nit semantics.
Continue normalizing received VLAN headers into metadata, while deriving protocol, network-relative loads, RAW/DGRAM offsets, ancillary values, and queued bytes from the same packet view.
Add a deterministic veth regression that filters outgoing traffic by packet type and the inline VLAN EtherType.
Signed-off-by: longjin <longjin@dragonos.org>
* fix(net): align classic filter socket option ABI
Signed-off-by: longjin <longjin@dragonos.org>
* fix(net): retain zero-length packet datagrams
Signed-off-by: longjin <longjin@dragonos.org>
* fix(net): harden socket filter option handling
Signed-off-by: longjin <longjin@dragonos.org>
* fix(rcu): harden arc slot lifetime handling
Avoid entering an RCU read-side section for empty optional slots while reloading and pinning non-empty snapshots under RCU protection. Make raw slot swaps unsafe so callers must preserve removed references through a grace period, and update packet filters and signal handlers to document that obligation.
Add bounded cross-task RCU lifecycle and overlap coverage plus AF_PACKET replacement state regression tests.
Signed-off-by: longjin <longjin@dragonos.org>
---------
Signed-off-by: sparkzky <sparkhhhhhhhhhh@outlook.com>
Signed-off-by: longjin <longjin@dragonos.org>
Co-authored-by: longjin <longjin@dragonos.org>
1 parent 6b693da commit 23247da
19 files changed
Lines changed: 2442 additions & 470 deletions
File tree
- kernel/src
- bpf
- driver/net
- e1000e
- net
- socket/packet
- syscall
- process
- namespace
- rcu
- user/apps/tests/dunitest/suites/normal
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
90 | 90 | | |
91 | 91 | | |
92 | 92 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 93 | + | |
96 | 94 | | |
97 | 95 | | |
98 | 96 | | |
| |||
313 | 311 | | |
314 | 312 | | |
315 | 313 | | |
316 | | - | |
| 314 | + | |
317 | 315 | | |
318 | 316 | | |
319 | 317 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
305 | | - | |
306 | | - | |
| 304 | + | |
307 | 305 | | |
308 | 306 | | |
309 | 307 | | |
| |||
405 | 403 | | |
406 | 404 | | |
407 | 405 | | |
408 | | - | |
| 406 | + | |
409 | 407 | | |
410 | 408 | | |
411 | 409 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
444 | 444 | | |
445 | 445 | | |
446 | 446 | | |
447 | | - | |
| 447 | + | |
448 | 448 | | |
449 | 449 | | |
450 | 450 | | |
| |||
742 | 742 | | |
743 | 743 | | |
744 | 744 | | |
745 | | - | |
746 | | - | |
747 | | - | |
| 745 | + | |
748 | 746 | | |
749 | 747 | | |
750 | 748 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
113 | 113 | | |
114 | 114 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
25 | 27 | | |
26 | 28 | | |
27 | 29 | | |
| |||
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
42 | 65 | | |
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
46 | 69 | | |
47 | 70 | | |
48 | 71 | | |
| 72 | + | |
49 | 73 | | |
50 | 74 | | |
51 | 75 | | |
| |||
89 | 113 | | |
90 | 114 | | |
91 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
92 | 120 | | |
93 | 121 | | |
94 | 122 | | |
| |||
128 | 156 | | |
129 | 157 | | |
130 | 158 | | |
| 159 | + | |
| 160 | + | |
131 | 161 | | |
132 | 162 | | |
133 | 163 | | |
| |||
173 | 203 | | |
174 | 204 | | |
175 | 205 | | |
176 | | - | |
| 206 | + | |
177 | 207 | | |
178 | 208 | | |
179 | 209 | | |
| |||
0 commit comments