Skip to content

Commit 9bc0c0b

Browse files
q2venmehmetb0
authored andcommitted
gtp: Use for_each_netdev_rcu() in gtp_genl_dump_pdp().
BugLink: https://bugs.launchpad.net/bugs/2097298 [ Upstream commit 46841c7053e6d25fb33e0534ef023833bf03e382 ] 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 <shaw.leon@gmail.com> Closes: https://lore.kernel.org/netdev/CABAhCOQdBL6h9M2C+kd+bGivRJ9Q72JUxW+-gur0nub_=PmFPA@mail.gmail.com/ Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Noah Wager <noah.wager@canonical.com> Signed-off-by: Koichiro Den <koichiro.den@canonical.com>
1 parent 4087c24 commit 9bc0c0b

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
@@ -698,7 +698,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev,
698698
}
699699

700700
gn = net_generic(dev_net(dev), gtp_net_id);
701-
list_add_rcu(&gtp->list, &gn->gtp_dev_list);
701+
list_add(&gtp->list, &gn->gtp_dev_list);
702702
dev->priv_destructor = gtp_destructor;
703703

704704
netdev_dbg(dev, "registered new GTP interface\n");
@@ -724,7 +724,7 @@ static void gtp_dellink(struct net_device *dev, struct list_head *head)
724724
hlist_for_each_entry_safe(pctx, next, &gtp->tid_hash[i], hlist_tid)
725725
pdp_context_delete(pctx);
726726

727-
list_del_rcu(&gtp->list);
727+
list_del(&gtp->list);
728728
unregister_netdevice_queue(dev, head);
729729
}
730730

@@ -1305,16 +1305,19 @@ static int gtp_genl_dump_pdp(struct sk_buff *skb,
13051305
struct gtp_dev *last_gtp = (struct gtp_dev *)cb->args[2], *gtp;
13061306
int i, j, bucket = cb->args[0], skip = cb->args[1];
13071307
struct net *net = sock_net(skb->sk);
1308+
struct net_device *dev;
13081309
struct pdp_ctx *pctx;
1309-
struct gtp_net *gn;
1310-
1311-
gn = net_generic(net, gtp_net_id);
13121310

13131311
if (cb->args[4])
13141312
return 0;
13151313

13161314
rcu_read_lock();
1317-
list_for_each_entry_rcu(gtp, &gn->gtp_dev_list, list) {
1315+
for_each_netdev_rcu(net, dev) {
1316+
if (dev->rtnl_link_ops != &gtp_link_ops)
1317+
continue;
1318+
1319+
gtp = netdev_priv(dev);
1320+
13181321
if (last_gtp && last_gtp != gtp)
13191322
continue;
13201323
else
@@ -1410,9 +1413,9 @@ static void __net_exit gtp_net_exit_batch_rtnl(struct list_head *net_list,
14101413

14111414
list_for_each_entry(net, net_list, exit_list) {
14121415
struct gtp_net *gn = net_generic(net, gtp_net_id);
1413-
struct gtp_dev *gtp;
1416+
struct gtp_dev *gtp, *gtp_next;
14141417

1415-
list_for_each_entry(gtp, &gn->gtp_dev_list, list)
1418+
list_for_each_entry_safe(gtp, gtp_next, &gn->gtp_dev_list, list)
14161419
gtp_dellink(gtp->dev, dev_to_kill);
14171420
}
14181421
}

0 commit comments

Comments
 (0)