From patchwork Mon May 14 05:41:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Elmously X-Patchwork-Id: 912681 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=canonical.com Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40kqMK2fC2z9s0q; Mon, 14 May 2018 15:41:49 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1fI6Ex-0006Hh-U9; Mon, 14 May 2018 05:41:43 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1fI6Ew-0006HJ-5P for kernel-team@lists.ubuntu.com; Mon, 14 May 2018 05:41:42 +0000 Received: from mail-io0-f199.google.com ([209.85.223.199]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1fI6Ev-0006Qe-RN for kernel-team@lists.ubuntu.com; Mon, 14 May 2018 05:41:41 +0000 Received: by mail-io0-f199.google.com with SMTP id c24-v6so15611254ioh.12 for ; Sun, 13 May 2018 22:41:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=E8Kv4lrDwiv7r5tUMXNV4kXqYLXfMdKOpnqfdResAJY=; b=QgNqN/KPEoELGdv1af5hdWxsv/T1qBB0AVQ70GnNM5aJn5rCrWMPPNxhpAMwfrtuv2 w6CVfmKmE9PJRv2c0oGmDGxFueGRnnU9Koas1lGKV94uZpJoGFhow13sPcKIXqKlFd28 WEiSrmv8TpilyRvxvMcsOQ9B/NmPUEDreJE6xei6q3j9pvD6Ysqxpfc451LQVDjSwcqE 2gj8MkwKjOO7DuPdbdsYKQAQ/sODv5oaINs3rMwFSK8c757zG+AmzurMuf45N+/DDN2c yD7sNXrnWA0d7K3tajKkDwABhHruSnFfIJCthreAoGpLaNecmJUFxywDiXyFZkDYchic LIOw== X-Gm-Message-State: ALKqPwez8mxfaPbXA1rJ/oMmZQhudy0wt9N8IErEEq1J/5FVbsOrs/Oj 2k27Ib8yv5jSQwHprHRS1fk+yEfTD6BJ66zZr1SvJbEMAJCWFJ9HpakqjxlkvZHvfe9Ruqr3j6Y 5byS+OqfynAfFjbUH9aroQ5gLncB3DP9jaeXni+D19g== X-Received: by 2002:a24:f102:: with SMTP id c2-v6mr7531952iti.121.1526276500356; Sun, 13 May 2018 22:41:40 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpkMjbWTd34Ttw0P6x4Ax30eCfNEacZHUH/xTYwF2UspR3xLihhZRtlgwm8Q7dHtvrNuQ8PVA== X-Received: by 2002:a24:f102:: with SMTP id c2-v6mr7531949iti.121.1526276500202; Sun, 13 May 2018 22:41:40 -0700 (PDT) Received: from kbuntu.fuzzbuzz.org (198-84-180-15.cpe.teksavvy.com. [198.84.180.15]) by smtp.gmail.com with ESMTPSA id k3-v6sm4198511ioc.44.2018.05.13.22.41.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 May 2018 22:41:38 -0700 (PDT) From: Khalid Elmously To: kernel-team@lists.ubuntu.com Subject: [A][PATCH 1/1] netfilter: ebtables: CONFIG_COMPAT: don't trust userland offsets Date: Mon, 14 May 2018 01:41:28 -0400 Message-Id: <20180514054128.9385-2-khalid.elmously@canonical.com> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180514054128.9385-1-khalid.elmously@canonical.com> References: <20180514054128.9385-1-khalid.elmously@canonical.com> X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Florian Westphal CVE-2018-1068 We need to make sure the offsets are not out of range of the total size. Also check that they are in ascending order. The WARN_ON triggered by syzkaller (it sets panic_on_warn) is changed to also bail out, no point in continuing parsing. Briefly tested with simple ruleset of -A INPUT --limit 1/s' --log plus jump to custom chains using 32bit ebtables binary. Reported-by: Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso (cherry-picked from b71812168571fa55e44cdd0254471331b9c4c4c6) Signed-off-by: Khalid Elmously Acked-by: Andy Whitcroft Acked-by: Kleber Sacilotto de Souza --- net/bridge/netfilter/ebtables.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c index 9c6e619f452b..6890bb669197 100644 --- a/net/bridge/netfilter/ebtables.c +++ b/net/bridge/netfilter/ebtables.c @@ -2061,7 +2061,9 @@ static int ebt_size_mwt(struct compat_ebt_entry_mwt *match32, if (match_kern) match_kern->match_size = ret; - WARN_ON(type == EBT_COMPAT_TARGET && size_left); + if (WARN_ON(type == EBT_COMPAT_TARGET && size_left)) + return -EINVAL; + match32 = (struct compat_ebt_entry_mwt *) buf; } @@ -2117,6 +2119,15 @@ static int size_entry_mwt(struct ebt_entry *entry, const unsigned char *base, * * offsets are relative to beginning of struct ebt_entry (i.e., 0). */ + for (i = 0; i < 4 ; ++i) { + if (offsets[i] >= *total) + return -EINVAL; + if (i == 0) + continue; + if (offsets[i-1] > offsets[i]) + return -EINVAL; + } + for (i = 0, j = 1 ; j < 4 ; j++, i++) { struct compat_ebt_entry_mwt *match32; unsigned int size;