Skip to content

Commit 36e60bb

Browse files
q2venaloktiwa
authored andcommitted
gtp: Use for_each_netdev_rcu() in gtp_genl_dump_pdp().
[ Upstream commit 46841c7 ] gtp_newlink() links the gtp device to a list in dev_net(dev). However, even after the gtp device is moved to another netns, it stays on the list but should be invisible. Let's use for_each_netdev_rcu() for netdev traversal in gtp_genl_dump_pdp(). Note that gtp_dev_list is no longer used under RCU, so list helpers are converted to the non-RCU variant. Fixes: 459aa66 ("gtp: add initial driver for datapath of GPRS Tunneling Protocol (GTP-U)") Reported-by: Xiao Liang <[email protected]> Closes: https://lore.kernel.org/netdev/CABAhCOQdBL6h9M2C+kd+bGivRJ9Q72JUxW+-gur0nub_=PmFPA@mail.gmail.com/ Signed-off-by: Kuniyuki Iwashima <[email protected]> Signed-off-by: Paolo Abeni <[email protected]> Signed-off-by: Sasha Levin <[email protected]> (cherry picked from commit 574c3f3f8e5e4cad8ae92f46df4214c153866dd2) Signed-off-by: Alok Tiwari <[email protected]>
1 parent 659c019 commit 36e60bb

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/net/gtp.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev,
691691
}
692692

693693
gn = net_generic(dev_net(dev), gtp_net_id);
694-
list_add_rcu(&gtp->list, &gn->gtp_dev_list);
694+
list_add(&gtp->list, &gn->gtp_dev_list);
695695
dev->priv_destructor = gtp_destructor;
696696

697697
netdev_dbg(dev, "registered new GTP interface\n");
@@ -717,7 +717,7 @@ static void gtp_dellink(struct net_device *dev, struct list_head *head)
717717
hlist_for_each_entry_safe(pctx, next, &gtp->tid_hash[i], hlist_tid)
718718
pdp_context_delete(pctx);
719719

720-
list_del_rcu(&gtp->list);
720+
list_del(&gtp->list);
721721
unregister_netdevice_queue(dev, head);
722722
}
723723

@@ -1259,16 +1259,19 @@ static int gtp_genl_dump_pdp(struct sk_buff *skb,
12591259
struct gtp_dev *last_gtp = (struct gtp_dev *)cb->args[2], *gtp;
12601260
int i, j, bucket = cb->args[0], skip = cb->args[1];
12611261
struct net *net = sock_net(skb->sk);
1262+
struct net_device *dev;
12621263
struct pdp_ctx *pctx;
1263-
struct gtp_net *gn;
1264-
1265-
gn = net_generic(net, gtp_net_id);
12661264

12671265
if (cb->args[4])
12681266
return 0;
12691267

12701268
rcu_read_lock();
1271-
list_for_each_entry_rcu(gtp, &gn->gtp_dev_list, list) {
1269+
for_each_netdev_rcu(net, dev) {
1270+
if (dev->rtnl_link_ops != &gtp_link_ops)
1271+
continue;
1272+
1273+
gtp = netdev_priv(dev);
1274+
12721275
if (last_gtp && last_gtp != gtp)
12731276
continue;
12741277
else
@@ -1362,9 +1365,9 @@ static void __net_exit gtp_net_exit_batch_rtnl(struct list_head *net_list,
13621365

13631366
list_for_each_entry(net, net_list, exit_list) {
13641367
struct gtp_net *gn = net_generic(net, gtp_net_id);
1365-
struct gtp_dev *gtp;
1368+
struct gtp_dev *gtp, *gtp_next;
13661369

1367-
list_for_each_entry(gtp, &gn->gtp_dev_list, list)
1370+
list_for_each_entry_safe(gtp, gtp_next, &gn->gtp_dev_list, list)
13681371
gtp_dellink(gtp->dev, dev_to_kill);
13691372
}
13701373
}

0 commit comments

Comments
 (0)