From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36ED619503 for ; Mon, 12 Jun 2023 10:34:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B0685C4339B; Mon, 12 Jun 2023 10:34:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1686566070; bh=B7heiBcN7tc9i5gTayhAXMvOtb4LeXG7pTvWmoy8l0g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BZMta9zjENkWGG3jp70QxET9QXDeG6CLKJa6MChb6Pkc97J1FlfWIb4dw6NVoMhxV YX8zsdzU472H86kq4jKj3BrmPsbD0SVO+BUPb56vMBuiYXdd14z2QqVVQT9H8CrDww zKqKnxk+aqP3VPEpBcKZq7wUyJhStQSoI80IV//s= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tijs Van Buggenhout , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.10 23/68] netfilter: conntrack: fix NULL pointer dereference in nf_confirm_cthelper Date: Mon, 12 Jun 2023 12:26:15 +0200 Message-ID: <20230612101659.398631465@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612101658.437327280@linuxfoundation.org> References: <20230612101658.437327280@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Tijs Van Buggenhout [ Upstream commit e1f543dc660b44618a1bd72ddb4ca0828a95f7ad ] An nf_conntrack_helper from nf_conn_help may become NULL after DNAT. Observed when TCP port 1720 (Q931_PORT), associated with h323 conntrack helper, is DNAT'ed to another destination port (e.g. 1730), while nfqueue is being used for final acceptance (e.g. snort). This happenned after transition from kernel 4.14 to 5.10.161. Workarounds: * keep the same port (1720) in DNAT * disable nfqueue * disable/unload h323 NAT helper $ linux-5.10/scripts/decode_stacktrace.sh vmlinux < /tmp/kernel.log BUG: kernel NULL pointer dereference, address: 0000000000000084 [..] RIP: 0010:nf_conntrack_update (net/netfilter/nf_conntrack_core.c:2080 net/netfilter/nf_conntrack_core.c:2134) nf_conntrack [..] nfqnl_reinject (net/netfilter/nfnetlink_queue.c:237) nfnetlink_queue nfqnl_recv_verdict (net/netfilter/nfnetlink_queue.c:1230) nfnetlink_queue nfnetlink_rcv_msg (net/netfilter/nfnetlink.c:241) nfnetlink [..] Fixes: ee04805ff54a ("netfilter: conntrack: make conntrack userspace helpers work again") Signed-off-by: Tijs Van Buggenhout Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_conntrack_core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 193a18bfddc0a..f82a234ac53a1 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -2075,6 +2075,9 @@ static int nf_confirm_cthelper(struct sk_buff *skb, struct nf_conn *ct, return 0; helper = rcu_dereference(help->helper); + if (!helper) + return 0; + if (!(helper->flags & NF_CT_HELPER_F_USERSPACE)) return 0; -- 2.39.2