From: Cong Wang <xiyou.wangcong@gmail.com>
To: netdev@vger.kernel.org
Cc: jhs@mojatatu.com, Cong Wang <xiyou.wangcong@gmail.com>
Subject: [Patch net-next v2 2/4] net_sched: introduce tclass_del_notify()
Date: Thu, 24 Aug 2017 16:51:28 -0700 [thread overview]
Message-ID: <20170824235130.28503-3-xiyou.wangcong@gmail.com> (raw)
In-Reply-To: <20170824235130.28503-1-xiyou.wangcong@gmail.com>
Like for TC actions, ->delete() is a special case,
we have to prepare and fill the notification before delete
otherwise would get use-after-free after we remove the
reference count.
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
net/sched/sch_api.c | 39 +++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c
index 330ffaea9974..3ef4eb578739 100644
--- a/net/sched/sch_api.c
+++ b/net/sched/sch_api.c
@@ -1618,6 +1618,38 @@ static int tclass_notify(struct net *net, struct sk_buff *oskb,
n->nlmsg_flags & NLM_F_ECHO);
}
+static int tclass_del_notify(struct net *net,
+ const struct Qdisc_class_ops *cops,
+ struct sk_buff *oskb, struct nlmsghdr *n,
+ struct Qdisc *q, unsigned long cl)
+{
+ u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
+ struct sk_buff *skb;
+ int err = 0;
+
+ if (!cops->delete)
+ return -EOPNOTSUPP;
+
+ skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
+ if (!skb)
+ return -ENOBUFS;
+
+ if (tc_fill_tclass(skb, q, cl, portid, n->nlmsg_seq, 0,
+ RTM_DELTCLASS) < 0) {
+ kfree_skb(skb);
+ return -EINVAL;
+ }
+
+ err = cops->delete(q, cl);
+ if (err) {
+ kfree_skb(skb);
+ return err;
+ }
+
+ return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
+ n->nlmsg_flags & NLM_F_ECHO);
+}
+
static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n,
struct netlink_ext_ack *extack)
{
@@ -1722,12 +1754,7 @@ static int tc_ctl_tclass(struct sk_buff *skb, struct nlmsghdr *n,
goto out;
break;
case RTM_DELTCLASS:
- err = -EOPNOTSUPP;
- if (cops->delete)
- err = cops->delete(q, cl);
- if (err == 0)
- tclass_notify(net, skb, n, q, cl,
- RTM_DELTCLASS);
+ err = tclass_del_notify(net, cops, skb, n, q, cl);
goto out;
case RTM_GETTCLASS:
err = tclass_notify(net, skb, n, q, cl, RTM_NEWTCLASS);
--
2.13.0
next prev parent reply other threads:[~2017-08-24 23:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-24 23:51 [Patch net-next v2 0/4] net_sched: clean up tc classes and u32 filter Cong Wang
2017-08-24 23:51 ` [Patch net-next v2 1/4] net_sched: get rid of more forward declarations Cong Wang
2017-08-25 8:45 ` Jiri Pirko
2017-08-25 11:51 ` Jamal Hadi Salim
2017-08-24 23:51 ` Cong Wang [this message]
2017-08-25 8:54 ` [Patch net-next v2 2/4] net_sched: introduce tclass_del_notify() Jiri Pirko
2017-08-25 11:51 ` Jamal Hadi Salim
2017-08-24 23:51 ` [Patch net-next v2 3/4] net_sched: remove tc class reference counting Cong Wang
2017-08-25 9:00 ` Jiri Pirko
2017-08-25 9:18 ` Florian Westphal
2017-08-25 9:36 ` Jiri Pirko
2017-08-25 9:41 ` Jiri Pirko
2017-08-25 12:28 ` Jamal Hadi Salim
2017-08-24 23:51 ` [Patch net-next v2 4/4] net_sched: kill u32_node pointer in Qdisc Cong Wang
2017-08-25 9:06 ` Jiri Pirko
2017-08-25 12:29 ` Jamal Hadi Salim
2017-08-25 12:37 ` Jiri Pirko
2017-08-26 0:20 ` [Patch net-next v2 0/4] net_sched: clean up tc classes and u32 filter 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=20170824235130.28503-3-xiyou.wangcong@gmail.com \
--to=xiyou.wangcong@gmail.com \
--cc=jhs@mojatatu.com \
--cc=netdev@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).