Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp4365703pxu; Mon, 12 Oct 2020 17:44:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2UNx/chrQPpCYe65znXZ3jx+8Uyn6DI3JBPXt5ZFKLTKC9R/NMP8mSaaWbWC2my4UmrSB X-Received: by 2002:a17:906:86c3:: with SMTP id j3mr31590537ejy.493.1602549853499; Mon, 12 Oct 2020 17:44:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602549853; cv=none; d=google.com; s=arc-20160816; b=pgkXi71/2f9Mg2sGt2hUnn80jmdubJnYzk4D18FAqDFxs7ZeLeUvDAZ3owBKUCTaHX o5/E+krsRwbIRYZm9ToWpaAINvc/ESZW5arNesGUqUjeE781E3/RKYYvRbKn6jdb/Vsc EoT7diri9rCxXQiwfIY7EPli5ui3R+G1Cr7NpGY6Yi//hCe5KuGbugHfqRl1SCC32uQC e75mT2Wsm/AMtCcw5wsoNu6DYmglkxJdhO3Ljy0pk6X90rT3ewlWv70zGcgmwplW4j23 YTQ2MZQT27QsCkCmFQI9WfLfjyvT1S86fmYRaLwUlqvPqIKCrS3sT3thWNgJmAXWFouU ut0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/bKwko7wAke6MLeV5gENuJt6lQtakNnXial/5r4H5rg=; b=HfmmzLYpXLFZCchoZWsbAJAGMWLGq+AhW6RO92TKbZUb39OyfOLZvgXPHXVd20cVTy tq1swte88ctr2+0sggzAPjnvcEf4j8mxRoAtQuLGMsSVa2EY8wtQgcSb6F/BE0uL24nu kkvfy0cufnHWRIzqQzsbVgR5+s1EZZLH+HGZHedRhSWah6mQyR2xSua+UTga8hGAasAv 0A+sGn2gGiHw8Q441B8Dm7nAoh4JZaauhPX75SKJzN0Lzt7QQACpWxhxI2inbu0lX4dJ U6mOtB4478lNot6aj0x7WEFdKxhJxERgh4Qgo5kVqB2k6Fd5J9zgwzg3Xfd5doR+l8uN a9Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PC+ok3aS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y17si13412540ejr.469.2020.10.12.17.43.50; Mon, 12 Oct 2020 17:44:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PC+ok3aS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730765AbgJLOF0 (ORCPT + 99 others); Mon, 12 Oct 2020 10:05:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:37170 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730787AbgJLNfN (ORCPT ); Mon, 12 Oct 2020 09:35:13 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CB145221FF; Mon, 12 Oct 2020 13:35:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1602509712; bh=/NvLDIZWzlq4ntL9rtpaNjhw66AfYa5NvmvPft2yXEs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PC+ok3aS4LrXik3Ev8P44tkFATj4YYnw4i5w64nh41PBPt5K/hSpd6Z3dxGZsadQv RbEabwjbHM6JpzJVf5PHNCzn2H/QyLmmYsWdt1nJtNWwcOPX2aDgK7nThHJ8nm0GKl hcrTUvJksSmruNP/Gn+MY95r8Sw8RjvWURyN8RX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Will McVicker , Pablo Neira Ayuso Subject: [PATCH 4.9 22/54] netfilter: ctnetlink: add a range check for l3/l4 protonum Date: Mon, 12 Oct 2020 15:26:44 +0200 Message-Id: <20201012132630.611019111@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201012132629.585664421@linuxfoundation.org> References: <20201012132629.585664421@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will McVicker commit 1cc5ef91d2ff94d2bf2de3b3585423e8a1051cb6 upstream. The indexes to the nf_nat_l[34]protos arrays come from userspace. So check the tuple's family, e.g. l3num, when creating the conntrack in order to prevent an OOB memory access during setup. Here is an example kernel panic on 4.14.180 when userspace passes in an index greater than NFPROTO_NUMPROTO. Internal error: Oops - BUG: 0 [#1] PREEMPT SMP Modules linked in:... Process poc (pid: 5614, stack limit = 0x00000000a3933121) CPU: 4 PID: 5614 Comm: poc Tainted: G S W O 4.14.180-g051355490483 Hardware name: Qualcomm Technologies, Inc. SM8150 V2 PM8150 Google Inc. MSM task: 000000002a3dfffe task.stack: 00000000a3933121 pc : __cfi_check_fail+0x1c/0x24 lr : __cfi_check_fail+0x1c/0x24 ... Call trace: __cfi_check_fail+0x1c/0x24 name_to_dev_t+0x0/0x468 nfnetlink_parse_nat_setup+0x234/0x258 ctnetlink_parse_nat_setup+0x4c/0x228 ctnetlink_new_conntrack+0x590/0xc40 nfnetlink_rcv_msg+0x31c/0x4d4 netlink_rcv_skb+0x100/0x184 nfnetlink_rcv+0xf4/0x180 netlink_unicast+0x360/0x770 netlink_sendmsg+0x5a0/0x6a4 ___sys_sendmsg+0x314/0x46c SyS_sendmsg+0xb4/0x108 el0_svc_naked+0x34/0x38 This crash is not happening since 5.4+, however, ctnetlink still allows for creating entries with unsupported layer 3 protocol number. Fixes: c1d10adb4a521 ("[NETFILTER]: Add ctnetlink port for nf_conntrack") Signed-off-by: Will McVicker [pablo@netfilter.org: rebased original patch on top of nf.git] Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_conntrack_netlink.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/netfilter/nf_conntrack_netlink.c +++ b/net/netfilter/nf_conntrack_netlink.c @@ -1031,6 +1031,8 @@ ctnetlink_parse_tuple(const struct nlatt if (!tb[CTA_TUPLE_IP]) return -EINVAL; + if (l3num != NFPROTO_IPV4 && l3num != NFPROTO_IPV6) + return -EOPNOTSUPP; tuple->src.l3num = l3num; err = ctnetlink_parse_tuple_ip(tb[CTA_TUPLE_IP], tuple);