netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org, kuba@kernel.org,
	pabeni@redhat.com, edumazet@google.com,
	mathew.j.martineau@linux.intel.com, matthieu.baerts@tessares.net,
	mptcp@lists.linux.dev
Subject: [PATCH net,v2] uapi: linux: restore IPPROTO_MAX to 256 and add IPPROTO_UAPI_MAX
Date: Thu,  6 Apr 2023 11:25:58 +0200	[thread overview]
Message-ID: <20230406092558.459491-1-pablo@netfilter.org> (raw)

IPPROTO_MAX used to be 256, but with the introduction of IPPROTO_MPTCP
definition, IPPROTO_MAX was bumped to 263.

IPPROTO_MPTCP definition is used for the socket interface from
userspace (ie. uAPI). It is never used in the layer 4 protocol field of
IP headers.

IPPROTO_* definitions are used anywhere in the kernel as well as in
userspace to set the layer 4 protocol field in IP headers as well as
for uAPI.

At least in Netfilter, there is code in userspace that relies on
IPPROTO_MAX (not inclusive) to check for the maximum layer 4 protocol.

This patch restores IPPROTO_MAX to 256 for the maximum protocol number
in the IP headers, and it adds a new IPPROTO_UAPI_MAX for the maximum
protocol number for uAPI.

Update kernel code to use IPPROTO_UAPI_MAX for inet_diag (mptcp
registers one for this) and the inet{4,6}_create() IP socket API.

Fixes: faf391c3826c ("tcp: Define IPPROTO_MPTCP")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v2: Add IPPROTO_UAPI_MAX so mptcp socket API does not break.

 include/uapi/linux/in.h | 3 ++-
 net/ipv4/af_inet.c      | 2 +-
 net/ipv4/inet_diag.c    | 8 ++++----
 net/ipv6/af_inet6.c     | 2 +-
 4 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/include/uapi/linux/in.h b/include/uapi/linux/in.h
index 4b7f2df66b99..58ca09438bf0 100644
--- a/include/uapi/linux/in.h
+++ b/include/uapi/linux/in.h
@@ -80,10 +80,11 @@ enum {
   IPPROTO_ETHERNET = 143,	/* Ethernet-within-IPv6 Encapsulation	*/
 #define IPPROTO_ETHERNET	IPPROTO_ETHERNET
   IPPROTO_RAW = 255,		/* Raw IP packets			*/
+  IPPROTO_MAX,
 #define IPPROTO_RAW		IPPROTO_RAW
   IPPROTO_MPTCP = 262,		/* Multipath TCP connection		*/
 #define IPPROTO_MPTCP		IPPROTO_MPTCP
-  IPPROTO_MAX
+  IPPROTO_UAPI_MAX
 };
 #endif
 
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 8db6747f892f..4a9061da8983 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -252,7 +252,7 @@ static int inet_create(struct net *net, struct socket *sock, int protocol,
 	int try_loading_module = 0;
 	int err;
 
-	if (protocol < 0 || protocol >= IPPROTO_MAX)
+	if (protocol < 0 || protocol >= IPPROTO_UAPI_MAX)
 		return -EINVAL;
 
 	sock->state = SS_UNCONNECTED;
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index b812eb36f0e3..0723bef44827 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -52,7 +52,7 @@ static DEFINE_MUTEX(inet_diag_table_mutex);
 
 static const struct inet_diag_handler *inet_diag_lock_handler(int proto)
 {
-	if (proto < 0 || proto >= IPPROTO_MAX) {
+	if (proto < 0 || proto >= IPPROTO_UAPI_MAX) {
 		mutex_lock(&inet_diag_table_mutex);
 		return ERR_PTR(-ENOENT);
 	}
@@ -1413,7 +1413,7 @@ int inet_diag_register(const struct inet_diag_handler *h)
 	const __u16 type = h->idiag_type;
 	int err = -EINVAL;
 
-	if (type >= IPPROTO_MAX)
+	if (type >= IPPROTO_UAPI_MAX)
 		goto out;
 
 	mutex_lock(&inet_diag_table_mutex);
@@ -1432,7 +1432,7 @@ void inet_diag_unregister(const struct inet_diag_handler *h)
 {
 	const __u16 type = h->idiag_type;
 
-	if (type >= IPPROTO_MAX)
+	if (type >= IPPROTO_UAPI_MAX)
 		return;
 
 	mutex_lock(&inet_diag_table_mutex);
@@ -1443,7 +1443,7 @@ EXPORT_SYMBOL_GPL(inet_diag_unregister);
 
 static int __init inet_diag_init(void)
 {
-	const int inet_diag_table_size = (IPPROTO_MAX *
+	const int inet_diag_table_size = (IPPROTO_UAPI_MAX *
 					  sizeof(struct inet_diag_handler *));
 	int err = -ENOMEM;
 
diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
index 38689bedfce7..64d5c803f070 100644
--- a/net/ipv6/af_inet6.c
+++ b/net/ipv6/af_inet6.c
@@ -128,7 +128,7 @@ static int inet6_create(struct net *net, struct socket *sock, int protocol,
 	int try_loading_module = 0;
 	int err;
 
-	if (protocol < 0 || protocol >= IPPROTO_MAX)
+	if (protocol < 0 || protocol >= IPPROTO_UAPI_MAX)
 		return -EINVAL;
 
 	/* Look for the requested type/protocol pair. */
-- 
2.30.2


             reply	other threads:[~2023-04-06  9:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06  9:25 Pablo Neira Ayuso [this message]
2023-04-06 10:45 ` [PATCH net,v2] uapi: linux: restore IPPROTO_MAX to 256 and add IPPROTO_UAPI_MAX Matthieu Baerts
2023-04-12 14:21   ` Jakub Kicinski
2023-04-12 15:22     ` Matthieu Baerts
2023-04-12 16:04       ` Pablo Neira Ayuso
2023-04-12 16:35         ` Matthieu Baerts
2023-04-12 19:37           ` Jakub Kicinski
2023-04-12 22:22             ` Pablo Neira Ayuso
2023-04-12 16:14       ` Jan Engelhardt
2023-04-12 16:44         ` Matthieu Baerts
2023-04-12 18:24           ` Jan Engelhardt
2023-04-12 14:18 ` Jakub Kicinski

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=20230406092558.459491-1-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=mathew.j.martineau@linux.intel.com \
    --cc=matthieu.baerts@tessares.net \
    --cc=mptcp@lists.linux.dev \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pabeni@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).