Skip to content

Commit 5b5f99b

Browse files
wangzk320davem330
authored andcommitted
net_sched: return correct value for *notify* functions
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>
1 parent deb6bfa commit 5b5f99b

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

net/sched/cls_api.c

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,7 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
18931893
{
18941894
struct sk_buff *skb;
18951895
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
1896+
int err = 0;
18961897

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

19081909
if (unicast)
1909-
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
1910+
err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
1911+
else
1912+
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1913+
n->nlmsg_flags & NLM_F_ECHO);
19101914

1911-
return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1912-
n->nlmsg_flags & NLM_F_ECHO);
1915+
if (err > 0)
1916+
err = 0;
1917+
return err;
19131918
}
19141919

19151920
static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
@@ -1941,12 +1946,15 @@ static int tfilter_del_notify(struct net *net, struct sk_buff *oskb,
19411946
}
19421947

19431948
if (unicast)
1944-
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
1945-
1946-
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1947-
n->nlmsg_flags & NLM_F_ECHO);
1949+
err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
1950+
else
1951+
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1952+
n->nlmsg_flags & NLM_F_ECHO);
19481953
if (err < 0)
19491954
NL_SET_ERR_MSG(extack, "Failed to send filter delete notification");
1955+
1956+
if (err > 0)
1957+
err = 0;
19501958
return err;
19511959
}
19521960

@@ -2688,6 +2696,7 @@ static int tc_chain_notify(struct tcf_chain *chain, struct sk_buff *oskb,
26882696
struct tcf_block *block = chain->block;
26892697
struct net *net = block->net;
26902698
struct sk_buff *skb;
2699+
int err = 0;
26912700

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

27032712
if (unicast)
2704-
return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
2713+
err = netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
2714+
else
2715+
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
2716+
flags & NLM_F_ECHO);
27052717

2706-
return rtnetlink_send(skb, net, portid, RTNLGRP_TC, flags & NLM_F_ECHO);
2718+
if (err > 0)
2719+
err = 0;
2720+
return err;
27072721
}
27082722

27092723
static int tc_chain_notify_delete(const struct tcf_proto_ops *tmplt_ops,

net/sched/sch_api.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,6 +1824,7 @@ static int tclass_notify(struct net *net, struct sk_buff *oskb,
18241824
{
18251825
struct sk_buff *skb;
18261826
u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
1827+
int err = 0;
18271828

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

1837-
return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1838-
n->nlmsg_flags & NLM_F_ECHO);
1838+
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1839+
n->nlmsg_flags & NLM_F_ECHO);
1840+
if (err > 0)
1841+
err = 0;
1842+
return err;
18391843
}
18401844

18411845
static int tclass_del_notify(struct net *net,
@@ -1866,8 +1870,11 @@ static int tclass_del_notify(struct net *net,
18661870
return err;
18671871
}
18681872

1869-
return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1870-
n->nlmsg_flags & NLM_F_ECHO);
1873+
err = rtnetlink_send(skb, net, portid, RTNLGRP_TC,
1874+
n->nlmsg_flags & NLM_F_ECHO);
1875+
if (err > 0)
1876+
err = 0;
1877+
return err;
18711878
}
18721879

18731880
#ifdef CONFIG_NET_CLS

0 commit comments

Comments
 (0)