Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp1105683rdb; Wed, 6 Dec 2023 08:43:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDQ28P0DyTbayn3CV++gqJVzMQbnYz1U0wMr9QCdfRJjcf4Kjy46I1vgF/yV58Unm7PitT X-Received: by 2002:a17:902:ba8f:b0:1d0:6ffd:6101 with SMTP id k15-20020a170902ba8f00b001d06ffd6101mr1237939pls.35.1701880999643; Wed, 06 Dec 2023 08:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701880999; cv=none; d=google.com; s=arc-20160816; b=rGq7wD1uq8S4Hn37D5rJEo/K7q9YS2CCe/gCdpF0x/2kxeqGba6hizhgWp7PQWWi3c sKudsaraT/iaCmMEXjf1Y//zskFsKXjJ/ps+E035UIxUbYEsJ7vhxWKIF8U7igeFrXUz d3s01eAqbAg6eVgiA7bc80dUZLeeROm2p96QqKAE07JL1YcR1lKZUTQLGW7IiqWovNt7 Rm2SIpTOw9aJjlQ75g55GCnluP/kG3sEYp35eIEFe5wz5qERNo6HoGRFXxo5DzVHOmD8 Xku4O815HXxkZZ4nPSztRqbGjhWBZMtiWxKmWbrCt/7XsYuR8J4P9ncZEoqc2KYU9aUY Gung== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:to :from:date; bh=PpN8Y48ijjt+jxlvh0T6UlUzWJXWU3p324m5CdTkK8U=; fh=Ru2vETNNpXQr+6WQ7KlVmT53q0+AWYfSblqEhJA3rAc=; b=nEoylSv2ur8n1Fq24OAP3ZnYufluXQdWRGX186qQUAznNczXmPncZC1iBEKdQZyYE/ vjdWlVnliAKHgPB7N6rQlBP4ReneBhQoQQUVmJKY2JH+CE3Bf0OYNk4CfSnpNuX7GXv/ AlKDeP1uvcqlCpHNxqndqw+qQSgOiILRPQbe8DYEUzMd0gApwjLXxo9na7+EDdpAno8v vthb1P3UAweeuj1WCPf2TuCH0X8eVy3mTq3FFtNAHrOLqniR2j9LmgBcRX39p8zycBja MwbwptFFwSQ9tosq6D59rg9VcPCyiFBZzGL8G3RwEBMxXtJajI9quRr1Nf01B3nYMlMb 8Ztw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id z15-20020a1709027e8f00b001cfc048af27si36164pla.584.2023.12.06.08.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:43:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 8D2998369F62; Wed, 6 Dec 2023 08:43:16 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378480AbjLFQmu (ORCPT + 99 others); Wed, 6 Dec 2023 11:42:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230028AbjLFQms (ORCPT ); Wed, 6 Dec 2023 11:42:48 -0500 Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09F0AD51; Wed, 6 Dec 2023 08:42:48 -0800 (PST) Received: from [78.30.43.141] (port=54118 helo=gnumonks.org) by ganesha.gnumonks.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rAuyx-003xzA-MK; Wed, 06 Dec 2023 17:42:46 +0100 Date: Wed, 6 Dec 2023 17:42:42 +0100 From: Pablo Neira Ayuso To: Phil Sutter , Jann Horn , Jozsef Kadlecsik , Florian Westphal , netfilter-devel , coreteam@netfilter.org, Christian Brauner , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Network Development , kernel list Subject: Re: Is xt_owner's owner_mt() racy with sock_orphan()? [worse with new TYPESAFE_BY_RCU file lifetime?] Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Score: -1.9 (-) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Wed, 06 Dec 2023 08:43:16 -0800 (PST) On Tue, Dec 05, 2023 at 10:40:15PM +0100, Phil Sutter wrote: > Hi, > > On Tue, Dec 05, 2023 at 06:08:29PM +0100, Jann Horn wrote: > > On Tue, Dec 5, 2023 at 5:40 PM Jann Horn wrote: > > > > > > Hi! > > > > > > I think this code is racy, but testing that seems like a pain... > > > > > > owner_mt() in xt_owner runs in context of a NF_INET_LOCAL_OUT or > > > NF_INET_POST_ROUTING hook. It first checks that sk->sk_socket is > > > non-NULL, then checks that sk->sk_socket->file is non-NULL, then > > > accesses the ->f_cred of that file. > > > > > > I don't see anything that protects this against a concurrent > > > sock_orphan(), which NULLs out the sk->sk_socket pointer, if we're in > > > > Ah, and all the other users of ->sk_socket in net/netfilter/ do it > > under the sk_callback_lock... so I guess the fix would be to add the > > same in owner_mt? > > Sounds reasonable, although I wonder how likely a socket is to > orphan while netfilter is processing a packet it just sent. > > How about the attached patch? Not sure what hash to put into a Fixes: > tag given this is a day 1 bug and ipt_owner/ip6t_owner predate git. > > Thanks, Phil > From 3e28490e43b04d49e6e7f145a70fff7dd42c8cc5 Mon Sep 17 00:00:00 2001 > From: Phil Sutter > Date: Tue, 5 Dec 2023 21:58:12 +0100 > Subject: [nf PATCH] netfilter: xt_owner: Fix for unsafe access of sk->sk_socket > > A concurrently running sock_orphan() may NULL the sk_socket pointer in > between check and deref. Follow other users (like nft_meta.c for > instance) and acquire sk_callback_lock before dereferencing sk_socket. For the record, I have placed this patch in nf.git Thanks.