Message ID | 20230703145216.1096265-1-revest@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f45:0:b0:3ea:f831:8777 with SMTP id v5csp584529vqx; Mon, 3 Jul 2023 08:01:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlEV8yhwHtgNH4q0Y78wytueeXjDyfE6Uk/OnL+qYeS0lMECAIG3l2jLXl1n2MuDeNvQ0VsZ X-Received: by 2002:a05:6e02:f41:b0:346:1919:7cb1 with SMTP id y1-20020a056e020f4100b0034619197cb1mr972270ilj.2.1688396493792; Mon, 03 Jul 2023 08:01:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688396493; cv=none; d=google.com; s=arc-20160816; b=izu2ldyYahdufXxbdqSaP/E7/4rqxFaU8d4PtC0fkZl/lLOjCUxTmidkMtT3wmXr13 TV80FDbCyI1qZw2QSk8c7RcUJn/sjkvSnCDmJPV7IEUIB96yrYa22ro9qXbNac1C7yIB fjnZFggj9d58wNGObTEJPa2Y7B5ZThsgdk1Dxi+sWi5c2v2vjgDRISVMV/p2Z3FQ7Rc3 3zfnPn5MPo4TlPJPuxc+Rw0E1K/6F8ixVgMZLN2asEl2VcVYQfFNiARVMNTFbqMCZdf3 9vRzluqK/HavTOYOuSwbEZUEVqCRD0qP74ed+2FH4TcTQndwJNtPPSRPUFjQajHWSVGd b1AQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=+3KjuLBngLO3rai8mrqNkWZ2OBnCS0ojb/WfZfP0ytU=; fh=UkIEdljm5S6UPwmfoz6Doxbyprm/VHknRCJJV1Jhsrk=; b=e0WLV+05iaPm8LjwplnxvEDyxZYKIOCq0Z85cwfvF6TqCY94RNG7aaxLz1U1qqHiT2 vuMtHxGHn6MpXtryc3Tea8GtpOXvYm5jP1kwsx51jMWbaipJfbvJI2IMOdepd21O1kUc wVQiD3noILCPBPr9XeKosZz6HzbqeNiHUGfKwS7u1xeCiB9x1zkx7sQV4KvO4lw0wL8t EuJVtCLHNLReW0izZsz9PkXQLAaEkDTbUxjL6yO90FXxBkbYFQtuh5klWbHrxBFAnRb8 xgHUcyDUglB4PJhfhcCQHOTZMJyVs5b17evMsMJsyXbMzM9J4RSKtGWPQJKLchmiW8KU Udjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KFYcQJIC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k71-20020a63844a000000b0055b731aa992si6207925pgd.370.2023.07.03.08.01.16; Mon, 03 Jul 2023 08:01:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KFYcQJIC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230121AbjGCOw0 (ORCPT <rfc822;ivan.orlov0322@gmail.com> + 99 others); Mon, 3 Jul 2023 10:52:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229484AbjGCOwY (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 3 Jul 2023 10:52:24 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DE268E5F for <linux-kernel@vger.kernel.org>; Mon, 3 Jul 2023 07:52:22 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbd33a57dcso23193625e9.0 for <linux-kernel@vger.kernel.org>; Mon, 03 Jul 2023 07:52:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1688395941; x=1690987941; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=+3KjuLBngLO3rai8mrqNkWZ2OBnCS0ojb/WfZfP0ytU=; b=KFYcQJIC/LHmqIQeVankvlb89fFhXYJ2u4CRhT6/pS3M2Mop+/IKcNS6tZ4P3Wel4B 4812aItVGnJv3Opnl116QiQO7pXEjK6Fe0MXtMVzVAx03vxCOot9tHZcEF778K3ijkGZ 8ehBVmANtCmTN66OCjq2uFuheE7ql4BEsAXiI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688395941; x=1690987941; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+3KjuLBngLO3rai8mrqNkWZ2OBnCS0ojb/WfZfP0ytU=; b=H5qtRRs89xYxrvC6wCHQNyJmFBSUiYN+30Ca1GJPm9oU80ogO4FRHAEAdCcIlAfNPp PRm9/OeWDOo+ZfcfeNQGe3AfS8DY0mC/wgFJtRLaY1yhTMv6CjqIZDwD0P4ZfEym6cdH homGjkv8Fa52jYfjiamAVhsPYKEde/G6SZmO+utNDpKked8L1FX3/RYBzTG7NGs4dHtm +KKb5jnUTAT/GVNQUq1YCEwCklI7DhTDVyIVdN9oGINYjdSAhTJrBDDsc8rR4evoSR4a ACJPKOsgmibegJg6UxNqcJXmyP/o4tZcA6k/T5v3sNibmqzAh67re/VLWt7TMEOYB1of Z7xw== X-Gm-Message-State: AC+VfDxs22ZGwIcgKccesUMorB5lNI6QwrorngQeFH9Wh3Fd2GYkHbp+ qYqQl90Sts5rkyP/wiy5ah91qw== X-Received: by 2002:a7b:c38f:0:b0:3fb:a46c:7eac with SMTP id s15-20020a7bc38f000000b003fba46c7eacmr9214337wmj.7.1688395940886; Mon, 03 Jul 2023 07:52:20 -0700 (PDT) Received: from revest.zrh.corp.google.com ([2a00:79e0:9d:6:34e3:ca8b:5d5c:2c66]) by smtp.gmail.com with ESMTPSA id 12-20020a05600c028c00b003fbaade072dsm16878177wmk.23.2023.07.03.07.52.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 07:52:20 -0700 (PDT) From: Florent Revest <revest@chromium.org> To: netfilter-devel@vger.kernel.org, coreteam@netfilter.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, kpsingh@kernel.org, stable@vger.kernel.org, Florent Revest <revest@chromium.org> Subject: [PATCH nf v2] netfilter: conntrack: Avoid nf_ct_helper_hash uses after free Date: Mon, 3 Jul 2023 16:52:16 +0200 Message-ID: <20230703145216.1096265-1-revest@chromium.org> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768784090739188855?= X-GMAIL-MSGID: =?utf-8?q?1770412041398108086?= |
Series |
[nf,v2] netfilter: conntrack: Avoid nf_ct_helper_hash uses after free
|
|
Commit Message
Florent Revest
July 3, 2023, 2:52 p.m. UTC
If nf_conntrack_init_start() fails (for example due to a
register_nf_conntrack_bpf() failure), the nf_conntrack_helper_fini()
clean-up path frees the nf_ct_helper_hash map.
When built with NF_CONNTRACK=y, further netfilter modules (e.g:
netfilter_conntrack_ftp) can still be loaded and call
nf_conntrack_helpers_register(), independently of whether nf_conntrack
initialized correctly. This accesses the nf_ct_helper_hash dangling
pointer and causes a uaf, possibly leading to random memory corruption.
This patch guards nf_conntrack_helper_register() from accessing a freed
or uninitialized nf_ct_helper_hash pointer and fixes possible
uses-after-free when loading a conntrack module.
Cc: stable@vger.kernel.org
Fixes: 12f7a505331e ("netfilter: add user-space connection tracking helper infrastructure")
Signed-off-by: Florent Revest <revest@chromium.org>
---
net/netfilter/nf_conntrack_helper.c | 4 ++++
1 file changed, 4 insertions(+)
Comments
Florent Revest <revest@chromium.org> wrote: > If nf_conntrack_init_start() fails (for example due to a > register_nf_conntrack_bpf() failure), the nf_conntrack_helper_fini() > clean-up path frees the nf_ct_helper_hash map. > > When built with NF_CONNTRACK=y, further netfilter modules (e.g: > netfilter_conntrack_ftp) can still be loaded and call > nf_conntrack_helpers_register(), independently of whether nf_conntrack > initialized correctly. This accesses the nf_ct_helper_hash dangling > pointer and causes a uaf, possibly leading to random memory corruption. > > This patch guards nf_conntrack_helper_register() from accessing a freed > or uninitialized nf_ct_helper_hash pointer and fixes possible > uses-after-free when loading a conntrack module. Reviewed-by: Florian Westphal <fw@strlen.de>
diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c index 0c4db2f2ac43..f22691f83853 100644 --- a/net/netfilter/nf_conntrack_helper.c +++ b/net/netfilter/nf_conntrack_helper.c @@ -360,6 +360,9 @@ int nf_conntrack_helper_register(struct nf_conntrack_helper *me) BUG_ON(me->expect_class_max >= NF_CT_MAX_EXPECT_CLASSES); BUG_ON(strlen(me->name) > NF_CT_HELPER_NAME_LEN - 1); + if (!nf_ct_helper_hash) + return -ENOENT; + if (me->expect_policy->max_expected > NF_CT_EXPECT_MAX_CNT) return -EINVAL; @@ -515,4 +518,5 @@ int nf_conntrack_helper_init(void) void nf_conntrack_helper_fini(void) { kvfree(nf_ct_helper_hash); + nf_ct_helper_hash = NULL; }