Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
net_sched: return correct value for *notify* functions
Browse files Browse the repository at this point in the history
It is confusing to directly use return value of netlink_send()/
netlink_unicast() as the return value of *notify*, as it may be not
error at all.

Example: in tc_del_tfilter(), after calling tfilter_del_notify(), it will
goto errout if (err). However, the netlink_send()/netlink_unicast() will
return positive value even for successful case. So it may not call
tcf_chain_tp_remove() and so on to clean up the resource, as a result,
resource is leaked.

It may be easier to only check the return value of tfilter_del_nofiy(),
but it is more clean to correct all related functions.

Co-developed-by: Zengmo Gao <gaozengmo@jd.com>
Signed-off-by: Zhike Wang <wangzhike@jd.com>
Acked-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
wangzk320 authored and davem330 committed Mar 13, 2019
1 parent deb6bfa commit 5b5f99b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
32 changes: 23 additions & 9 deletions net/sched/cls_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,7 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
{
struct sk_buff *skb;
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
int err = 0;

skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
if (!skb)
Expand All @@ -1906,10 +1907,14 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
}

if (unicast)
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
else
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);

return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
if (err > 0)
err = 0;
return err;
}

static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
Expand Down Expand Up @@ -1941,12 +1946,15 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
}

if (unicast)
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);

err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
else
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
if (err < 0)
NL_SET_ERR_MSG(extack, "Failed to send filter delete notification");

if (err > 0)
err = 0;
return err;
}

Expand Down Expand Up @@ -2688,6 +2696,7 @@ static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
struct tcf_block *block = chain->block;
struct net *net = block->net;
struct sk_buff *skb;
int err = 0;

skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
if (!skb)
Expand All @@ -2701,9 +2710,14 @@ static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
}

if (unicast)
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
else
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
flags & NLM_F_ECHO);

return rtnetlink_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO);
if (err > 0)
err = 0;
return err;
}

static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops,
Expand Down
15 changes: 11 additions & 4 deletions net/sched/sch_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,7 @@ static int tclass_notify(struct net *net, struct sk_buff *oskb,
{
struct sk_buff *skb;
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
int err = 0;

skb = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
if (!skb)
Expand All @@ -1834,8 +1835,11 @@ static int tclass_notify(struct net *net, struct sk_buff *oskb,
return -EINVAL;
}

return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
if (err > 0)
err = 0;
return err;
}

static int tclass_del_notify(struct net *net,
Expand Down Expand Up @@ -1866,8 +1870,11 @@ static int tclass_del_notify(struct net *net,
return err;
}

return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
n->nlmsg_flags & NLM_F_ECHO);
if (err > 0)
err = 0;
return err;
}

#ifdef CONFIG_NET_CLS
Expand Down

0 comments on commit 5b5f99b

Please sign in to comment.