Skip to content

Commit 3045eb3

Browse files
dvyukovgregkh
authored andcommitted
netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check()
commit 1a38956cce5eabd7b74f94bab70265e4df83165e upstream. 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]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent eaae500 commit 3045eb3

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
@@ -365,7 +365,7 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
365365
struct ipt_clusterip_tgt_info *cipinfo = par->targinfo;
366366
const struct ipt_entry *e = par->entryinfo;
367367
struct clusterip_config *config;
368-
int ret;
368+
int ret, i;
369369

370370
if (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP &&
371371
cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT &&
@@ -379,8 +379,18 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
379379
pr_info("Please specify destination IP\n");
380380
return -EINVAL;
381381
}
382-
383-
/* FIXME: further sanity checks */
382+
if (cipinfo->num_local_nodes > ARRAY_SIZE(cipinfo->local_nodes)) {
383+
pr_info("bad num_local_nodes %u\n", cipinfo->num_local_nodes);
384+
return -EINVAL;
385+
}
386+
for (i = 0; i < cipinfo->num_local_nodes; i++) {
387+
if (cipinfo->local_nodes[i] - 1 >=
388+
sizeof(config->local_nodes) * 8) {
389+
pr_info("bad local_nodes[%d] %u\n",
390+
i, cipinfo->local_nodes[i]);
391+
return -EINVAL;
392+
}
393+
}
384394

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

0 commit comments

Comments
 (0)