Skip to content

Commit 1a38956

Browse files
dvyukovummakynes
authored andcommitted
netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check()
Commit 136e92b switched local_nodes from an array to a bitmask but did not add proper bounds checks. As the result clusterip_config_init_nodelist() can both over-read ipt_clusterip_tgt_info.local_nodes and over-write clusterip_config.local_nodes. Add bounds checks for both. Fixes: 136e92b ("[NETFILTER] CLUSTERIP: use a bitmap to store node responsibility data") Signed-off-by: Dmitry Vyukov <[email protected]> Reported-by: syzbot <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 1e98ffe commit 1a38956

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

net/ipv4/netfilter/ipt_CLUSTERIP.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
431431
struct ipt_clusterip_tgt_info *cipinfo = par->targinfo;
432432
const struct ipt_entry *e = par->entryinfo;
433433
struct clusterip_config *config;
434-
int ret;
434+
int ret, i;
435435

436436
if (par->nft_compat) {
437437
pr_err("cannot use CLUSTERIP target from nftables compat\n");
@@ -450,8 +450,18 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
450450
pr_info("Please specify destination IP\n");
451451
return -EINVAL;
452452
}
453-
454-
/* FIXME: further sanity checks */
453+
if (cipinfo->num_local_nodes > ARRAY_SIZE(cipinfo->local_nodes)) {
454+
pr_info("bad num_local_nodes %u\n", cipinfo->num_local_nodes);
455+
return -EINVAL;
456+
}
457+
for (i = 0; i < cipinfo->num_local_nodes; i++) {
458+
if (cipinfo->local_nodes[i] - 1 >=
459+
sizeof(config->local_nodes) * 8) {
460+
pr_info("bad local_nodes[%d] %u\n",
461+
i, cipinfo->local_nodes[i]);
462+
return -EINVAL;
463+
}
464+
}
455465

456466
config = clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1);
457467
if (!config) {

0 commit comments

Comments
 (0)