From patchwork Wed May 29 14:57:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1941311 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VqCCh0G2Qz20Tw for ; Thu, 30 May 2024 00:57:19 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1sCKjn-0001Xt-13; Wed, 29 May 2024 14:57:11 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sCKjk-0001Wq-Sn for kernel-team@lists.ubuntu.com; Wed, 29 May 2024 14:57:08 +0000 Received: from mail-oi1-f200.google.com (mail-oi1-f200.google.com [209.85.167.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id B97583F339 for ; Wed, 29 May 2024 14:57:08 +0000 (UTC) Received: by mail-oi1-f200.google.com with SMTP id 5614622812f47-3d1ba3543e8so2456761b6e.1 for ; Wed, 29 May 2024 07:57:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716994627; x=1717599427; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=USJE7Bw7JF7mXEP1qkjjdkZ1jNGZfn/hLkgke9kmcKw=; b=pk1yDrOEwzhdnCqMZr4mG0W2bdhHa9uy2AtcmOyL53Zvq04otBEIyFTURFPcHQ9lh+ I3MGMY2jxhmGKWXLVrFaOCGKpkoC4f31XR6I5cDh7aQl/Tn7KqIa9Y+0JAvg+K6C7qSw X4ubR29JRtzYPyvNl4ulXPh6laQxlSqZQ0+y/2ehF7Ko3TiaSVyRTrgWRhsyp8In+n4M T9kPZWtfJC3sf6K5oTeARH1ZfMBBfsMncE+eJogZ40MhEwn3FKjQG2cdorKgqAYCqNJf laMo8kfq19UKaftnrCGtMGHpNw+LIh/Viv79CccIrvDUWE+gOmuL6+XJg0YKlXoNYVi4 z/yA== X-Gm-Message-State: AOJu0Yyc/k8f1OmijymnYa0nVZZob/coLPW2i4wdMYs84wULsA8gYtp1 XbGittwxbH7vF24fPD+/vtMvYLfINfySmOJTF2mLWb7haN3kH7vKCmgsNwWI6SUaPHry+ZORtb5 L4i+gqSsMV250Sixazdjp8B/omYC78BxARqFbgDde9vziYgHg2GV7ztqG9wKcJXu3O9A5MLchl7 Hd0SQdfID56A== X-Received: by 2002:a05:6808:f8b:b0:3c3:d47b:e4cf with SMTP id 5614622812f47-3d1a745ade9mr19414186b6e.39.1716994627369; Wed, 29 May 2024 07:57:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFqLnK+N1ncHqeJboRcanOs4OZ+8q6FaUVl4coFONl1+IdWsJ9iVbg6zjkWry0r0XoVIdKe3Q== X-Received: by 2002:a05:6808:f8b:b0:3c3:d47b:e4cf with SMTP id 5614622812f47-3d1a745ade9mr19414162b6e.39.1716994626909; Wed, 29 May 2024 07:57:06 -0700 (PDT) Received: from smtp.gmail.com ([2001:67c:1562:8007::aac:48f9]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6ac162f2f35sm54855726d6.77.2024.05.29.07.57.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:57:06 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][F][PATCH v2 3/3] netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path Date: Wed, 29 May 2024 09:57:00 -0500 Message-Id: <20240529145700.19721-6-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240529145700.19721-1-bethany.jamison@canonical.com> References: <20240529145700.19721-1-bethany.jamison@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Pablo Neira Ayuso The commit mutex should not be released during the critical section between nft_gc_seq_begin() and nft_gc_seq_end(), otherwise, async GC worker could collect expired objects and get the released commit lock within the same GC sequence. nf_tables_module_autoload() temporarily releases the mutex to load module dependencies, then it goes back to replay the transaction again. Move it at the end of the abort phase after nft_gc_seq_end() is called. Cc: stable@vger.kernel.org Fixes: 720344340fb9 ("netfilter: nf_tables: GC transaction race with abort path") Reported-by: Kuan-Ting Chen Signed-off-by: Pablo Neira Ayuso (cherry picked from commit 0d459e2ffb541841714839e8228b845458ed3b27) CVE-2024-26925 Signed-off-by: Bethany Jamison --- net/netfilter/nf_tables_api.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index d9848f5edc788..4db8723ed7c51 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -7705,11 +7705,6 @@ static int __nf_tables_abort(struct net *net, enum nfnl_abort_action action) nf_tables_abort_release(trans); } - if (action == NFNL_ABORT_AUTOLOAD) - nf_tables_module_autoload(net); - else - nf_tables_module_autoload_cleanup(net); - return err; } @@ -7726,6 +7721,14 @@ static int nf_tables_abort(struct net *net, struct sk_buff *skb, WARN_ON_ONCE(!list_empty(&nft_net->commit_list)); + /* module autoload needs to happen after GC sequence update because it + * temporarily releases and grabs mutex again. + */ + if (action == NFNL_ABORT_AUTOLOAD) + nf_tables_module_autoload(net); + else + nf_tables_module_autoload_cleanup(net); + mutex_unlock(&nft_net->commit_mutex); return ret;