]> git.hungrycats.org Git - linux/commitdiff
net/route: enforce hoplimit max value
authorPaolo Abeni <pabeni@redhat.com>
Fri, 13 May 2016 16:33:41 +0000 (18:33 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Thu, 12 Oct 2017 14:28:12 +0000 (15:28 +0100)
[ Upstream commit 626abd59e51d4d8c6367e03aae252a8aa759ac78 ]

Currently, when creating or updating a route, no check is performed
in both ipv4 and ipv6 code to the hoplimit value.

The caller can i.e. set hoplimit to 256, and when such route will
 be used, packets will be sent with hoplimit/ttl equal to 0.

This commit adds checks for the RTAX_HOPLIMIT value, in both ipv4
ipv6 route code, substituting any value greater than 255 with 255.

This is consistent with what is currently done for ADVMSS and MTU
in the ipv4 code.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[bwh: Backported to 3.16: for IPv6, add the check to fib6_commit_metrics()]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
net/ipv4/fib_semantics.c
net/ipv6/ip6_fib.c

index 4a74ea85518fa9b2077d5fc5701a3ded8230b767..b77a181cd450a4aca115c18e6a1172a7e4a5aa66 100644 (file)
@@ -862,6 +862,8 @@ struct fib_info *fib_create_info(struct fib_config *cfg)
                                        val = 65535 - 40;
                                if (type == RTAX_MTU && val > 65535 - 15)
                                        val = 65535 - 15;
+                               if (type == RTAX_HOPLIMIT && val > 255)
+                                       val = 255;
                                fi->fib_metrics[type - 1] = val;
                        }
                }
index f5e99a85bf9296837d8b2875e59ef5939d1d589d..36aadaeb7f44eef3a12cf4b2a01e344cdd35e84f 100644 (file)
@@ -653,10 +653,14 @@ static int fib6_commit_metrics(struct dst_entry *dst,
                int type = nla_type(nla);
 
                if (type) {
+                       u32 val = nla_get_u32(nla);
+
                        if (type > RTAX_MAX)
                                return -EINVAL;
 
-                       mp[type - 1] = nla_get_u32(nla);
+                       if (type == RTAX_HOPLIMIT && val > 255)
+                               val = 255;
+                       mp[type - 1] = val;
                }
        }
        return 0;