Received: by 10.223.185.116 with SMTP id b49csp1074867wrg; Fri, 23 Feb 2018 11:27:53 -0800 (PST) X-Google-Smtp-Source: AH8x2260Y7sSG/Ewu/plbLMPRzPf/29Z0gJX5PdAhf0OkbnJwT9PrXYG86TXO+esg1OUNYzpeW/v X-Received: by 2002:a17:902:8215:: with SMTP id x21-v6mr2716305pln.164.1519414073498; Fri, 23 Feb 2018 11:27:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519414073; cv=none; d=google.com; s=arc-20160816; b=AeYMRSHDJxoo3s8/xXp5S5WzstjXnWjOSs9LTFTJB5jtTnE/O+yDAW5Yw/wpka6juH 63iFrO9lLaz9+THiq35fS73IWyzathYI6eO2fQ/D4GK8RQ/25XUR7l4m1xH/SXJ60taX VmNbns+DqlenYhQvthI5Q7uwf4lb9T8zsKGOle+wZcFFtAQz1JZa92PMfZ3U97O/0xWp yoCUkgf+OxSFkxt9wmblyLpY6l9Lc2qsHrR8+elhtwM3EH9Yi0kGF4zNUvncRilFLMnb oEEBAA1KL+lq1VuWk+k+jlE+K2WwT2r/koSnDjh22RTm4Kfc8SFU3O7faa0Tod8oaBZ0 fiFg== 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=CgIMvv8XLp7f7pPxFmdc1QeOABM6usn6hF5tfSUJEX8=; b=Okxa9KUnUi/gKrCG3m0lleEUGPfQlECKDrZvjqX48CTFLZaTRrvvsff00y5X/NVlgc iXrIVKL6aWMjCxKtyGdhMA3u0whk5qWLxupyTRurHZzuu9wXrR5yYUqApEZkA1oMMjyG Mq3qbdxt0oKmcw8rMKNe7xMsZ8x/PPeOqcDWdZlSpDOkbifTslP4srr2wSG+b2kUeDJi VFgoLM/6f/YfKQhuaJqgyN4Wv2jEOZdtZcmAvy5HWSa2GwZB+4LFIWPlQl84md2hRein CYWPZUoreMJ6MOThvT5W5RPrnnPlsYKCRhAmCQFarNyfiHXdF3AZIYqWCWqY3iAMMo/P Jiuw== 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 t15si2251638pfg.333.2018.02.23.11.27.38; Fri, 23 Feb 2018 11:27:53 -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 S935178AbeBWSwh (ORCPT + 99 others); Fri, 23 Feb 2018 13:52:37 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:46988 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935166AbeBWSwf (ORCPT ); Fri, 23 Feb 2018 13:52:35 -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 69727FC4; Fri, 23 Feb 2018 18:52:34 +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.14 037/159] netfilter: ipt_CLUSTERIP: fix out-of-bounds accesses in clusterip_tg_check() Date: Fri, 23 Feb 2018 19:25:45 +0100 Message-Id: <20180223170747.930608609@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@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.14-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) {