ipv4: Check attribute length for RTA_FLOW in multipath route
authorDavid Ahern <dsahern@kernel.org>
Fri, 31 Dec 2021 00:36:32 +0000 (17:36 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Jan 2022 14:23:32 +0000 (15:23 +0100)
commit 664b9c4b7392ce723b013201843264bf95481ce5 upstream.

Make sure RTA_FLOW is at least 4B before using.

Fixes: 4e902c57417c ("[IPv4]: FIB configuration using struct fib_config")
Signed-off-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/ipv4/fib_semantics.c

index 96ee05207facd63d98b4b4b7ada5e4d25f3488c0..c462778cbccec76c3da76f8e1bc1568515ce70b2 100644 (file)
@@ -723,8 +723,13 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
                        }
 
                        nla = nla_find(attrs, attrlen, RTA_FLOW);
-                       if (nla)
+                       if (nla) {
+                               if (nla_len(nla) < sizeof(u32)) {
+                                       NL_SET_ERR_MSG(extack, "Invalid RTA_FLOW");
+                                       return -EINVAL;
+                               }
                                fib_cfg.fc_flow = nla_get_u32(nla);
+                       }
 
                        fib_cfg.fc_encap = nla_find(attrs, attrlen, RTA_ENCAP);
                        nla = nla_find(attrs, attrlen, RTA_ENCAP_TYPE);
@@ -955,8 +960,14 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
 
 #ifdef CONFIG_IP_ROUTE_CLASSID
                        nla = nla_find(attrs, attrlen, RTA_FLOW);
-                       if (nla && nla_get_u32(nla) != nh->nh_tclassid)
-                               return 1;
+                       if (nla) {
+                               if (nla_len(nla) < sizeof(u32)) {
+                                       NL_SET_ERR_MSG(extack, "Invalid RTA_FLOW");
+                                       return -EINVAL;
+                               }
+                               if (nla_get_u32(nla) != nh->nh_tclassid)
+                                       return 1;
+                       }
 #endif
                }