From patchwork Tue May 28 22:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1940821 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 4VpnN44M7yz23vF for ; Wed, 29 May 2024 08:33:07 +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 1sC5NM-0003pb-IU; Tue, 28 May 2024 22:33:00 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1sC5NG-0003lc-Li for kernel-team@lists.ubuntu.com; Tue, 28 May 2024 22:32:54 +0000 Received: from mail-ot1-f71.google.com (mail-ot1-f71.google.com [209.85.210.71]) (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-0.canonical.com (Postfix) with ESMTPS id 5CCF03FE40 for ; Tue, 28 May 2024 22:32:52 +0000 (UTC) Received: by mail-ot1-f71.google.com with SMTP id 46e09a7af769-6f8e9dee79dso1331868a34.3 for ; Tue, 28 May 2024 15:32:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716935570; x=1717540370; 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=mlDjRBID5MXrEySEtlnPczB0rArImYpwde03fxa72PY=; b=fUUaxA+boVgPE0XDKPdlBFGuGx5wy81iSuYr9U0qw+Edzo2RHbJIe5nYdeWB0XIVad 6+Ml0GJAc//0O1bJcj9j2qrw2UqmPAKYzyyk7JPTOXBpFOhBo7bUtkmPsbF8ioG6Fndn 6Gni0NPHERoJ3an8d7qtfjcQo0SY8MRzSW5+TeN0J/R+/R18METlIDT7nPADRCBQWtgY qeWwigEREvpXovNkDpytqQACOixejMkMZnSl8fvhf7hNwAytTgaHBCeFvbEnqPCYLr4C 4uAU/8qBhr8I/TefPOQ4KfLwi8VHNevip/LKO8jeqkmz3HC/uDlhIBcEF+2I4kto1US5 Bxcw== X-Gm-Message-State: AOJu0YxwxBc2k+XFDkwQ26QgkkBrwMYBR7rIgVCAGGDjICH9B8mruOXp yx6rrmWhilh+QhXv1XYY0kH2mj9TMRkWWUodi6X3PLpAfHCGqvQwwsw5q28MrVVu/kee/2iDzJx Iqxhz4L5aKTNmK9mRQZAx7k/gtGRzt57FZbGbKC4EK//BSzI4j54uOwB4FMBpRAZfa1HSAQ9KbT RdjkFnGpCV7Q== X-Received: by 2002:a9d:5619:0:b0:6f0:e4ee:51c with SMTP id 46e09a7af769-6f8d0aeecbemr14616997a34.21.1716935570180; Tue, 28 May 2024 15:32:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF72WRtu6q7Sw2/0e6aLRzx/wZVfep1CiZekojjIbQdmKGxxz/JvLlZ630UfbgG1a6GjM4D/Q== X-Received: by 2002:a9d:5619:0:b0:6f0:e4ee:51c with SMTP id 46e09a7af769-6f8d0aeecbemr14616988a34.21.1716935569828; Tue, 28 May 2024 15:32:49 -0700 (PDT) Received: from smtp.gmail.com ([2600:1700:564:3480:97ae:ad19:5b77:5447]) by smtp.gmail.com with ESMTPSA id 46e09a7af769-6f8d0e99dfdsm2083604a34.80.2024.05.28.15.32.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 15:32:49 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 2/2] netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path Date: Tue, 28 May 2024 17:32:44 -0500 Message-Id: <20240528223247.53626-3-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240528223247.53626-1-bethany.jamison@canonical.com> References: <20240528223247.53626-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 59e0953c0f5f7..213c479cbb1d3 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -10474,11 +10474,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; } @@ -10495,6 +10490,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;