All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kees Cook <kees@kernel.org>
To: Jakub Kicinski <kuba@kernel.org>
Cc: Kees Cook <kees@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Willem de Bruijn <willemb@google.com>,
	netdev@vger.kernel.org
Subject: [PATCH 1/6 net-next] net: uapi: Add __kernel_sockaddr_unspec for sockaddr of unknown length
Date: Wed, 23 Jul 2025 16:19:08 -0700	[thread overview]
Message-ID: <20250723231921.2293685-1-kees@kernel.org> (raw)
In-Reply-To: <20250723230354.work.571-kees@kernel.org>

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@kernel.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


  reply	other threads:[~2025-07-23 23:19 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-23 23:19 [PATCH 0/6 net-next] net: Introduce struct sockaddr_unspec Kees Cook
2025-07-23 23:19 ` Kees Cook [this message]
2025-07-24 21:40   ` [PATCH 1/6 net-next] net: uapi: Add __kernel_sockaddr_unspec for sockaddr of unknown length Jakub Kicinski
2025-07-24 22:28     ` Kees Cook
2025-07-23 23:19 ` [PATCH 2/6 net-next] net/l2tp: Add missing sa_family validation in pppol2tp_sockaddr_get_info Kees Cook
2025-07-23 23:19 ` [PATCH 3/6 net-next] net: Convert proto_ops bind() callbacks to use sockaddr_unspec Kees Cook
2025-07-24 11:29   ` kernel test robot
2025-07-24 13:31     ` Kees Cook
2025-07-24 13:02   ` kernel test robot
2025-07-23 23:19 ` [PATCH 4/6 net-next] net: Convert proto_ops connect() " Kees Cook
2025-07-24 12:00   ` kernel test robot
2025-07-23 23:19 ` [PATCH 5/6 net-next] net: Remove struct sockaddr from net.h Kees Cook
2025-07-23 23:19 ` [PATCH 6/6 net-next] net: Convert proto callbacks from sockaddr to sockaddr_unspec Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250723231921.2293685-1-kees@kernel.org \
    --to=kees@kernel.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=willemb@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.