netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation
@ 2023-05-31 16:01 Xin Long
  2023-05-31 16:01 ` [PATCHv2 net 1/3] rtnetlink: call validate_linkmsg in rtnl_create_link Xin Long
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Xin Long @ 2023-05-31 16:01 UTC (permalink / raw)
  To: network dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Stephen Hemminger,
	Patrick McHardy, Thomas Graf, Alexander Duyck, Simon Horman

validate_linkmsg() was introduced to do linkmsg validation for existing
links. However, the new created links also need this linkmsg validation.

Add validate_linkmsg() check for link creating in Patch 1, and add more
tb checks into validate_linkmsg() in Patch 2 and 3.

v2:
- not improve the multiple times validating in patch 1, and will do it
  in net-next, as Jakub suggested.

Xin Long (3):
  rtnetlink: call validate_linkmsg in rtnl_create_link
  rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg
  rtnetlink: add the missing IFLA_GRO_ tb check in validate_linkmsg

 net/core/rtnetlink.c | 54 +++++++++++++++++++++++++++++++-------------
 1 file changed, 38 insertions(+), 16 deletions(-)

-- 
2.39.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCHv2 net 1/3] rtnetlink: call validate_linkmsg in rtnl_create_link
  2023-05-31 16:01 [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation Xin Long
@ 2023-05-31 16:01 ` Xin Long
  2023-05-31 16:01 ` [PATCHv2 net 2/3] rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg Xin Long
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Xin Long @ 2023-05-31 16:01 UTC (permalink / raw)
  To: network dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Stephen Hemminger,
	Patrick McHardy, Thomas Graf, Alexander Duyck, Simon Horman

validate_linkmsg() was introduced by commit 1840bb13c22f5b ("[RTNL]:
Validate hardware and broadcast address attribute for RTM_NEWLINK")
to validate tb[IFLA_ADDRESS/BROADCAST] for existing links. The same
check should also be done for newly created links.

This patch adds validate_linkmsg() call in rtnl_create_link(), to
avoid the invalid address set when creating some devices like:

  # ip link add dummy0 type dummy
  # ip link add link dummy0 name mac0 address 01:02 type macsec

Fixes: 0e06877c6fdb ("[RTNETLINK]: rtnl_link: allow specifying initial device address")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
---
 net/core/rtnetlink.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 653901a1bf75..824688edb722 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3285,6 +3285,7 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
 	struct net_device *dev;
 	unsigned int num_tx_queues = 1;
 	unsigned int num_rx_queues = 1;
+	int err;
 
 	if (tb[IFLA_NUM_TX_QUEUES])
 		num_tx_queues = nla_get_u32(tb[IFLA_NUM_TX_QUEUES]);
@@ -3320,13 +3321,18 @@ struct net_device *rtnl_create_link(struct net *net, const char *ifname,
 	if (!dev)
 		return ERR_PTR(-ENOMEM);
 
+	err = validate_linkmsg(dev, tb, extack);
+	if (err < 0) {
+		free_netdev(dev);
+		return ERR_PTR(err);
+	}
+
 	dev_net_set(dev, net);
 	dev->rtnl_link_ops = ops;
 	dev->rtnl_link_state = RTNL_LINK_INITIALIZING;
 
 	if (tb[IFLA_MTU]) {
 		u32 mtu = nla_get_u32(tb[IFLA_MTU]);
-		int err;
 
 		err = dev_validate_mtu(dev, mtu, extack);
 		if (err) {
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCHv2 net 2/3] rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg
  2023-05-31 16:01 [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation Xin Long
  2023-05-31 16:01 ` [PATCHv2 net 1/3] rtnetlink: call validate_linkmsg in rtnl_create_link Xin Long
@ 2023-05-31 16:01 ` Xin Long
  2023-05-31 16:01 ` [PATCHv2 net 3/3] rtnetlink: add the missing IFLA_GRO_ tb check in validate_linkmsg Xin Long
  2023-06-01 17:10 ` [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Xin Long @ 2023-05-31 16:01 UTC (permalink / raw)
  To: network dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Stephen Hemminger,
	Patrick McHardy, Thomas Graf, Alexander Duyck, Simon Horman

These IFLA_GSO_* tb check should also be done for the new created link,
otherwise, they can be set to a huge value when creating links:

  # ip link add dummy1 gso_max_size 4294967295 type dummy
  # ip -d link show dummy1
    dummy addrgenmode eui64 ... gso_max_size 4294967295

Fixes: 46e6b992c250 ("rtnetlink: allow GSO maximums to be set on device creation")
Fixes: 9eefedd58ae1 ("net: add gso_ipv4_max_size and gro_ipv4_max_size per device")
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
---
 net/core/rtnetlink.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 824688edb722..bc068a857219 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2385,6 +2385,25 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[],
 		if (tb[IFLA_BROADCAST] &&
 		    nla_len(tb[IFLA_BROADCAST]) < dev->addr_len)
 			return -EINVAL;
+
+		if (tb[IFLA_GSO_MAX_SIZE] &&
+		    nla_get_u32(tb[IFLA_GSO_MAX_SIZE]) > dev->tso_max_size) {
+			NL_SET_ERR_MSG(extack, "too big gso_max_size");
+			return -EINVAL;
+		}
+
+		if (tb[IFLA_GSO_MAX_SEGS] &&
+		    (nla_get_u32(tb[IFLA_GSO_MAX_SEGS]) > GSO_MAX_SEGS ||
+		     nla_get_u32(tb[IFLA_GSO_MAX_SEGS]) > dev->tso_max_segs)) {
+			NL_SET_ERR_MSG(extack, "too big gso_max_segs");
+			return -EINVAL;
+		}
+
+		if (tb[IFLA_GSO_IPV4_MAX_SIZE] &&
+		    nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]) > dev->tso_max_size) {
+			NL_SET_ERR_MSG(extack, "too big gso_ipv4_max_size");
+			return -EINVAL;
+		}
 	}
 
 	if (tb[IFLA_AF_SPEC]) {
@@ -2858,11 +2877,6 @@ static int do_setlink(const struct sk_buff *skb,
 	if (tb[IFLA_GSO_MAX_SIZE]) {
 		u32 max_size = nla_get_u32(tb[IFLA_GSO_MAX_SIZE]);
 
-		if (max_size > dev->tso_max_size) {
-			err = -EINVAL;
-			goto errout;
-		}
-
 		if (dev->gso_max_size ^ max_size) {
 			netif_set_gso_max_size(dev, max_size);
 			status |= DO_SETLINK_MODIFIED;
@@ -2872,11 +2886,6 @@ static int do_setlink(const struct sk_buff *skb,
 	if (tb[IFLA_GSO_MAX_SEGS]) {
 		u32 max_segs = nla_get_u32(tb[IFLA_GSO_MAX_SEGS]);
 
-		if (max_segs > GSO_MAX_SEGS || max_segs > dev->tso_max_segs) {
-			err = -EINVAL;
-			goto errout;
-		}
-
 		if (dev->gso_max_segs ^ max_segs) {
 			netif_set_gso_max_segs(dev, max_segs);
 			status |= DO_SETLINK_MODIFIED;
@@ -2895,11 +2904,6 @@ static int do_setlink(const struct sk_buff *skb,
 	if (tb[IFLA_GSO_IPV4_MAX_SIZE]) {
 		u32 max_size = nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]);
 
-		if (max_size > dev->tso_max_size) {
-			err = -EINVAL;
-			goto errout;
-		}
-
 		if (dev->gso_ipv4_max_size ^ max_size) {
 			netif_set_gso_ipv4_max_size(dev, max_size);
 			status |= DO_SETLINK_MODIFIED;
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCHv2 net 3/3] rtnetlink: add the missing IFLA_GRO_ tb check in validate_linkmsg
  2023-05-31 16:01 [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation Xin Long
  2023-05-31 16:01 ` [PATCHv2 net 1/3] rtnetlink: call validate_linkmsg in rtnl_create_link Xin Long
  2023-05-31 16:01 ` [PATCHv2 net 2/3] rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg Xin Long
@ 2023-05-31 16:01 ` Xin Long
  2023-06-01 17:10 ` [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: Xin Long @ 2023-05-31 16:01 UTC (permalink / raw)
  To: network dev
  Cc: davem, kuba, Eric Dumazet, Paolo Abeni, Stephen Hemminger,
	Patrick McHardy, Thomas Graf, Alexander Duyck, Simon Horman

This fixes the issue that dev gro_max_size and gso_ipv4_max_size
can be set to a huge value:

  # ip link add dummy1 type dummy
  # ip link set dummy1 gro_max_size 4294967295
  # ip -d link show dummy1
    dummy addrgenmode eui64 ... gro_max_size 4294967295

Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536")
Fixes: 9eefedd58ae1 ("net: add gso_ipv4_max_size and gro_ipv4_max_size per device")
Reported-by: Xiumei Mu <xmu@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
Reviewed-by: Simon Horman <simon.horman@corigine.com>
---
 net/core/rtnetlink.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index bc068a857219..41de3a2f29e1 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2399,11 +2399,23 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[],
 			return -EINVAL;
 		}
 
+		if (tb[IFLA_GRO_MAX_SIZE] &&
+		    nla_get_u32(tb[IFLA_GRO_MAX_SIZE]) > GRO_MAX_SIZE) {
+			NL_SET_ERR_MSG(extack, "too big gro_max_size");
+			return -EINVAL;
+		}
+
 		if (tb[IFLA_GSO_IPV4_MAX_SIZE] &&
 		    nla_get_u32(tb[IFLA_GSO_IPV4_MAX_SIZE]) > dev->tso_max_size) {
 			NL_SET_ERR_MSG(extack, "too big gso_ipv4_max_size");
 			return -EINVAL;
 		}
+
+		if (tb[IFLA_GRO_IPV4_MAX_SIZE] &&
+		    nla_get_u32(tb[IFLA_GRO_IPV4_MAX_SIZE]) > GRO_MAX_SIZE) {
+			NL_SET_ERR_MSG(extack, "too big gro_ipv4_max_size");
+			return -EINVAL;
+		}
 	}
 
 	if (tb[IFLA_AF_SPEC]) {
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation
  2023-05-31 16:01 [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation Xin Long
                   ` (2 preceding siblings ...)
  2023-05-31 16:01 ` [PATCHv2 net 3/3] rtnetlink: add the missing IFLA_GRO_ tb check in validate_linkmsg Xin Long
@ 2023-06-01 17:10 ` patchwork-bot+netdevbpf
  3 siblings, 0 replies; 5+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-06-01 17:10 UTC (permalink / raw)
  To: Xin Long
  Cc: netdev, davem, kuba, edumazet, pabeni, stephen, kaber, tgraf,
	alexanderduyck, simon.horman

Hello:

This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 31 May 2023 12:01:41 -0400 you wrote:
> validate_linkmsg() was introduced to do linkmsg validation for existing
> links. However, the new created links also need this linkmsg validation.
> 
> Add validate_linkmsg() check for link creating in Patch 1, and add more
> tb checks into validate_linkmsg() in Patch 2 and 3.
> 
> v2:
> - not improve the multiple times validating in patch 1, and will do it
>   in net-next, as Jakub suggested.
> 
> [...]

Here is the summary with links:
  - [PATCHv2,net,1/3] rtnetlink: call validate_linkmsg in rtnl_create_link
    https://git.kernel.org/netdev/net/c/b0ad3c179059
  - [PATCHv2,net,2/3] rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg
    https://git.kernel.org/netdev/net/c/fef5b228dd38
  - [PATCHv2,net,3/3] rtnetlink: add the missing IFLA_GRO_ tb check in validate_linkmsg
    https://git.kernel.org/netdev/net/c/65d6914e253f

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-06-01 17:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-31 16:01 [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation Xin Long
2023-05-31 16:01 ` [PATCHv2 net 1/3] rtnetlink: call validate_linkmsg in rtnl_create_link Xin Long
2023-05-31 16:01 ` [PATCHv2 net 2/3] rtnetlink: move IFLA_GSO_ tb check to validate_linkmsg Xin Long
2023-05-31 16:01 ` [PATCHv2 net 3/3] rtnetlink: add the missing IFLA_GRO_ tb check in validate_linkmsg Xin Long
2023-06-01 17:10 ` [PATCHv2 net 0/3] rtnetlink: a couple of fixes in linkmsg validation patchwork-bot+netdevbpf

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).