diff mbox series

[net] rtnetlink: not allow dev gro_max_size to exceed GRO_MAX_SIZE

Message ID 25a7b1b138e5ad3c926afce8cd4e08d8b7ef3af6.1684516568.git.lucien.xin@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] rtnetlink: not allow dev gro_max_size to exceed GRO_MAX_SIZE | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 10 this patch: 10
netdev/cc_maintainers warning 3 maintainers not CCed: razor@blackwall.org idosch@nvidia.com liuhangbin@gmail.com
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 10 this patch: 10
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 22 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Xin Long May 19, 2023, 5:16 p.m. UTC
In commit 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536"),
it limited GRO_MAX_SIZE to (8 * 65535) to avoid overflows, but also
deleted the check of GRO_MAX_SIZE when setting the dev gro_max_size.

Currently, dev gro_max_size can be set up to U32_MAX (0xFFFFFFFF),
and GRO_MAX_SIZE is not even used anywhere.

This patch brings back the GRO_MAX_SIZE check when setting dev
gro_max_size/gro_ipv4_max_size by users.

Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536")
Reported-by: Xiumei Mu <xmu@redhat.com>
Signed-off-by: Xin Long <lucien.xin@gmail.com>
---
 net/core/rtnetlink.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Stephen Hemminger May 19, 2023, 8:43 p.m. UTC | #1
On Fri, 19 May 2023 13:16:08 -0400
Xin Long <lucien.xin@gmail.com> wrote:

> In commit 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536"),
> it limited GRO_MAX_SIZE to (8 * 65535) to avoid overflows, but also
> deleted the check of GRO_MAX_SIZE when setting the dev gro_max_size.
> 
> Currently, dev gro_max_size can be set up to U32_MAX (0xFFFFFFFF),
> and GRO_MAX_SIZE is not even used anywhere.
> 
> This patch brings back the GRO_MAX_SIZE check when setting dev
> gro_max_size/gro_ipv4_max_size by users.
> 
> Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536")
> Reported-by: Xiumei Mu <xmu@redhat.com>
> Signed-off-by: Xin Long <lucien.xin@gmail.com>
> ---
>  net/core/rtnetlink.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 653901a1bf75..59b24b184cb0 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -2886,6 +2886,11 @@ static int do_setlink(const struct sk_buff *skb,
>  	if (tb[IFLA_GRO_MAX_SIZE]) {
>  		u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_MAX_SIZE]);
>  
> +		if (gro_max_size > GRO_MAX_SIZE) {
> +			err = -EINVAL;
> +			goto errout;
> +		}
> +

Please add extack messages so the error can be reported better.
Eric Dumazet May 21, 2023, 5:25 p.m. UTC | #2
On Fri, May 19, 2023 at 10:43 PM Stephen Hemminger
<stephen@networkplumber.org> wrote:
>
> On Fri, 19 May 2023 13:16:08 -0400
> Xin Long <lucien.xin@gmail.com> wrote:
>
> > In commit 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536"),
> > it limited GRO_MAX_SIZE to (8 * 65535) to avoid overflows, but also
> > deleted the check of GRO_MAX_SIZE when setting the dev gro_max_size.
> >
> > Currently, dev gro_max_size can be set up to U32_MAX (0xFFFFFFFF),
> > and GRO_MAX_SIZE is not even used anywhere.
> >
> > This patch brings back the GRO_MAX_SIZE check when setting dev
> > gro_max_size/gro_ipv4_max_size by users.
> >
> > Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536")
> > Reported-by: Xiumei Mu <xmu@redhat.com>
> > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > ---
> >  net/core/rtnetlink.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> >
> > diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> > index 653901a1bf75..59b24b184cb0 100644
> > --- a/net/core/rtnetlink.c
> > +++ b/net/core/rtnetlink.c
> > @@ -2886,6 +2886,11 @@ static int do_setlink(const struct sk_buff *skb,
> >       if (tb[IFLA_GRO_MAX_SIZE]) {
> >               u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_MAX_SIZE]);
> >
> > +             if (gro_max_size > GRO_MAX_SIZE) {
> > +                     err = -EINVAL;
> > +                     goto errout;
> > +             }
> > +
>
> Please add extack messages so the error can be reported better.

Also, what is the reason for not changing rtnl_create_link() ?
Xin Long May 21, 2023, 11:27 p.m. UTC | #3
On Sun, May 21, 2023 at 1:25 PM Eric Dumazet <edumazet@google.com> wrote:
>
> On Fri, May 19, 2023 at 10:43 PM Stephen Hemminger
> <stephen@networkplumber.org> wrote:
> >
> > On Fri, 19 May 2023 13:16:08 -0400
> > Xin Long <lucien.xin@gmail.com> wrote:
> >
> > > In commit 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536"),
> > > it limited GRO_MAX_SIZE to (8 * 65535) to avoid overflows, but also
> > > deleted the check of GRO_MAX_SIZE when setting the dev gro_max_size.
> > >
> > > Currently, dev gro_max_size can be set up to U32_MAX (0xFFFFFFFF),
> > > and GRO_MAX_SIZE is not even used anywhere.
> > >
> > > This patch brings back the GRO_MAX_SIZE check when setting dev
> > > gro_max_size/gro_ipv4_max_size by users.
> > >
> > > Fixes: 0fe79f28bfaf ("net: allow gro_max_size to exceed 65536")
> > > Reported-by: Xiumei Mu <xmu@redhat.com>
> > > Signed-off-by: Xin Long <lucien.xin@gmail.com>
> > > ---
> > >  net/core/rtnetlink.c | 10 ++++++++++
> > >  1 file changed, 10 insertions(+)
> > >
> > > diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> > > index 653901a1bf75..59b24b184cb0 100644
> > > --- a/net/core/rtnetlink.c
> > > +++ b/net/core/rtnetlink.c
> > > @@ -2886,6 +2886,11 @@ static int do_setlink(const struct sk_buff *skb,
> > >       if (tb[IFLA_GRO_MAX_SIZE]) {
> > >               u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_MAX_SIZE]);
> > >
> > > +             if (gro_max_size > GRO_MAX_SIZE) {
> > > +                     err = -EINVAL;
> > > +                     goto errout;
> > > +             }
> > > +
> >
> > Please add extack messages so the error can be reported better.
>
> Also, what is the reason for not changing rtnl_create_link() ?
Good catch!

Not only GRO_MAX_SIZE, all tb[IFLA_GSO/GRO_*] checks should be moved
to validate_linkmsg(), with extra added for sure. Otherwise:

# ip link add dummy1 gso_max_size 4294967295 gro_max_size 4294967295
gso_ipv4_max_size 4294967295 gro_ipv4_max_size 4294967295 type dummy
# ip -d link show dummy1
6: dummy1: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN mode
DEFAULT group default qlen 1000
    link/ether ba:cd:f2:8d:84:9b brd ff:ff:ff:ff:ff:ff promiscuity 0
allmulti 0 minmtu 0 maxmtu 0
    dummy addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size
4294967295 gso_max_segs 65535 tso_max_size 65536 tso_max_segs 65535
gro_max_size 4294967295 gso_ipv4_max_size 4294967295 gro_ipv4_max_size
4294967295

Also, I might move validate_linkmsg() from do_setlink() to its caller,
to avoid validate_linkmsg() being called twice in the path of:
__rtnl_newlink() -> do_setlink().

Thanks.
diff mbox series

Patch

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 653901a1bf75..59b24b184cb0 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -2886,6 +2886,11 @@  static int do_setlink(const struct sk_buff *skb,
 	if (tb[IFLA_GRO_MAX_SIZE]) {
 		u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_MAX_SIZE]);
 
+		if (gro_max_size > GRO_MAX_SIZE) {
+			err = -EINVAL;
+			goto errout;
+		}
+
 		if (dev->gro_max_size ^ gro_max_size) {
 			netif_set_gro_max_size(dev, gro_max_size);
 			status |= DO_SETLINK_MODIFIED;
@@ -2909,6 +2914,11 @@  static int do_setlink(const struct sk_buff *skb,
 	if (tb[IFLA_GRO_IPV4_MAX_SIZE]) {
 		u32 gro_max_size = nla_get_u32(tb[IFLA_GRO_IPV4_MAX_SIZE]);
 
+		if (gro_max_size > GRO_MAX_SIZE) {
+			err = -EINVAL;
+			goto errout;
+		}
+
 		if (dev->gro_ipv4_max_size ^ gro_max_size) {
 			netif_set_gro_ipv4_max_size(dev, gro_max_size);
 			status |= DO_SETLINK_MODIFIED;