History

bpf: make sure to clear unused fields in tunnel/xfrm state fetch

Since the remaining bits are not filled in struct bpf_tunnel_key resp. struct bpf_xfrm_state and originate from uninitialized stack space, we should make sure to clear them before handing control back to the program. Also add a padding element to struct bpf_xfrm_state for future use similar as we have in struct bpf_tunnel_key and clear it as well. struct bpf_xfrm_state { __u32 reqid; /* 0 4 */ __u32 spi; /* 4 4 */ __u16 family; /* 8 2 */ /* XXX 2 bytes hole, try to pack */ union { __u32 remote_ipv4; /* 4 */ __u32 remote_ipv6[4]; /* 16 */ }; /* 12 16 */ /* size: 28, cachelines: 1, members: 4 */ /* sum members: 26, holes: 1, sum holes: 2 */ /* last cacheline: 28 bytes */ };

Daniel Borkmann committed 8 years ago

Commit 1fbc2e01 parent cb20b082 files · +8 −1Browse files

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

Unified · Split

include/uapi/linux/bpf.h+2−1
@@ -2268,7 +2268,7 @@ struct bpf_tunnel_key { · 2267 unmodified lines
2268 };2268 };
2269 __u8 tunnel_tos;2269 __u8 tunnel_tos;
2270 __u8 tunnel_ttl;2270 __u8 tunnel_ttl;
2271 __u16 tunnel_ext;2271 __u16 tunnel_ext; /* Padding, future use. */
2272 __u32 tunnel_label;2272 __u32 tunnel_label;
2273};2273};
2274 2274
@@ -2279,6 +2279,7 @@ struct bpf_xfrm_state { · 4 unmodified lines
2279 __u32 reqid;2279 __u32 reqid;
2280 __u32 spi; /* Stored in network byte order */2280 __u32 spi; /* Stored in network byte order */
2281 __u16 family;2281 __u16 family;
2282 __u16 ext; /* Padding, future use. */
2282 union {2283 union {
2283 __u32 remote_ipv4; /* Stored in network byte order */2284 __u32 remote_ipv4; /* Stored in network byte order */
2284 __u32 remote_ipv6[4]; /* Stored in network byte order */2285 __u32 remote_ipv6[4]; /* Stored in network byte order */