Skip to content

Commit de51ad0

Browse files
q2venPaolo Abeni
authored andcommitted
phonet: Pass net and ifindex to rtm_phonet_notify().
Currently, rtm_phonet_notify() fetches netns and ifindex from dev. Once route_doit() is converted to RCU, rtm_phonet_notify() will be called outside of RCU due to GFP_KERNEL, and dev will be unavailable there. Let's pass net and ifindex to rtm_phonet_notify(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 302fc6b commit de51ad0

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

include/net/phonet/pn_dev.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void phonet_address_notify(struct net *net, int event, u32 ifindex, u8 addr);
4343

4444
int phonet_route_add(struct net_device *dev, u8 daddr);
4545
int phonet_route_del(struct net_device *dev, u8 daddr);
46-
void rtm_phonet_notify(int event, struct net_device *dev, u8 dst);
46+
void rtm_phonet_notify(struct net *net, int event, u32 ifindex, u8 dst);
4747
struct net_device *phonet_route_get_rcu(struct net *net, u8 daddr);
4848
struct net_device *phonet_route_output(struct net *net, u8 daddr);
4949

net/phonet/pn_dev.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,13 @@ static int phonet_device_autoconf(struct net_device *dev)
263263

264264
static void phonet_route_autodel(struct net_device *dev)
265265
{
266-
struct phonet_net *pnn = phonet_pernet(dev_net(dev));
267-
unsigned int i;
266+
struct net *net = dev_net(dev);
268267
DECLARE_BITMAP(deleted, 64);
268+
u32 ifindex = dev->ifindex;
269+
struct phonet_net *pnn;
270+
unsigned int i;
271+
272+
pnn = phonet_pernet(net);
269273

270274
/* Remove left-over Phonet routes */
271275
bitmap_zero(deleted, 64);
@@ -281,7 +285,7 @@ static void phonet_route_autodel(struct net_device *dev)
281285
return; /* short-circuit RCU */
282286
synchronize_rcu();
283287
for_each_set_bit(i, deleted, 64) {
284-
rtm_phonet_notify(RTM_DELROUTE, dev, i);
288+
rtm_phonet_notify(net, RTM_DELROUTE, ifindex, i);
285289
dev_put(dev);
286290
}
287291
}

net/phonet/pn_netlink.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ static int fill_route(struct sk_buff *skb, u32 ifindex, u8 dst,
200200
return -EMSGSIZE;
201201
}
202202

203-
void rtm_phonet_notify(int event, struct net_device *dev, u8 dst)
203+
void rtm_phonet_notify(struct net *net, int event, u32 ifindex, u8 dst)
204204
{
205205
struct sk_buff *skb;
206206
int err = -ENOBUFS;
@@ -210,17 +210,17 @@ void rtm_phonet_notify(int event, struct net_device *dev, u8 dst)
210210
if (skb == NULL)
211211
goto errout;
212212

213-
err = fill_route(skb, dev->ifindex, dst, 0, 0, event);
213+
err = fill_route(skb, ifindex, dst, 0, 0, event);
214214
if (err < 0) {
215215
WARN_ON(err == -EMSGSIZE);
216216
kfree_skb(skb);
217217
goto errout;
218218
}
219-
rtnl_notify(skb, dev_net(dev), 0,
220-
RTNLGRP_PHONET_ROUTE, NULL, GFP_KERNEL);
219+
220+
rtnl_notify(skb, net, 0, RTNLGRP_PHONET_ROUTE, NULL, GFP_KERNEL);
221221
return;
222222
errout:
223-
rtnl_set_sk_err(dev_net(dev), RTNLGRP_PHONET_ROUTE, err);
223+
rtnl_set_sk_err(net, RTNLGRP_PHONET_ROUTE, err);
224224
}
225225

226226
static const struct nla_policy rtm_phonet_policy[RTA_MAX+1] = {
@@ -235,6 +235,7 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
235235
struct nlattr *tb[RTA_MAX+1];
236236
struct net_device *dev;
237237
struct rtmsg *rtm;
238+
u32 ifindex;
238239
int err;
239240
u8 dst;
240241

@@ -260,7 +261,8 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
260261
if (dst & 3) /* Phonet addresses only have 6 high-order bits */
261262
return -EINVAL;
262263

263-
dev = __dev_get_by_index(net, nla_get_u32(tb[RTA_OIF]));
264+
ifindex = nla_get_u32(tb[RTA_OIF]);
265+
dev = __dev_get_by_index(net, ifindex);
264266
if (dev == NULL)
265267
return -ENODEV;
266268

@@ -269,7 +271,7 @@ static int route_doit(struct sk_buff *skb, struct nlmsghdr *nlh,
269271
else
270272
err = phonet_route_del(dev, dst);
271273
if (!err)
272-
rtm_phonet_notify(nlh->nlmsg_type, dev, dst);
274+
rtm_phonet_notify(net, nlh->nlmsg_type, ifindex, dst);
273275
return err;
274276
}
275277

0 commit comments

Comments
 (0)