History

sock: make cookie generation global instead of per netns

Generating and retrieving socket cookies are a useful feature that is exposed to BPF for various program types through bpf_get_socket_cookie() helper. The fact that the cookie counter is per netns is quite a limitation for BPF in practice in particular for programs in host namespace that use socket cookies as part of a map lookup key since they will be causing socket cookie collisions e.g. when attached to BPF cgroup hooks or cls_bpf on tc egress in host namespace handling container traffic from veth or ipvlan devices with peer in different netns. Change the counter to be global instead. Socket cookie consumers must assume the value as opqaue in any case. Not every socket must have a cookie generated and knowledge of the counter value itself does not provide much value either way hence conversion to global is fine.

Daniel Borkmann committed 7 years ago

Commit cd48bdd1 parent 7bac7623 files · +4 −4Browse files

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

Unified · Split

include/uapi/linux/bpf.h+2−2
@@ -1466,8 +1466,8 @@ union bpf_attr { · 1465 unmodified lines
14661466 * If no cookie has been set yet, generate a new cookie. Once
14671467 * generated, the socket cookie remains stable for the life of the
14681468 * socket. This helper can be useful for monitoring per socket
1469− * networking traffic statistics as it provides a unique socket
1470− * identifier per namespace.
1469+ * networking traffic statistics as it provides a global socket
1470+ * identifier that can be assumed unique.
14711471 * Return
14721472 * A 8-byte long non-decreasing number on success, or 0 if the
14731473 * socket field is missing inside *skb*.