Received: by 10.223.185.116 with SMTP id b49csp1107907wrg; Fri, 23 Feb 2018 12:04:30 -0800 (PST) X-Google-Smtp-Source: AH8x227sHFVx3dU/pGfGt96+eNG0dzFJZ67FImzfRVTU4qov/eczkDS/qZFmHZgQ8vpi1xU37LjU X-Received: by 2002:a17:902:e65:: with SMTP id 92-v6mr2738367plw.268.1519416270249; Fri, 23 Feb 2018 12:04:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519416270; cv=none; d=google.com; s=arc-20160816; b=CeYh5smgTpej7LLqdkeqvYquAW6Mj7Bsy196Zk6vUnC9SJYIIf2/T0RwrH4+XhDYMC zvdlvfpQy/RmqxbBmWahxGqn0FxkzcQLQPLFNXJkUO6vVvwg6yf3GgwefT8dHkAKGLh8 7leJrAq7EnkZXtvFlNoRn1aWNLPAU0vW5hZdoFnRMpm0pBTIrVBK9RFnZn/uzZZsESa3 GH4JRgVJHn+fRqZ55+qgmovEzfkyalOzxiXWH6inR9eN0WjaUx8ZuE25JzkzwDX1g8Hl iJaB2uGRlCft3LU6RJ9rKBLfEA6p85gL5ji5rIigEgA2/DXl9TcFQkduUYeogF41iOvD vNDQ== 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=9tUOxvRSq3HUDh/VSXYrJI6yFIjFhg8GBGXKxxp7zzY=; b=IECCVhY5727jbFHC/vE7vqGtK6r5gs9wSPhdRf3ItEmq2rGe5EGuVOy+C4aAuLtwMN rfgAlB1m0uAqHfaWwtlz46PhOFdY/8KyGE+IR94todNuWfH6iKb9enyrGezo14lVjSI6 CL6XKq3NAnvUDNYqs+bFPtxfYHLu49wbzxbsZDAnhDGZkXAKJD+gXmMO+117VI1MsnL7 ftKbb2A1pP48bTsTPPVIjr4K0hb/KLx93jBbvlVZIlDrlyGM8mC7lIX8rmto8PPwXfqf AJe185mLlSJkcmKiyZzPNf3tXBn+U+SKPobh/3usTUV6AjKGjxtSdijNi/5dQBOa7nf7 EAbQ== 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 n10si1875256pgp.343.2018.02.23.12.04.06; Fri, 23 Feb 2018 12:04:30 -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 S933198AbeBWSnI (ORCPT + 99 others); Fri, 23 Feb 2018 13:43:08 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42042 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932515AbeBWSnE (ORCPT ); Fri, 23 Feb 2018 13:43:04 -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 33A5C1046; Fri, 23 Feb 2018 18:43:03 +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.9 024/145] netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check() Date: Fri, 23 Feb 2018 19:25:30 +0100 Message-Id: <20180223170727.895360268@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@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.9-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 @@ -365,7 +365,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"); @@ -384,8 +384,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) {