Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1776270pxp; Mon, 7 Mar 2022 02:03:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzYn/w/4pb0khMLGxnmg46rSD/P5lpcXv8+Qt7fMn589Z1GaQ4GEWkcGBctDd8jmS7OfQZR X-Received: by 2002:a05:6402:442:b0:416:14b7:4d55 with SMTP id p2-20020a056402044200b0041614b74d55mr10148147edw.183.1646647411599; Mon, 07 Mar 2022 02:03:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646647411; cv=none; d=google.com; s=arc-20160816; b=PIVi/76VHdF/YDwOI/ZfKlQ/o5tuh3xHBoIw5D4Gyu1P7gt6GiPBWRgaEDDGhn2QiE JiOlm8ilX8YlBBzEWUeg+BXIniyg8GGO9P6pp2kDc04Z3GqAtf4R/4phMX+iZNjxXH9r g6V/JZQ5O6kxXgbBPC9awxmNZZ8duwyidHpluHStXKpg/JUw8bASQqSlQMKAsEpdZgqp KNq9RPDEjZMEzeA8g6VRBXRNe60aL6X2eEPggsCSqFScTfqUlcZU9Dw2/x5KBuymevrq TPBvQix0v3CmSRSLKlAtmu+g9riSMdxxJOyAho+qLQe0dsMaMTlS12oiuZapHauoLaPy Xhbg== 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=dZY0jv4+PfmijU+ef1INsNTu+3P0eDm1R8X7A/ij9NA=; b=cuz2FbEPqW8iZjwTp0p1fCVnMSFXVAgS0O872oWLvtPvQOLWcIVoZR/HojYUzZ4SYS RPQ87TsuuYDYr8PlM9I0GhgPWGKQ0Onsoe0PchXDaQ6YPDLebN3t03PgcfX+3V2N/RZ9 GcmRjOslYkQ2uZyU9qTX3cy8GYjaG72sSsiOl3SWzT1kfHjzYNWsBgyj+E3pxJ+PtntE aXF458DwFwzKhElgv8bPoVuDBVXWFMwKG41pMCnZWSvCXAbrbKoE30BUZh3Au1S8i2n0 fBhFgMlIG45jQQz3JEibYfZhOEXH6qb6Voz5NKtOOvjfdP4YYlCu4IwqJngsGihD80Cn rZVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=blArTWqR; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bf4-20020a0564021a4400b0041602994aaesi5570688edb.33.2022.03.07.02.03.09; Mon, 07 Mar 2022 02:03:31 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=blArTWqR; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236884AbiCGJZ6 (ORCPT + 99 others); Mon, 7 Mar 2022 04:25:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237091AbiCGJXY (ORCPT ); Mon, 7 Mar 2022 04:23:24 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C85B66AD3; Mon, 7 Mar 2022 01:21:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 33168B810CB; Mon, 7 Mar 2022 09:21:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 888EFC340F7; Mon, 7 Mar 2022 09:21:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646644907; bh=SMjhGzvyBQIr5ixAIOlOYHqg0n+x4DBNfeHbKsz0Z7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=blArTWqRzd+57tZJW5/YqkY3yCs6VgxczWU05uStvhDQoLmXFF0cwKAX174treJjA ayNglEa2nzGpdii2wGfjd72RC+QcopySFeXlF7c48xsPRv3KBzrcPg9u2ShJOmKZb2 Rz8yLBoORtm/TG0jhXNM2+96QEHtSBbDOCkl3LyI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Oleksandr Natalenko , Florian Westphal Subject: [PATCH 4.14 18/42] netfilter: nf_queue: dont assume sk is full socket Date: Mon, 7 Mar 2022 10:18:52 +0100 Message-Id: <20220307091636.681038579@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220307091636.146155347@linuxfoundation.org> References: <20220307091636.146155347@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Florian Westphal commit 747670fd9a2d1b7774030dba65ca022ba442ce71 upstream. There is no guarantee that state->sk refers to a full socket. If refcount transitions to 0, sock_put calls sk_free which then ends up with garbage fields. I'd like to thank Oleksandr Natalenko and Jiri Benc for considerable debug work and pointing out state->sk oddities. Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener") Tested-by: Oleksandr Natalenko Signed-off-by: Florian Westphal Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_queue.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) --- a/net/netfilter/nf_queue.c +++ b/net/netfilter/nf_queue.c @@ -44,6 +44,15 @@ void nf_unregister_queue_handler(struct } EXPORT_SYMBOL(nf_unregister_queue_handler); +static void nf_queue_sock_put(struct sock *sk) +{ +#ifdef CONFIG_INET + sock_gen_put(sk); +#else + sock_put(sk); +#endif +} + void nf_queue_entry_release_refs(struct nf_queue_entry *entry) { struct nf_hook_state *state = &entry->state; @@ -54,7 +63,7 @@ void nf_queue_entry_release_refs(struct if (state->out) dev_put(state->out); if (state->sk) - sock_put(state->sk); + nf_queue_sock_put(state->sk); #if IS_ENABLED(CONFIG_BRIDGE_NETFILTER) if (entry->skb->nf_bridge) { struct net_device *physdev;