Skip to content

Commit b5c3afc

Browse files
keesKernel Patches Daemon
authored andcommitted
net: Add struct sockaddr_unspec for sockaddr of unknown length
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]>
1 parent ee5122f commit b5c3afc

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

include/linux/socket.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,23 @@ struct sockaddr {
4040
};
4141
};
4242

43+
/**
44+
* struct sockaddr_unspec - Unspecified size sockaddr for callbacks
45+
* @sa_family: Address family (AF_UNIX, AF_INET, AF_INET6, etc.)
46+
* @sa_data: Flexible array for address data
47+
*
48+
* This structure is designed for callback interfaces where the
49+
* total size is known via the sockaddr_len parameter. Unlike struct
50+
* sockaddr which has a fixed 14-byte sa_data limit or struct
51+
* sockaddr_storage which has a fixed 128-byte sa_data limit, this
52+
* structure can accommodate addresses of any size, but must be used
53+
* carefully.
54+
*/
55+
struct sockaddr_unspec {
56+
__kernel_sa_family_t sa_family; /* address family, AF_xxx */
57+
char sa_data[]; /* flexible address data */
58+
};
59+
4360
struct linger {
4461
int l_onoff; /* Linger active */
4562
int l_linger; /* How long to linger for */

0 commit comments

Comments
 (0)