From: Al Viro <v...@zeniv.linux.org.uk> ... and disallow deleting or linking to such
Signed-off-by: Al Viro <v...@zeniv.linux.org.uk> --- net/sched/cls_u32.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c index 3f985f29ef30..9ea5f2be907b 100644 --- a/net/sched/cls_u32.c +++ b/net/sched/cls_u32.c @@ -91,6 +91,7 @@ struct tc_u_hnode { */ struct tc_u_knode __rcu *ht[1]; }; +#define TCA_CLS_FLAGS_U32_ROOT (1<<8) struct tc_u_common { struct tc_u_hnode __rcu *hlist; @@ -377,6 +378,7 @@ static int u32_init(struct tcf_proto *tp) root_ht->refcnt++; root_ht->handle = tp_c ? gen_new_htid(tp_c, root_ht) : 0x80000000; root_ht->prio = tp->prio; + root_ht->flags = TCA_CLS_FLAGS_U32_ROOT; idr_init(&root_ht->handle_idr); if (tp_c == NULL) { @@ -491,7 +493,8 @@ static void u32_clear_hw_hnode(struct tcf_proto *tp, struct tc_u_hnode *h, struct tcf_block *block = tp->chain->block; struct tc_cls_u32_offload cls_u32 = {}; - tc_cls_common_offload_init(&cls_u32.common, tp, h->flags, extack); + tc_cls_common_offload_init(&cls_u32.common, tp, + h->flags & ~TCA_CLS_FLAGS_U32_ROOT, extack); cls_u32.command = TC_CLSU32_DELETE_HNODE; cls_u32.hnode.divisor = h->divisor; cls_u32.hnode.handle = h->handle; @@ -693,7 +696,7 @@ static int u32_delete(struct tcf_proto *tp, void *arg, bool *last, goto out; } - if (root_ht == ht) { + if (ht->flags & TCA_CLS_FLAGS_U32_ROOT) { NL_SET_ERR_MSG_MOD(extack, "Not allowed to delete root node"); return -EINVAL; } @@ -795,6 +798,10 @@ static int u32_set_parms(struct net *net, struct tcf_proto *tp, NL_SET_ERR_MSG_MOD(extack, "Link hash table not found"); return -EINVAL; } + if (ht_down->flags & TCA_CLS_FLAGS_U32_ROOT) { + NL_SET_ERR_MSG_MOD(extack, "Not linke to root node"); + return -EINVAL; + } ht_down->refcnt++; } @@ -1214,7 +1221,8 @@ static int u32_reoffload_hnode(struct tcf_proto *tp, struct tc_u_hnode *ht, struct tc_cls_u32_offload cls_u32 = {}; int err; - tc_cls_common_offload_init(&cls_u32.common, tp, ht->flags, extack); + tc_cls_common_offload_init(&cls_u32.common, tp, + ht->flags & ~TCA_CLS_FLAGS_U32_ROOT, extack); cls_u32.command = add ? TC_CLSU32_NEW_HNODE : TC_CLSU32_DELETE_HNODE; cls_u32.hnode.divisor = ht->divisor; cls_u32.hnode.handle = ht->handle; -- 2.11.0