Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2301992imm; Thu, 7 Jun 2018 08:26:45 -0700 (PDT) X-Google-Smtp-Source: ADUXVKJw4gVMnHmFD9lWNAIdslQ31cOggY8u7NwX9SWxolIMNNLJb7n93IZTeOtfTNkxrFumWVRl X-Received: by 2002:a62:d09:: with SMTP id v9-v6mr2167840pfi.163.1528385205065; Thu, 07 Jun 2018 08:26:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528385205; cv=none; d=google.com; s=arc-20160816; b=mSyU2f0/+AV8pS0TiyNo4E+bZZTzrkvWUZlzhIi/I/OSJEMcDc36IkMipyNP3DimbG iS8m7RKGAaZ1qDcpXMP5VvhtNvO3fCN6mciWf1EaUlimsj3Sdz0uOZbgWkjMdtysVrZs fRgEupRXjEAMzMk+ffrlZs//IZfJ+5zptkSo6Iy5FqWs/LEJtN3KoJg9lpRWxS8UYaW4 aNx5wqu45AVwVKObBUCb7527sSmWKfhtKBcauev24QBaYdDGyZT/SH/O0DT/xzQetXYX u/l0zT2aGIGH0ADt5nA1kHnAZqEhdJvnYHdMazbxBKWRuYyai64A7veu10QqU1kqr3gp nPig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=eNEbpLuHqpmDthTX7QxA0vNiqTjiZDtyKDwkHH6DpCA=; b=jDkOIkvbaAbIOE/l6h59EgC/QkT5yx3CcQuiqbKhqPDjOtJn9BLa3U9tjjpn/uUD+q STGJl+V1/XBNIHt9uuftus7Qf71wCUYVze16+5f18r+TD115f4RS1I/xUqVl56/k86I1 J+xvywp1nxhCbEZS2W83j+ip35vU3DfLfcY22Or0ffyRrgYJKYemA7qaVqo845niptkr bW+9RxO9/yG0lLOlmhNDIM/ZuWp6uINRuHqUajlcaBTX+WtxHnPC2cdRNfrSyAMAAfrO jOX6wa8xcOfBAztqQE1N1D4l+jbJJYJCmz4q6bgo/r8WI3/HY5OmFk4euD0IX2BZ4K03 I7SQ== 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 a5-v6si54401367plh.340.2018.06.07.08.26.29; Thu, 07 Jun 2018 08:26:45 -0700 (PDT) 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 S935872AbeFGPYb (ORCPT + 99 others); Thu, 7 Jun 2018 11:24:31 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41198 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932716AbeFGO6h (ORCPT ); Thu, 7 Jun 2018 10:58:37 -0400 Received: from [148.252.241.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1fQvbk-0005Zs-3S; Thu, 07 Jun 2018 15:09:44 +0100 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1fQvb4-0002xq-Tt; Thu, 07 Jun 2018 15:09:02 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "syzbot" , "Pablo Neira Ayuso" , "Dmitry Vyukov" Date: Thu, 07 Jun 2018 15:05:21 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 180/410] netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check() In-Reply-To: X-SA-Exim-Connect-IP: 148.252.241.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.57-rc1 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: Ben Hutchings --- 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 @@ -366,7 +366,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 (cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP && cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT && @@ -380,8 +380,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) {