From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 60751331ED5; Fri, 9 Oct 2026 14:16:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791555374; cv=none; b=Z/i3LMvbr4P8ml5cMENRpb5xm3RT7jAxYBYMhtF+vspQC59wemwNXRnAQhiQtPv7QUOEsIoPbji04Z50mTkRpXwPWbrz4Z/lQ2707Eeu0lHTumUr/d6FeSmHIGYBiL2RhkKCKRWu+eUkfl+XlDl5pnsU/hBmBLlCkFt9geNiTJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791555374; c=relaxed/simple; bh=Oq8kr7zr5OsriisctF/QyClySup9B2IamwD48aiR72k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJYRzQz2y3dWKKjmhdnTTle59BZSu6odbiVat4Xufv1VQaT1zuBUFhwwzoEGCo8G4XIVGXxYZHTYrQPOVk6Lq4VGxJmPLfevTAjzI818jV4qhpJzB3HyQBcM6QibWPxCjryrB8tqeGC7ehZc4q+nnkjusGE6ygIK6MbJ+oCydPM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=NtHJLAyG; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="NtHJLAyG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22AFB1F00898; Fri, 9 Oct 2026 14:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1791555367; bh=+zsv/1Q/Y+Rvx81dBYJXq6Rg7Y7mW7B638bnHrw3Sng=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NtHJLAyGzruGydu2TRDAkOoQ3pTwvs+rMRrLvEjOXZ7P2bZr/vhfnODmylZ1Y9iVm 1NBJpK64zPq9ZXQ7I9YSdp9hUkheylGIH30B+k/rjAaGXS2fHCQx45ZeptSnp4pUtt lod8fbdniAFi56XajIC9cvjnMvuoUKDJfgHZDeG0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, TencentOS Corvus AI , Aohan Mei , Pablo Neira Ayuso Subject: [PATCH 6.18 034/403] netfilter: nft_flow_offload: drop flowtable reference on init error path Date: Fri, 9 Oct 2026 16:06:35 +0200 Message-ID: <20261009140952.908273276@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261009140952.119038291@linuxfoundation.org> References: <20261009140952.119038291@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aohan Mei commit 747928b5d4ff8c8de55138a54c13980e4bb88578 upstream. nft_flow_offload_init() bumps the flowtable use count with nft_use_inc() before calling nf_ct_netns_get(). When the latter fails, the error is returned as-is and the reference is leaked. The upper layers do not balance it either: nf_tables_newexpr() clears expr->ops when the expression init callback fails, so the nft_expr_more() iteration in nft_rule_expr_deactivate() and nf_tables_rule_destroy() stops right before the failed expression and its ->destroy callback, which would drop the reference, never runs. Each failed rule addition therefore leaks one flowtable reference and the flowtable can no longer be removed: NFT_MSG_DELFLOWTABLE keeps reporting -EBUSY even though no rule references it. Save the nf_ct_netns_get() return value and undo the nft_use_inc() when it fails, restoring the inc/dec pairing within nft_flow_offload_init() itself. Fixes: a3c90f7a2323 ("netfilter: nf_tables: flow offload expression") Reported-by: TencentOS Corvus AI Cc: stable@vger.kernel.org Assisted-by: CodeBuddy:Kimi-K3 Signed-off-by: Aohan Mei Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nft_flow_offload.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/net/netfilter/nft_flow_offload.c +++ b/net/netfilter/nft_flow_offload.c @@ -159,6 +159,7 @@ static int nft_flow_offload_init(const s struct nft_flow_offload *priv = nft_expr_priv(expr); u8 genmask = nft_genmask_next(ctx->net); struct nft_flowtable *flowtable; + int err; if (!tb[NFTA_FLOW_TABLE_NAME]) return -EINVAL; @@ -173,7 +174,11 @@ static int nft_flow_offload_init(const s priv->flowtable = flowtable; - return nf_ct_netns_get(ctx->net, ctx->family); + err = nf_ct_netns_get(ctx->net, ctx->family); + if (err < 0) + nft_use_dec(&flowtable->use); + + return err; } static void nft_flow_offload_deactivate(const struct nft_ctx *ctx,