]> git.ipfire.org Git - thirdparty/ipset.git/commitdiff
64bit division isn't allowed on 32bit, replace it with shift
authorJozsef Kadlecsik <kadlec@netfilter.org>
Wed, 28 Jul 2021 14:06:46 +0000 (16:06 +0200)
committerJozsef Kadlecsik <kadlec@netfilter.org>
Wed, 28 Jul 2021 14:09:01 +0000 (16:09 +0200)
The number of hosts in a netblock must be a power of two,
so use shift instead of division.

Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
kernel/net/netfilter/ipset/ip_set_hash_ip.c

index 789b28a4ff9bcae86a56c23697af4852453eef25..baa5e14c70fda2d38ec1ec007e2895bae9126e87 100644 (file)
@@ -148,7 +148,8 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[],
 
        hosts = h->netmask == 32 ? 1 : 2 << (32 - h->netmask - 1);
 
-       if (((u64)ip_to - ip + 1)/hosts > IPSET_MAX_RANGE)
+       /* 64bit division is not allowed on 32bit */
+       if (((u64)ip_to - ip + 1) >> (32 - h->netmask) > IPSET_MAX_RANGE)
                return -ERANGE;
 
        if (retried) {