[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250723231921.2293685-1-kees@kernel.org>
Date: Wed, 23 Jul 2025 16:19:08 -0700
From: Kees Cook <kees@...nel.org>
To: Jakub Kicinski <kuba@...nel.org>
Cc: Kees Cook <kees@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Simon Horman <horms@...nel.org>,
Kuniyuki Iwashima <kuniyu@...gle.com>,
Willem de Bruijn <willemb@...gle.com>,
netdev@...r.kernel.org
Subject: [PATCH 1/6 net-next] net: uapi: Add __kernel_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. 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.
I added this to UAPI in the hopes that it could also be used for any
future "arbitrarily sized" sockaddr needs. But it may be better to
use a different UAPI with an explicit size member:
struct sockaddr_unspec {
u16 sa_data_len;
u16 sa_family;
u8 sa_data[] __counted_by(sa_data_len);
};
Signed-off-by: Kees Cook <kees@...nel.org>
---
include/linux/net.h | 2 ++
include/uapi/linux/socket.h | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/include/linux/net.h b/include/linux/net.h
index ec09620f40f7..77de581bdd56 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -26,6 +26,8 @@
#include <uapi/linux/net.h>
+#define sockaddr_unspec __kernel_sockaddr_unspec
+
struct poll_table_struct;
struct pipe_inode_info;
struct inode;
diff --git a/include/uapi/linux/socket.h b/include/uapi/linux/socket.h
index d3fcd3b5ec53..2667dd64fd0f 100644
--- a/include/uapi/linux/socket.h
+++ b/include/uapi/linux/socket.h
@@ -26,6 +26,21 @@ struct __kernel_sockaddr_storage {
};
};
+/**
+ * struct __kernel_sockaddr_unspec - 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, this structure
+ * can accommodate addresses of any size.
+ */
+struct __kernel_sockaddr_unspec {
+ __kernel_sa_family_t sa_family; /* address family, AF_xxx */
+ char sa_data[]; /* flexible address data */
+};
+
#define SOCK_SNDBUF_LOCK 1
#define SOCK_RCVBUF_LOCK 2
--
2.34.1
Powered by blists - more mailing lists