Received: by 10.223.185.116 with SMTP id b49csp1058109wrg; Fri, 23 Feb 2018 11:08:35 -0800 (PST) X-Google-Smtp-Source: AH8x227ziJ3A1Cvh2r41WV7UG/Qlb1vmsUJNFcCB+TvUzxsKOgAsP9IsSCyPqDE8fA3J8tSmqQk0 X-Received: by 2002:a17:902:7883:: with SMTP id q3-v6mr2587146pll.361.1519412914984; Fri, 23 Feb 2018 11:08:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519412914; cv=none; d=google.com; s=arc-20160816; b=P5DaxJoSg1dx+JBNHx+fplcbHiQznnSiLdaLRQgaJA7JmaGHnJiKSGslpO2sGVJA+Z h/IJdC6skQnrYb1iCB91SW+M9FaFxv0krFDWF/nSFQOEnC4+AkadxNCJuP9N0PXhhcZp Rs4q1Aqy006SjmNCQlkKzg6/wQzaATW4dS/4HvHKXJmUvfyEGdf6E7UMIiZkAZp31f9l JICJ1FsI94w0frCySN5EZwHBlrxIKtY3QoXxU34lnknUHD6gc2zflQSthFOGT4ybcPCw yD87ulf+vgJZFwv7WGXct3nVomBWpLXIOP2JPTa3tfXtHiyLou1qSyOxqg3wqRaNmDo7 b4eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ugdTlBNBIzfZ2IFkpDY80ayQNo439UCI82ykC6yBHOg=; b=xHKPSdRFPv3RdnyOANESmCoiEhopYDO7BkWWB6T9FvHZ7ixa07M5i2dWP8M9bxu0PA MVe4EYoGioORVxRQLUOWhz78VEWcbSN5DVs7pwgi5JmH1QjEUP02K0mDFvZAWb9V0lez fJevtKKyeMEZdLisl6/7T7TmxGMFLQUmgH4vHRaIOVF6c3bdmONO6M11yidCmi0WcsdB oo60+YIZJjHCbT1mDHhpbzEAK2xlM8gCKiyOIIHFTU+Sxruo7OlhS9yeQVAzvCuoSyxq s263SopV20S1ggQInLTANq/t0BuQJ9w7oH4bVm/5cNbSKQSovBxlYpOeztv30v36WAEw MEsg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m189si2198804pfc.410.2018.02.23.11.08.20; Fri, 23 Feb 2018 11:08:34 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965405AbeBWS53 (ORCPT + 99 others); Fri, 23 Feb 2018 13:57:29 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:50178 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965358AbeBWS5X (ORCPT ); Fri, 23 Feb 2018 13:57:23 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0B70FCE7; Fri, 23 Feb 2018 18:57:22 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Vyukov , syzbot , Pablo Neira Ayuso Subject: [PATCH 4.15 15/45] netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check() Date: Fri, 23 Feb 2018 19:28:54 +0100 Message-Id: <20180223170717.757260952@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170715.197760019@linuxfoundation.org> References: <20180223170715.197760019@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Vyukov commit 1a38956cce5eabd7b74f94bab70265e4df83165e upstream. 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 responsibility data") Signed-off-by: Dmitry Vyukov Reported-by: syzbot Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/ipv4/netfilter/ipt_CLUSTERIP.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c @@ -431,7 +431,7 @@ static int clusterip_tg_check(const stru struct ipt_clusterip_tgt_info *cipinfo = par->targinfo; const struct ipt_entry *e = par->entryinfo; struct clusterip_config *config; - int ret; + int ret, i; if (par->nft_compat) { pr_err("cannot use CLUSTERIP target from nftables compat\n"); @@ -450,8 +450,18 @@ static int clusterip_tg_check(const stru 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 = 0; i < cipinfo->num_local_nodes; i++) { + if (cipinfo->local_nodes[i] - 1 >= + sizeof(config->local_nodes) * 8) { + pr_info("bad local_nodes[%d] %u\n", + i, cipinfo->local_nodes[i]); + return -EINVAL; + } + } config = clusterip_config_find_get(par->net, e->ip.dst.s_addr, 1); if (!config) {