-
Notifications
You must be signed in to change notification settings - Fork 5
net: Introduce struct sockaddr_unspec #6187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bpf-next_base
Are you sure you want to change the base?
net: Introduce struct sockaddr_unspec #6187
Conversation
|
Upstream branch: 04a8995 |
2b803ce to
9b33bf7
Compare
|
Upstream branch: 04a8995 |
50e3c6d to
93619a1
Compare
9b33bf7 to
33b4c7f
Compare
|
Upstream branch: 96d31df |
93619a1 to
1dc282c
Compare
33b4c7f to
e698de7
Compare
|
Upstream branch: e758657 |
1dc282c to
77e0ce4
Compare
e698de7 to
ee5122f
Compare
|
Upstream branch: e758657 |
77e0ce4 to
2075ce0
Compare
ee5122f to
d5592b9
Compare
Add flexible sockaddr structure to support addresses longer than the
traditional 14-byte struct sockaddr::sa_data limitation without
requiring the full 128-byte sa_data of struct sockaddr_storage. This
allows the network APIs to pass around a pointer to an object that
isn't lying to the compiler about how big it is, but must be accompanied
by its actual size as an additional parameter.
It's possible we may way to migrate to including the size with the
struct in the future, e.g.:
struct sockaddr_unspec {
u16 sa_data_len;
u16 sa_family;
u8 sa_data[] __counted_by(sa_data_len);
};
Signed-off-by: Kees Cook <[email protected]>
While reviewing the struct proto_ops connect() and bind() callback implementations, I noticed that there doesn't appear to be any validation that AF_PPPOX sockaddr structures actually have sa_family set to AF_PPPOX. The pppol2tp_sockaddr_get_info() checks only look at the sizes. I don't see any way that this might actually cause problems as specific info fields are being populated, for which the existing size checks are correct, but it stood out as a missing address family check. Add the check and return -EAFNOSUPPORT on mismatch. Signed-off-by: Kees Cook <[email protected]>
Update all struct proto_ops bind() callback function prototypes from "struct sockaddr *" to "struct sockaddr_unspec *" to avoid lying to the compiler about object sizes. Calls into struct proto handlers gain casts that will be removed in the struct proto conversion patch. No binary changes expected. Signed-off-by: Kees Cook <[email protected]>
Update all struct proto_ops connect() callback function prototypes from "struct sockaddr *" to "struct sockaddr_unspec *" to avoid lying to the compiler about object sizes. Calls into struct proto handlers gain casts that will be removed in the struct proto conversion patch. No binary changes expected. Signed-off-by: Kees Cook <[email protected]>
Now that struct sockaddr is no longer used by net.h, remove it. Signed-off-by: Kees Cook <[email protected]>
|
Upstream branch: e758657 |
Convert struct proto pre_connect(), connect(), bind(), and bind_add() callback function prototypes from struct sockaddr to struct sockaddr_unspec. This does not change per-implementation use of sockaddr for passing around an arbitrarily sized sockaddr struct. Those will be addressed in future patches. Additionally removes the no longer referenced struct sockaddr from include/net/inet_common.h. No binary changes expected. Signed-off-by: Kees Cook <[email protected]>
Update BPF cgroup sockaddr filtering infrastructure to use sockaddr_unspec consistently throughout the call chain, removing redundant explicit casts from callers. Signed-off-by: Kees Cook <[email protected]>
Change struct bpf_sock_addr_kern to use sockaddr_unspec for the "uaddr" field instead of sockaddr. This improves type safety in the BPF cgroup socket address filtering code. The casting in __cgroup_bpf_run_filter_sock_addr() is updated to match the new type, removing an unnecessary cast in the initialization and updating the conditional assignment to use the appropriate sockaddr_unspec cast. Signed-off-by: Kees Cook <[email protected]>
Revert struct sockaddr from flexible array to fixed 14-byte "sa_data", solves over 36,000 -Wflex-array-member-not-at-end warnings, since struct sockaddr is embedded within many network structs. With socket/proto sockaddr-based internal APIs switched to use struct sockaddr_unspec, there should be no more uses of struct sockaddr that depend on reading beyond the end of struct sockaddr::sa_data that might trigger bounds checking. Comparing an x86_64 "allyesconfig" vmlinux build before and after this patch showed no new "ud1" instructions from CONFIG_UBSAN_BOUNDS nor any explicit "field-spanning" memcpy CONFIG_FORTIFY_SOURCE instrumentations. Cc: "Gustavo A. R. Silva" <[email protected]> Signed-off-by: Kees Cook <[email protected]>
2075ce0 to
74df391
Compare
75ba762 to
385f65b
Compare
Pull request for series with
subject: net: Introduce struct sockaddr_unspec
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1013767