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 439A03AAF69; Sat, 17 Oct 2026 16:57:18 +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=1792256239; cv=none; b=hx2WM8yYDslCFGxOmSCvSJ6ykbQQ0U4iasNSZdP6g7BNhgIpIba+cBe791NlcaKWXWc1MDNiBew+Yii0ppC0ybntBuKjkyoTrgEM5lrtHiN6VNIGAxKTkDqdTraZU8qERqMK/QTn51/0EKbXGAmqxVG9/ur58uAarGbp1MgDcJw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792256239; c=relaxed/simple; bh=hVrWB/JbIQ5Y2oEJcVMhNIwEq4fNc1zCG7eae9y9tqA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hx3zbtbBeVCVOY9h7BDZpr4WdZinj6n9rEoYMraJh9wd8IFO3Z8VNMhfkRBveSWkMRZ4/Isi8I61r+0NenCX67PpdkA9AO0VQDdDXXPbnvS5+IS+sI0tC18qeje4sp32vK/ynm2uB5tgeYi3BWn7aV8qqTOaR+fjQ+nLnkImtHI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=nW/h/yMK; 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="nW/h/yMK" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E2E41F000C4; Sat, 17 Oct 2026 16:57:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792256238; bh=/8o2mCzgl2JpqemyEaWfloQLsikwMGb7wqEPAaiTEg0=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=nW/h/yMKbGXAF0mxGC9kYCJ+08NvvSEaSP7Ym/uwpOTg0xbWCHySHUzvdbPqR+j5V V0p1Jf0xslMqlKMvKllA60y0R299RC/kk/cu7m+s07XxyuTqadBSpjkSeVXvOQGq0m P4WlUg2jfxh5fhHTMjb9pUo5oWt9I+ZMHBlIKOmM= 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.6 0171/1674] netfilter: nft_flow_offload: drop flowtable reference on init error path Date: Sat, 17 Oct 2026 17:40:43 +0200 Message-ID: <20261017160435.546726868@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160431.119607952@linuxfoundation.org> References: <20261017160431.119607952@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.6-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 @@ -416,6 +416,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; @@ -430,7 +431,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,