Return-Path: Received: from mail-sn1nam02on0096.outbound.protection.outlook.com ([104.47.36.96]:45422 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032424AbeCAPgj (ORCPT ); Thu, 1 Mar 2018 10:36:39 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Dmitry Vyukov , Pablo Neira Ayuso , Sasha Levin Subject: [added to the 4.1 stable tree] netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check() Date: Thu, 1 Mar 2018 15:26:43 +0000 Message-ID: <20180301152116.1486-392-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Dmitry Vyukov This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 1a38956cce5eabd7b74f94bab70265e4df83165e ] Commit 136e92bbec0a 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: 136e92bbec0a ("[NETFILTER] CLUSTERIP: use a bitmap to store node res= ponsibility data") Signed-off-by: Dmitry Vyukov Reported-by: syzbot Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/ipv4/netfilter/ipt_CLUSTERIP.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CL= USTERIP.c index 771ab3d01ad3..d098013855f0 100644 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -365,7 +365,7 @@ static int clusterip_tg_check(const struct xt_tgchk_par= am *par) struct ipt_clusterip_tgt_info *cipinfo =3D par->targinfo; const struct ipt_entry *e =3D par->entryinfo; struct clusterip_config *config; - int ret; + int ret, i; =20 if (cipinfo->hash_mode !=3D CLUSTERIP_HASHMODE_SIP && cipinfo->hash_mode !=3D CLUSTERIP_HASHMODE_SIP_SPT && @@ -379,8 +379,18 @@ static int clusterip_tg_check(const struct xt_tgchk_pa= ram *par) pr_info("Please specify destination IP\n"); return -EINVAL; } - - /* FIXME: further sanity checks */ + if (cipinfo->num_local_nodes > ARRAY_SIZE(cipinfo->local_nodes)) { + pr_info("bad num_local_nodes %u\n", cipinfo->num_local_nodes); + return -EINVAL; + } + for (i =3D 0; i < cipinfo->num_local_nodes; i++) { + if (cipinfo->local_nodes[i] - 1 >=3D + sizeof(config->local_nodes) * 8) { + pr_info("bad local_nodes[%d] %u\n", + i, cipinfo->local_nodes[i]); + return -EINVAL; + } + } =20 config =3D clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1); if (!config) { --=20 2.14.1