From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795051966; b=E7VcAw4CHhXHUdcROgplv81OYi+HdI3FKw6ns2o5pI6Ya3C9ADOCE7O1On8hndLj9VUn 4JkgRVHKxRBgfpQZxVY8cL7BhgbtHKseh0/rusKiSUlQItqlmQgAgzAqcXd4vsTAnjAfF CyA8B6qogdSir8mAMAHo5m9RShTrOCErWpPzNpRxwzQ4Cv1nzriPLfrHtxWi5+ecUUAuX YODqjvGK8SnlQbKSNe5MtWdW4ox7RG6S/Bt7E1zhCEiiwLynwHqz4iuHbUQDt58emEjeL j7dboMxtl08ELCnhmnNyBj7Q79Qf70b452yzhRU85PHl+Ioe7LiuPEnGa1I0liXNx5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795051966; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=lvhOYJ8ovms8Sg7+LWsQiPHG5RSimXy8iNP5HOZtLQg=; b=SIugnAmBQRtbYwm4Pn/zaRXh+59m9cM9OcECM6VfogmP1DYeqJ6gjxvCO5inHy4c32BB binqVtpaKc1xG8Ady866I+PL61YBEDfJKRzGyfqykFGWorJyBLMyM2k63g/n6rU3KKXHL 74O4iosKdWoZFDu/NO0MU1O3TaMnilMTw+OVnBX47AMUGbM8IXvlwXILZIgF7B2SmTkE5 lzOfDK/gw4k60JnXoPboriyCNHXRoL+8M/20gi90Z620BcfBqEonJH+iVsvWHU2NhKvCr h6PcuTenzHcMI+yM0LVHrRRNTYtoy00zAxKmQIdo0Kyr8CXI7Xe6n16y5LMjhRsyd+Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BT50Y0vN; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22FDA606A332; Thu, 19 Nov 2026 01:32:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BT50Y0vN Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7ABF71F000C4; Thu, 19 Nov 2026 01:32:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795051966; bh=lvhOYJ8ovms8Sg7+LWsQiPHG5RSimXy8iNP5HOZtLQg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BT50Y0vNyMPj8yZoViCNNfpWLB8CYElfzkE72r2acV3NEftwjEAWxQlb19TRucaon lcxJu2a5vMgkiNL/NdzYzp+TsJzRRs2RgmOEHGVayS/PfiqjSkwBzKU/++fHqhvPH+ AyzuqFupdanpB5NXz/IWPzOplSa99aage5t6cbOs= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Xin Liu , Yucheng Lu , Yuhang Zheng , Ren Wei , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.15 0395/2214] net/sched: cls_flower: avoid stale mask references after delete Date: Wed, 18 Nov 2026 15:34:31 +0100 Message-ID: <20261118150026.463577967@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150009.797899913@linuxfoundation.org> References: <20261118150009.797899913@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yuhang Zheng [ Upstream commit 58f7989da6e715ce834ac861b7ba6ae9f9bdb098 ] Flower releases a mask reference when a filter is removed from the classifier. The filter object can remain alive while dump, walk, or hardware reoffload paths hold a reference to it. Those paths can then dereference f->mask after the mask has already been released. Keep the mask reference until the filter reference count reaches zero. Release the mask synchronously from the final __fl_put() while the caller still holds the tcf_proto reference, and leave the existing RCU work to free the mask. This keeps the mask available to every reader that still holds the filter. The filter is still removed from the classifier indexes immediately. Therefore, a deleted filter can temporarily retain an otherwise empty mask; fl_delete() uses the handle IDR, rather than the mask list, to determine whether the classifier has become empty. Failed mask assignment can leave fnew->mask as an error or borrowed pointer without an owned mask reference. Clear it before the common failure path so the final put cannot release an unowned reference. This fix does not add fields, snapshots, or per-filter memory. Fixes: 92149190067d ("net: sched: flower: set unlocked flag for flower proto ops") Cc: stable@vger.kernel.org Reported-by: Xin Liu Tested-by: Yucheng Lu Signed-off-by: Yuhang Zheng Signed-off-by: Ren Wei Link: https://patch.msgid.link/20261012010720.2248662-2-n05ec@lzu.edu.cn Signed-off-by: Jakub Kicinski [ sashal: Changed jumps to unbind_filter to use the existing errout cleanup label. ] Signed-off-by: Sasha Levin --- net/sched/cls_flower.c | 49 ++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/net/sched/cls_flower.c b/net/sched/cls_flower.c index a369a426f90f2..b9bdaa1f8c0e3 100644 --- a/net/sched/cls_flower.c +++ b/net/sched/cls_flower.c @@ -504,15 +504,22 @@ static void fl_hw_update_stats(struct tcf_proto *tp, struct cls_fl_filter *f, cls_flower.stats.used_hw_stats_valid); } -static void __fl_put(struct cls_fl_filter *f) +static bool __fl_put(struct tcf_proto *tp, struct cls_fl_filter *f) { + bool last = false; + if (!refcount_dec_and_test(&f->refcnt)) - return; + return false; + + if (f->mask) + last = fl_mask_put(fl_head_dereference(tp), f->mask); if (tcf_exts_get_net(&f->exts)) tcf_queue_work(&f->rwork, fl_destroy_filter_work); else __fl_destroy_filter(f); + + return last; } static struct cls_fl_filter *__fl_get(struct cls_fl_head *head, u32 handle) @@ -549,11 +556,10 @@ static int __fl_delete(struct tcf_proto *tp, struct cls_fl_filter *f, list_del_rcu(&f->list); spin_unlock(&tp->lock); - *last = fl_mask_put(head, f->mask); if (!tc_skip_hw(f->flags)) fl_hw_destroy_filter(tp, f, rtnl_held, extack); tcf_unbind_filter(tp, &f->res); - __fl_put(f); + *last = __fl_put(tp, f); return 0; } @@ -594,7 +600,7 @@ static void fl_put(struct tcf_proto *tp, void *arg) { struct cls_fl_filter *f = arg; - __fl_put(f); + __fl_put(tp, f); } static void *fl_get(struct tcf_proto *tp, u32 handle) @@ -2063,12 +2069,14 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, goto errout; err = fl_check_assign_mask(head, fnew, fold, mask); - if (err) + if (err) { + fnew->mask = NULL; goto errout; + } err = fl_ht_insert_unique(fnew, fold, &in_ht); if (err) - goto errout_mask; + goto errout; if (!tc_skip_hw(fnew->flags)) { err = fl_hw_replace_filter(tp, fnew, rtnl_held, extack); @@ -2120,7 +2128,6 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, spin_unlock(&tp->lock); - fl_mask_put(head, fold->mask); if (!tc_skip_hw(fold->flags)) fl_hw_destroy_filter(tp, fold, rtnl_held, NULL); tcf_unbind_filter(tp, &fold->res); @@ -2128,7 +2135,7 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, * after this. */ refcount_dec(&fold->refcnt); - __fl_put(fold); + __fl_put(tp, fold); } else { if (handle) { /* user specifies a handle and it doesn't exist */ @@ -2173,17 +2180,15 @@ static int fl_change(struct net *net, struct sk_buff *in_skb, if (in_ht) rhashtable_remove_fast(&fnew->mask->ht, &fnew->ht_node, fnew->mask->filter_ht_params); -errout_mask: - fl_mask_put(head, fnew->mask); errout: - __fl_put(fnew); + __fl_put(tp, fnew); errout_tb: kfree(tb); errout_mask_alloc: tcf_queue_work(&mask->rwork, fl_uninit_mask_free_work); errout_fold: if (fold) - __fl_put(fold); + __fl_put(tp, fold); return err; } @@ -2196,8 +2201,10 @@ static int fl_delete(struct tcf_proto *tp, void *arg, bool *last, int err = 0; err = __fl_delete(tp, f, &last_on_mask, rtnl_held, extack); - *last = list_empty(&head->masks); - __fl_put(f); + spin_lock(&tp->lock); + *last = idr_is_empty(&head->handle_idr); + spin_unlock(&tp->lock); + __fl_put(tp, f); return err; } @@ -2219,12 +2226,12 @@ static void fl_walk(struct tcf_proto *tp, struct tcf_walker *arg, rcu_read_unlock(); if (arg->fn(tp, f, arg) < 0) { - __fl_put(f); + __fl_put(tp, f); arg->stop = 1; rcu_read_lock(); break; } - __fl_put(f); + __fl_put(tp, f); arg->count++; rcu_read_lock(); } @@ -2275,7 +2282,7 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, cls_flower.rule = flow_rule_alloc(tcf_exts_num_actions(&f->exts)); if (!cls_flower.rule) { - __fl_put(f); + __fl_put(tp, f); return -ENOMEM; } @@ -2293,7 +2300,7 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, kfree(cls_flower.rule); if (tc_skip_sw(f->flags)) { NL_SET_ERR_MSG_MOD(extack, "Failed to setup flow action"); - __fl_put(f); + __fl_put(tp, f); return err; } goto next_flow; @@ -2309,11 +2316,11 @@ static int fl_reoffload(struct tcf_proto *tp, bool add, flow_setup_cb_t *cb, kfree(cls_flower.rule); if (err) { - __fl_put(f); + __fl_put(tp, f); return err; } next_flow: - __fl_put(f); + __fl_put(tp, f); } return 0; -- 2.53.0