Received: by 10.213.65.68 with SMTP id h4csp644037imn; Fri, 6 Apr 2018 06:40:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx48CikW62zAXxSdO83pgJN5agZgh+k7XkUaZuxvshEdkuXF2laCUjGxKQBnnwbVtVZw+7ZkB X-Received: by 10.99.174.67 with SMTP id e3mr17827127pgp.139.1523022016976; Fri, 06 Apr 2018 06:40:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523022016; cv=none; d=google.com; s=arc-20160816; b=ksUeSkAfQGKTkAEfY6D5yDr9yIim1aY+P2lBLKZ7SLDOpmdGE5TmK53SUqS0QOQlI4 Rszpo50RVpRRR/aadTU2FQUAKR0LhLWJqlDjrDbZRaNWy7Z886uvOEpw/kLoyG9Hqn8G 5bqDgRzEDfZO8V+dYL9AxmPoJRe4T1v4HNhTn4eoEckQsqkyEcSN/Wa1VhwkjXTH9Ayj fKnBvPfkfED7FkFd/Y08HPh28Tl1yIF/e8AjvH3vLf0edwME3KYO/Qx/2GZW29EPBwvM nosmfjjQfsxHv9o0jz57QqNDui+bcp/8YgnOTgNmFTqrCTvS61Tq/LQx9IuWFNne/BuN FZMA== 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=wcnaCqnhgDorOj/ID7V4ebe195AcK9Cztn2H5G3bog8=; b=EA9rAgmJ5psaXiPu0kzUKzwpOLj95f+YTKggReCFEeI9/OQz4IN1HtMZI7EwwuB72m 7Nj6E1djpF4PwFyecW+rRWVnzicMyvE+EFkSupkuBfG/2bJA18Z/frM9PUsHbdeL86yW 0U4fNYB3I/5NJawef6tXcEGmisC6NusrgPUoMVvvC6NnZ9OQc24qiU93HAPAfykGgLlw OincqC9NQpk1JPPolTWXLHo9Gd/eq47IC2veMTEnRRnaEI8K08wAxb18vQHiGGOGwiz2 6Ygl87lwSaksO2BjLNJ/Tx8KJJTSd6KX3pImVWIKz+pB7mVv0Vc56MW/7kFlW4dN5pDT fvfQ== 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 w16-v6si7947182plp.165.2018.04.06.06.40.03; Fri, 06 Apr 2018 06:40:16 -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 S932477AbeDFNih (ORCPT + 99 others); Fri, 6 Apr 2018 09:38:37 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33366 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932468AbeDFNif (ORCPT ); Fri, 6 Apr 2018 09:38:35 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 75D1DCDD; Fri, 6 Apr 2018 13:38:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+bdabab6f1983a03fc009@syzkaller.appspotmail.com, Florian Westphal , Eric Dumazet , Pablo Neira Ayuso Subject: [PATCH 4.14 30/67] netfilter: bridge: ebt_among: add more missing match size checks Date: Fri, 6 Apr 2018 15:24:00 +0200 Message-Id: <20180406084345.281062474@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180406084341.225558262@linuxfoundation.org> References: <20180406084341.225558262@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: Florian Westphal commit c8d70a700a5b486bfa8e5a7d33d805389f6e59f9 upstream. ebt_among is special, it has a dynamic match size and is exempt from the central size checks. commit c4585a2823edf ("bridge: ebt_among: add missing match size checks") added validation for pool size, but missed fact that the macros ebt_among_wh_src/dst can already return out-of-bound result because they do not check value of wh_src/dst_ofs (an offset) vs. the size of the match that userspace gave to us. v2: check that offset has correct alignment. Paolo Abeni points out that we should also check that src/dst wormhash arrays do not overlap, and src + length lines up with start of dst (or vice versa). v3: compact wormhash_sizes_valid() part NB: Fixes tag is intentionally wrong, this bug exists from day one when match was added for 2.6 kernel. Tag is there so stable maintainers will notice this one too. Tested with same rules from the earlier patch. Fixes: c4585a2823edf ("bridge: ebt_among: add missing match size checks") Reported-by: Signed-off-by: Florian Westphal Reviewed-by: Eric Dumazet Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/bridge/netfilter/ebt_among.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) --- a/net/bridge/netfilter/ebt_among.c +++ b/net/bridge/netfilter/ebt_among.c @@ -177,6 +177,28 @@ static bool poolsize_invalid(const struc return w && w->poolsize >= (INT_MAX / sizeof(struct ebt_mac_wormhash_tuple)); } +static bool wormhash_offset_invalid(int off, unsigned int len) +{ + if (off == 0) /* not present */ + return false; + + if (off < (int)sizeof(struct ebt_among_info) || + off % __alignof__(struct ebt_mac_wormhash)) + return true; + + off += sizeof(struct ebt_mac_wormhash); + + return off > len; +} + +static bool wormhash_sizes_valid(const struct ebt_mac_wormhash *wh, int a, int b) +{ + if (a == 0) + a = sizeof(struct ebt_among_info); + + return ebt_mac_wormhash_size(wh) + a == b; +} + static int ebt_among_mt_check(const struct xt_mtchk_param *par) { const struct ebt_among_info *info = par->matchinfo; @@ -189,6 +211,10 @@ static int ebt_among_mt_check(const stru if (expected_length > em->match_size) return -EINVAL; + if (wormhash_offset_invalid(info->wh_dst_ofs, em->match_size) || + wormhash_offset_invalid(info->wh_src_ofs, em->match_size)) + return -EINVAL; + wh_dst = ebt_among_wh_dst(info); if (poolsize_invalid(wh_dst)) return -EINVAL; @@ -201,6 +227,14 @@ static int ebt_among_mt_check(const stru if (poolsize_invalid(wh_src)) return -EINVAL; + if (info->wh_src_ofs < info->wh_dst_ofs) { + if (!wormhash_sizes_valid(wh_src, info->wh_src_ofs, info->wh_dst_ofs)) + return -EINVAL; + } else { + if (!wormhash_sizes_valid(wh_dst, info->wh_dst_ofs, info->wh_src_ofs)) + return -EINVAL; + } + expected_length += ebt_mac_wormhash_size(wh_src); if (em->match_size != EBT_ALIGN(expected_length)) {