Skip to content

Commit 1e2ed2a

Browse files
pvts-matPlaidCat
authored andcommitted
net/sched: flower: Fix chain template offload
jira VULN-8198 cve CVE-2024-26669 commit-author Ido Schimmel <idosch@nvidia.com> commit 32f2a0a upstream-diff | Adding `tmplt_reoffload' field to the `tcf_proto_ops' struct breaks kABI for the whitelisted symbols: - flow_block_cb_alloc - flow_block_cb_free - flow_block_cb_lookup - flow_block_cb_setup_simple - flow_indr_block_cb_alloc - flow_indr_dev_register - flow_indr_dev_unregister - qdisc_reset Added it with the `RH_KABI_BROKEN_INSERT' tag anyway because `tcf_proto_ops' was not put on the whitelist directly and changing it affects kABI only through the `Qdisc' struct used as parameter in the functions listed above. Since `register_tcf_proto_ops' isn't in the kABI stablelist, and it is the only way a `tcf_proto_ops' pointer can be reached through struct `Qdisc', there's no kABI breakage in the strictest sense. When a qdisc is deleted from a net device the stack instructs the underlying driver to remove its flow offload callback from the associated filter block using the 'FLOW_BLOCK_UNBIND' command. The stack then continues to replay the removal of the filters in the block for this driver by iterating over the chains in the block and invoking the 'reoffload' operation of the classifier being used. In turn, the classifier in its 'reoffload' operation prepares and emits a 'FLOW_CLS_DESTROY' command for each filter. However, the stack does not do the same for chain templates and the underlying driver never receives a 'FLOW_CLS_TMPLT_DESTROY' command when a qdisc is deleted. This results in a memory leak [1] which can be reproduced using [2]. Fix by introducing a 'tmplt_reoffload' operation and have the stack invoke it with the appropriate arguments as part of the replay. Implement the operation in the sole classifier that supports chain templates (flower) by emitting the 'FLOW_CLS_TMPLT_{CREATE,DESTROY}' command based on whether a flow offload callback is being bound to a filter block or being unbound from one. As far as I can tell, the issue happens since cited commit which reordered tcf_block_offload_unbind() before tcf_block_flush_all_chains() in __tcf_block_put(). The order cannot be reversed as the filter block is expected to be freed after flushing all the chains. [1] unreferenced object 0xffff888107e28800 (size 2048): comm "tc", pid 1079, jiffies 4294958525 (age 3074.287s) hex dump (first 32 bytes): b1 a6 7c 11 81 88 ff ff e0 5b b3 10 81 88 ff ff ..|......[...... 01 00 00 00 00 00 00 00 e0 aa b0 84 ff ff ff ff ................ backtrace: [<ffffffff81c06a68>] __kmem_cache_alloc_node+0x1e8/0x320 [<ffffffff81ab374e>] __kmalloc+0x4e/0x90 [<ffffffff832aec6d>] mlxsw_sp_acl_ruleset_get+0x34d/0x7a0 [<ffffffff832bc195>] mlxsw_sp_flower_tmplt_create+0x145/0x180 [<ffffffff832b2e1a>] mlxsw_sp_flow_block_cb+0x1ea/0x280 [<ffffffff83a10613>] tc_setup_cb_call+0x183/0x340 [<ffffffff83a9f85a>] fl_tmplt_create+0x3da/0x4c0 [<ffffffff83a22435>] tc_ctl_chain+0xa15/0x1170 [<ffffffff838a863c>] rtnetlink_rcv_msg+0x3cc/0xed0 [<ffffffff83ac87f0>] netlink_rcv_skb+0x170/0x440 [<ffffffff83ac6270>] netlink_unicast+0x540/0x820 [<ffffffff83ac6e28>] netlink_sendmsg+0x8d8/0xda0 [<ffffffff83793def>] ____sys_sendmsg+0x30f/0xa80 [<ffffffff8379d29a>] ___sys_sendmsg+0x13a/0x1e0 [<ffffffff8379d50c>] __sys_sendmsg+0x11c/0x1f0 [<ffffffff843b9ce0>] do_syscall_64+0x40/0xe0 unreferenced object 0xffff88816d2c0400 (size 1024): comm "tc", pid 1079, jiffies 4294958525 (age 3074.287s) hex dump (first 32 bytes): 40 00 00 00 00 00 00 00 57 f6 38 be 00 00 00 00 @.......W.8..... 10 04 2c 6d 81 88 ff ff 10 04 2c 6d 81 88 ff ff ..,m......,m.... backtrace: [<ffffffff81c06a68>] __kmem_cache_alloc_node+0x1e8/0x320 [<ffffffff81ab36c1>] __kmalloc_node+0x51/0x90 [<ffffffff81a8ed96>] kvmalloc_node+0xa6/0x1f0 [<ffffffff82827d03>] bucket_table_alloc.isra.0+0x83/0x460 [<ffffffff82828d2b>] rhashtable_init+0x43b/0x7c0 [<ffffffff832aed48>] mlxsw_sp_acl_ruleset_get+0x428/0x7a0 [<ffffffff832bc195>] mlxsw_sp_flower_tmplt_create+0x145/0x180 [<ffffffff832b2e1a>] mlxsw_sp_flow_block_cb+0x1ea/0x280 [<ffffffff83a10613>] tc_setup_cb_call+0x183/0x340 [<ffffffff83a9f85a>] fl_tmplt_create+0x3da/0x4c0 [<ffffffff83a22435>] tc_ctl_chain+0xa15/0x1170 [<ffffffff838a863c>] rtnetlink_rcv_msg+0x3cc/0xed0 [<ffffffff83ac87f0>] netlink_rcv_skb+0x170/0x440 [<ffffffff83ac6270>] netlink_unicast+0x540/0x820 [<ffffffff83ac6e28>] netlink_sendmsg+0x8d8/0xda0 [<ffffffff83793def>] ____sys_sendmsg+0x30f/0xa80 [2] # tc qdisc add dev swp1 clsact # tc chain add dev swp1 ingress proto ip chain 1 flower dst_ip 0.0.0.0/32 # tc qdisc del dev swp1 clsact # devlink dev reload pci/0000:06:00.0 Fixes: bbf7383 ("net: sched: traverse chains in block with tcf_get_next_chain()") Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> (cherry picked from commit 32f2a0a) Signed-off-by: Marcin Wcisło <marcin.wcislo@conclusive.pl>
1 parent 3713f88 commit 1e2ed2a

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

include/net/sch_generic.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/rwsem.h>
1717
#include <linux/atomic.h>
1818
#include <linux/hashtable.h>
19+
#include <linux/rh_kabi.h>
1920
#include <net/gen_stats.h>
2021
#include <net/rtnetlink.h>
2122
#include <net/flow_offload.h>
@@ -376,6 +377,10 @@ struct tcf_proto_ops {
376377
struct nlattr **tca,
377378
struct netlink_ext_ack *extack);
378379
void (*tmplt_destroy)(void *tmplt_priv);
380+
RH_KABI_BROKEN_INSERT(void (*tmplt_reoffload)(struct tcf_chain *chain,
381+
bool add,
382+
flow_setup_cb_t *cb,
383+
void *cb_priv))
379384
struct tcf_exts * (*get_exts)(const struct tcf_proto *tp,
380385
u32 handle);
381386

net/sched/cls_api.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1536,6 +1536,9 @@ tcf_block_playback_offloads(struct tcf_block *block, flow_setup_cb_t *cb,
15361536
chain_prev = chain,
15371537
chain = __tcf_get_next_chain(block, chain),
15381538
tcf_chain_put(chain_prev)) {
1539+
if (chain->tmplt_ops && add)
1540+
chain->tmplt_ops->tmplt_reoffload(chain, true, cb,
1541+
cb_priv);
15391542
for (tp = __tcf_get_next_proto(chain, NULL); tp;
15401543
tp_prev = tp,
15411544
tp = __tcf_get_next_proto(chain, tp),
@@ -1551,6 +1554,9 @@ tcf_block_playback_offloads(struct tcf_block *block, flow_setup_cb_t *cb,
15511554
goto err_playback_remove;
15521555
}
15531556
}
1557+
if (chain->tmplt_ops && !add)
1558+
chain->tmplt_ops->tmplt_reoffload(chain, false, cb,
1559+
cb_priv);
15541560
}
15551561

15561562
return 0;
@@ -2950,7 +2956,8 @@ static int tc_chain_tmplt_add(struct tcf_chain *chain, struct net *net,
29502956
ops = tcf_proto_lookup_ops(name, true, extack);
29512957
if (IS_ERR(ops))
29522958
return PTR_ERR(ops);
2953-
if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump) {
2959+
if (!ops->tmplt_create || !ops->tmplt_destroy || !ops->tmplt_dump ||
2960+
!ops->tmplt_reoffload) {
29542961
NL_SET_ERR_MSG(extack, "Chain templates are not supported with specified classifier");
29552962
module_put(ops->owner);
29562963
return -EOPNOTSUPP;

net/sched/cls_flower.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,28 @@ static void fl_tmplt_destroy(void *tmplt_priv)
26952695
kfree(tmplt);
26962696
}
26972697

2698+
static void fl_tmplt_reoffload(struct tcf_chain *chain, bool add,
2699+
flow_setup_cb_t *cb, void *cb_priv)
2700+
{
2701+
struct fl_flow_tmplt *tmplt = chain->tmplt_priv;
2702+
struct flow_cls_offload cls_flower = {};
2703+
2704+
cls_flower.rule = flow_rule_alloc(0);
2705+
if (!cls_flower.rule)
2706+
return;
2707+
2708+
cls_flower.common.chain_index = chain->index;
2709+
cls_flower.command = add ? FLOW_CLS_TMPLT_CREATE :
2710+
FLOW_CLS_TMPLT_DESTROY;
2711+
cls_flower.cookie = (unsigned long) tmplt;
2712+
cls_flower.rule->match.dissector = &tmplt->dissector;
2713+
cls_flower.rule->match.mask = &tmplt->mask;
2714+
cls_flower.rule->match.key = &tmplt->dummy_key;
2715+
2716+
cb(TC_SETUP_CLSFLOWER, &cls_flower, cb_priv);
2717+
kfree(cls_flower.rule);
2718+
}
2719+
26982720
static int fl_dump_key_val(struct sk_buff *skb,
26992721
void *val, int val_type,
27002722
void *mask, int mask_type, int len)
@@ -3596,6 +3618,7 @@ static struct tcf_proto_ops cls_fl_ops __read_mostly = {
35963618
.bind_class = fl_bind_class,
35973619
.tmplt_create = fl_tmplt_create,
35983620
.tmplt_destroy = fl_tmplt_destroy,
3621+
.tmplt_reoffload = fl_tmplt_reoffload,
35993622
.tmplt_dump = fl_tmplt_dump,
36003623
.get_exts = fl_get_exts,
36013624
.owner = THIS_MODULE,

0 commit comments

Comments
 (0)