From patchwork Wed May 29 14:56:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1941310 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 4VqCCh01W0z20Pb 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 1sCKjk-0001Wp-Qr; Wed, 29 May 2024 14:57:08 +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 1sCKji-0001WL-1o for kernel-team@lists.ubuntu.com; Wed, 29 May 2024 14:57:06 +0000 Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) (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 E477A3F16B for ; Wed, 29 May 2024 14:57:05 +0000 (UTC) Received: by mail-qv1-f70.google.com with SMTP id 6a1803df08f44-6ad706fab2aso24919226d6.1 for ; Wed, 29 May 2024 07:57:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716994624; x=1717599424; 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=EhBSCLuHiVOPEKqe7rRVZ/tTl2elkQ9B/WVgTXq2uWGCShk3iCcOQM9y1M5xSrrYf+ /v6dZ/fBDIBpWLEDwB5ckJoPR8soVnXhtRBon/i8oBMLDXCD03Rwd3dWSiOWnmOqad3n QBcNBQOpW+YH2oRIyX7D6B3xEwPeiqBUscC40Y0DjGbhdFMNg5u2pJaoqXSkXQ9yddPB Hkl7gpd14DKO4yiyr8RWDhYtjNrkGp+UjbkeCkBV6psMa9mkf3skOp2nW1dyTYX5r4uq gohT4RmCZuDDbSQ1uPRgcThsAIzEDakL3i/RW/ITgzIbyTuAvvTrkW4HyaKJzv3ayWhB v2ug== X-Gm-Message-State: AOJu0YzqL+2PKIw13GAGhv6W0fn63FvfZQ9BjC6Fn6MPjU7Jx8ygCYHv +IfJXTH+Z5uRhwfMP/qrIZdceer0X+i71LFVWfAp+vSoc3Q6JpGZElhCJolKLzB/H452TeX4CSY sX86tX2OTEgyXK78lWxnrwQ9BTWR/Is7YZNpY6bhfSuaVB9C894xiENzTlJnh21Sb8vbchBSws/ tLkEJvB+0g8A== X-Received: by 2002:a05:6214:21af:b0:6ad:8af3:6100 with SMTP id 6a1803df08f44-6ad8af3611fmr96362216d6.51.1716994624631; Wed, 29 May 2024 07:57:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFPFkpDtfBgMGTyn2D0dJnxvd4jG9IOCpDNRgISmsATVp4HkwT20dsuOaTeRCBg4amYPcKiyQ== X-Received: by 2002:a05:6214:21af:b0:6ad:8af3:6100 with SMTP id 6a1803df08f44-6ad8af3611fmr96361976d6.51.1716994624240; Wed, 29 May 2024 07:57:04 -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.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 07:57:04 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH v2 2/2] netfilter: nf_tables: release mutex after nft_gc_seq_end from abort path Date: Wed, 29 May 2024 09:56:57 -0500 Message-Id: <20240529145700.19721-3-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 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;