]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip/ipnexthop: fix unsigned overflow in parse_nh_group_type_res()
authorMaxim Petrov <mmrmaximuzz@gmail.com>
Wed, 17 Nov 2021 19:11:24 +0000 (22:11 +0300)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 18 Nov 2021 23:01:48 +0000 (15:01 -0800)
0UL has type 'unsigned long' which is likely to be 64bit on modern machines. At
the same time, the '{idle,unbalanced}_timer' variables are declared as u32, so
these variables cannot be greater than '~0UL / 100' when 'unsigned long' is 64
bits. In such condition it is still possible to pass the check but get the
overflow later when the timers are multiplied by 100 in 'addattr32'.

Fix the possible overflow by changing '~0UL' to 'UINT32_MAX'.

Fixes: 91676718228b ("nexthop: Add support for resilient nexthop groups")
Signed-off-by: Maxim Petrov <mmrmaximuzz@gmail.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/ipnexthop.c

index 83a5540e771cf2fecca6f9ee8530ef9ba394135d..2f448449ea1d14817840121b4678d7f80c31824e 100644 (file)
@@ -6,6 +6,7 @@
  */
 
 #include <linux/nexthop.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <string.h>
 #include <rt_names.h>
@@ -840,7 +841,7 @@ static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp,
 
                        NEXT_ARG();
                        if (get_unsigned(&idle_timer, *argv, 0) ||
-                           idle_timer >= ~0UL / 100)
+                           idle_timer >= UINT32_MAX / 100)
                                invarg("invalid idle timer value", *argv);
 
                        addattr32(n, maxlen, NHA_RES_GROUP_IDLE_TIMER,
@@ -850,7 +851,7 @@ static void parse_nh_group_type_res(struct nlmsghdr *n, int maxlen, int *argcp,
 
                        NEXT_ARG();
                        if (get_unsigned(&unbalanced_timer, *argv, 0) ||
-                           unbalanced_timer >= ~0UL / 100)
+                           unbalanced_timer >= UINT32_MAX / 100)
                                invarg("invalid unbalanced timer value", *argv);
 
                        addattr32(n, maxlen, NHA_RES_GROUP_UNBALANCED_TIMER,