]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: Add struct sockaddr_unsized for sockaddr of unknown length
authorKees Cook <kees@kernel.org>
Tue, 4 Nov 2025 00:26:09 +0000 (16:26 -0800)
committerJakub Kicinski <kuba@kernel.org>
Wed, 5 Nov 2025 03:10:32 +0000 (19:10 -0800)
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_unsized {
u16 sa_data_len;
u16 sa_family;
u8  sa_data[] __counted_by(sa_data_len);
};

Signed-off-by: Kees Cook <kees@kernel.org>
Link: https://patch.msgid.link/20251104002617.2752303-1-kees@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/linux/socket.h

index 3b262487ec06032b885cad017ec828cc6a4142db..7b1a01be29da8cfddac7d110d91fc3121ca78f94 100644 (file)
@@ -40,6 +40,23 @@ struct sockaddr {
        };
 };
 
+/**
+ * struct sockaddr_unsized - Unspecified size sockaddr for callbacks
+ * @sa_family: Address family (AF_UNIX, AF_INET, AF_INET6, etc.)
+ * @sa_data: Flexible array for address data
+ *
+ * This structure is designed for callback interfaces where the
+ * total size is known via the sockaddr_len parameter. Unlike struct
+ * sockaddr which has a fixed 14-byte sa_data limit or struct
+ * sockaddr_storage which has a fixed 128-byte sa_data limit, this
+ * structure can accommodate addresses of any size, but must be used
+ * carefully.
+ */
+struct sockaddr_unsized {
+       __kernel_sa_family_t    sa_family;      /* address family, AF_xxx */
+       char                    sa_data[];      /* flexible address data */
+};
+
 struct linger {
        int             l_onoff;        /* Linger active                */
        int             l_linger;       /* How long to linger for       */