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
22682268 };
22692269 __u8 tunnel_tos;
22702270 __u8 tunnel_ttl;
2271− __u16 tunnel_ext;
2271+ __u16 tunnel_ext; /* Padding, future use. */
22722272 __u32 tunnel_label;
22732273 };
22742274
@@ -2279,6 +2279,7 @@ struct bpf_xfrm_state { · 4 unmodified lines
22792279 __u32 reqid;
22802280 __u32 spi; /* Stored in network byte order */
22812281 __u16 family;
2282+ __u16 ext; /* Padding, future use. */
22822283 union {
22832284 __u32 remote_ipv4; /* Stored in network byte order */
22842285 __u32 remote_ipv6[4]; /* Stored in network byte order */