From: Jamal Hadi Salim <jhs@mojatatu.com>
To: Cong Wang <xiyou.wangcong@gmail.com>, netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>
Subject: Re: [Patch net-next v3 4/5] net_sched: act: refuse to remove bound action outside
Date: Wed, 12 Feb 2014 07:44:18 -0500 [thread overview]
Message-ID: <52FB6CA2.1080301@mojatatu.com> (raw)
In-Reply-To: <1392167255-21744-5-git-send-email-xiyou.wangcong@gmail.com>
On 02/11/14 20:07, Cong Wang wrote:
> When an action is bonnd to a filter, there is no point to
> remove it outside. Currently we just silently decrease the refcnt,
> we should reject this explicitly with EPERM.
>
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: David S. Miller <davem@davemloft.net>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>
> ---
> include/net/act_api.h | 2 +-
> net/sched/act_api.c | 26 ++++++++++++++++++++------
> 2 files changed, 21 insertions(+), 7 deletions(-)
>
> diff --git a/include/net/act_api.h b/include/net/act_api.h
> index 969cac6..3ee4c92 100644
> --- a/include/net/act_api.h
> +++ b/include/net/act_api.h
> @@ -109,7 +109,7 @@ void tcf_hash_insert(struct tc_action *a);
>
> int tcf_register_action(struct tc_action_ops *a, unsigned int mask);
> int tcf_unregister_action(struct tc_action_ops *a);
> -void tcf_action_destroy(struct list_head *actions, int bind);
> +int tcf_action_destroy(struct list_head *actions, int bind);
> int tcf_action_exec(struct sk_buff *skb, const struct list_head *actions,
> struct tcf_result *res);
> int tcf_action_init(struct net *net, struct nlattr *nla,
> diff --git a/net/sched/act_api.c b/net/sched/act_api.c
> index c88d382..27e4c53 100644
> --- a/net/sched/act_api.c
> +++ b/net/sched/act_api.c
> @@ -53,6 +53,8 @@ int tcf_hash_release(struct tc_action *a, int bind)
> if (p) {
> if (bind)
> p->tcfc_bindcnt--;
> + else if (p->tcfc_bindcnt > 0)
> + return -EPERM;
>
> p->tcfc_refcnt--;
> if (p->tcfc_bindcnt <= 0 && p->tcfc_refcnt <= 0) {
> @@ -123,6 +125,7 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a)
> struct tcf_common *p;
> struct nlattr *nest;
> int i = 0, n_i = 0;
> + int ret = -EINVAL;
>
> nest = nla_nest_start(skb, a->order);
> if (nest == NULL)
> @@ -133,10 +136,12 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a)
> head = &hinfo->htab[tcf_hash(i, hinfo->hmask)];
> hlist_for_each_entry_safe(p, n, head, tcfc_head) {
> a->priv = p;
> - if (ACT_P_DELETED == tcf_hash_release(a, 0)) {
> + ret = tcf_hash_release(a, 0);
> + if (ret == ACT_P_DELETED) {
> module_put(a->ops->owner);
> n_i++;
> - }
> + } else if (ret < 0)
> + goto nla_put_failure;
> }
> }
> if (nla_put_u32(skb, TCA_FCNT, n_i))
> @@ -146,7 +151,7 @@ static int tcf_del_walker(struct sk_buff *skb, struct tc_action *a)
> return n_i;
> nla_put_failure:
> nla_nest_cancel(skb, nest);
> - return -EINVAL;
> + return ret;
> }
>
> static int tcf_generic_walker(struct sk_buff *skb, struct netlink_callback *cb,
> @@ -401,16 +406,21 @@ exec_done:
> }
> EXPORT_SYMBOL(tcf_action_exec);
>
> -void tcf_action_destroy(struct list_head *actions, int bind)
> +int tcf_action_destroy(struct list_head *actions, int bind)
> {
> struct tc_action *a, *tmp;
> + int ret = 0;
>
> list_for_each_entry_safe(a, tmp, actions, list) {
> - if (tcf_hash_release(a, bind) == ACT_P_DELETED)
> + ret = tcf_hash_release(a, bind);
> + if (ret == ACT_P_DELETED)
> module_put(a->ops->owner);
> + else if (ret < 0)
> + return ret;
> list_del(&a->list);
> kfree(a);
> }
> + return ret;
> }
>
> int
> @@ -838,7 +848,11 @@ tcf_del_notify(struct net *net, struct nlmsghdr *n, struct list_head *actions,
> }
>
> /* now do the delete */
> - tcf_action_destroy(actions, 0);
> + ret = tcf_action_destroy(actions, 0);
> + if (ret < 0) {
> + kfree_skb(skb);
> + return ret;
> + }
>
> ret = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
> n->nlmsg_flags & NLM_F_ECHO);
>
next prev parent reply other threads:[~2014-02-12 12:44 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-12 1:07 [Patch net-next v3 0/5] net_sched: act: more cleanup and improvement Cong Wang
2014-02-12 1:07 ` [Patch net-next v3 1/5] net_sched: act: hide struct tcf_common from API Cong Wang
2014-02-12 12:43 ` Jamal Hadi Salim
2014-02-12 1:07 ` [Patch net-next v3 2/5] net_sched: act: refactor cleanup ops Cong Wang
2014-02-12 12:43 ` Jamal Hadi Salim
2014-02-12 1:07 ` [Patch net-next v3 3/5] net_sched: act: move tcf_hashinfo_init() into tcf_register_action() Cong Wang
2014-02-12 12:44 ` Jamal Hadi Salim
2014-02-12 1:07 ` [Patch net-next v3 4/5] net_sched: act: refuse to remove bound action outside Cong Wang
2014-02-12 12:44 ` Jamal Hadi Salim [this message]
2014-02-12 1:07 ` [Patch net-next v3 5/5] net_sched: act: clean up tca_action_flush() Cong Wang
2014-02-12 12:44 ` Jamal Hadi Salim
2014-02-13 0:24 ` [Patch net-next v3 0/5] net_sched: act: more cleanup and improvement David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52FB6CA2.1080301@mojatatu.com \
--to=jhs@mojatatu.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.