Skip to content

Commit b9fed74

Browse files
author
Jozsef Kadlecsik
committed
netfilter: ipset: Check and reject crazy /0 input parameters
bitmap:ip and bitmap:ip,mac type did not reject such a crazy range when created and using such a set results in a kernel crash. The hash types just silently ignored such parameters. Reject invalid /0 input parameters explicitely. Signed-off-by: Jozsef Kadlecsik <[email protected]>
1 parent 6e27c9b commit b9fed74

File tree

6 files changed

+13
-10
lines changed

6 files changed

+13
-10
lines changed

net/netfilter/ipset/ip_set_bitmap_ip.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ bitmap_ip_uadt(struct ip_set *set, struct nlattr *tb[],
284284
} else if (tb[IPSET_ATTR_CIDR]) {
285285
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
286286

287-
if (cidr > 32)
287+
if (!cidr || cidr > 32)
288288
return -IPSET_ERR_INVALID_CIDR;
289289
ip_set_mask_from_to(ip, ip_to, cidr);
290290
} else
@@ -454,7 +454,8 @@ static int
454454
bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags)
455455
{
456456
struct bitmap_ip *map;
457-
u32 first_ip, last_ip, hosts, elements;
457+
u32 first_ip, last_ip, hosts;
458+
u64 elements;
458459
u8 netmask = 32;
459460
int ret;
460461

@@ -497,7 +498,7 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags)
497498

498499
if (netmask == 32) {
499500
hosts = 1;
500-
elements = last_ip - first_ip + 1;
501+
elements = (u64)last_ip - first_ip + 1;
501502
} else {
502503
u8 mask_bits;
503504
u32 mask;
@@ -515,7 +516,8 @@ bitmap_ip_create(struct ip_set *set, struct nlattr *tb[], u32 flags)
515516
if (elements > IPSET_BITMAP_MAX_RANGE + 1)
516517
return -IPSET_ERR_BITMAP_RANGE_SIZE;
517518

518-
pr_debug("hosts %u, elements %u\n", hosts, elements);
519+
pr_debug("hosts %u, elements %llu\n",
520+
hosts, (unsigned long long)elements);
519521

520522
map = kzalloc(sizeof(*map), GFP_KERNEL);
521523
if (!map)

net/netfilter/ipset/ip_set_bitmap_ipmac.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ static int
557557
bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[],
558558
u32 flags)
559559
{
560-
u32 first_ip, last_ip, elements;
560+
u32 first_ip, last_ip;
561+
u64 elements;
561562
struct bitmap_ipmac *map;
562563
int ret;
563564

@@ -588,7 +589,7 @@ bitmap_ipmac_create(struct ip_set *set, struct nlattr *tb[],
588589
} else
589590
return -IPSET_ERR_PROTOCOL;
590591

591-
elements = last_ip - first_ip + 1;
592+
elements = (u64)last_ip - first_ip + 1;
592593

593594
if (elements > IPSET_BITMAP_MAX_RANGE + 1)
594595
return -IPSET_ERR_BITMAP_RANGE_SIZE;

net/netfilter/ipset/ip_set_hash_ip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ hash_ip4_uadt(struct ip_set *set, struct nlattr *tb[],
179179
} else if (tb[IPSET_ATTR_CIDR]) {
180180
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
181181

182-
if (cidr > 32)
182+
if (!cidr || cidr > 32)
183183
return -IPSET_ERR_INVALID_CIDR;
184184
ip_set_mask_from_to(ip, ip_to, cidr);
185185
} else

net/netfilter/ipset/ip_set_hash_ipport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ hash_ipport4_uadt(struct ip_set *set, struct nlattr *tb[],
217217
} else if (tb[IPSET_ATTR_CIDR]) {
218218
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
219219

220-
if (cidr > 32)
220+
if (!cidr || cidr > 32)
221221
return -IPSET_ERR_INVALID_CIDR;
222222
ip_set_mask_from_to(ip, ip_to, cidr);
223223
} else

net/netfilter/ipset/ip_set_hash_ipportip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ hash_ipportip4_uadt(struct ip_set *set, struct nlattr *tb[],
225225
} else if (tb[IPSET_ATTR_CIDR]) {
226226
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
227227

228-
if (cidr > 32)
228+
if (!cidr || cidr > 32)
229229
return -IPSET_ERR_INVALID_CIDR;
230230
ip_set_mask_from_to(ip, ip_to, cidr);
231231
} else

net/netfilter/ipset/ip_set_hash_ipportnet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
290290
} else if (tb[IPSET_ATTR_CIDR]) {
291291
u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
292292

293-
if (cidr > 32)
293+
if (!cidr || cidr > 32)
294294
return -IPSET_ERR_INVALID_CIDR;
295295
ip_set_mask_from_to(ip, ip_to, cidr);
296296
}

0 commit comments

Comments
 (0)