Skip to content

Commit d756c8a

Browse files
q2vengregkh
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]>
1 parent 3d1c0c5 commit d756c8a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

drivers/net/gtp.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ static int gtp_newlink(struct net *src_net, struct net_device *dev,
10961096
}
10971097

10981098
gn = net_generic(dev_net(dev), gtp_net_id);
1099-
list_add_rcu(&gtp->list, &gn->gtp_dev_list);
1099+
list_add(&gtp->list, &gn->gtp_dev_list);
11001100
dev->priv_destructor = gtp_destructor;
11011101

11021102
netdev_dbg(dev, "registered new GTP interface\n");
@@ -1122,7 +1122,7 @@ static void gtp_dellink(struct net_device *dev, struct list_head *head)
11221122
hlist_for_each_entry_safe(pctx, next, &gtp->tid_hash[i], hlist_tid)
11231123
pdp_context_delete(pctx);
11241124

1125-
list_del_rcu(&gtp->list);
1125+
list_del(&gtp->list);
11261126
unregister_netdevice_queue(dev, head);
11271127
}
11281128

@@ -1690,16 +1690,19 @@ static int gtp_genl_dump_pdp(struct sk_buff *skb,
16901690
struct gtp_dev *last_gtp = (struct gtp_dev *)cb->args[2], *gtp;
16911691
int i, j, bucket = cb->args[0], skip = cb->args[1];
16921692
struct net *net = sock_net(skb->sk);
1693+
struct net_device *dev;
16931694
struct pdp_ctx *pctx;
1694-
struct gtp_net *gn;
1695-
1696-
gn = net_generic(net, gtp_net_id);
16971695

16981696
if (cb->args[4])
16991697
return 0;
17001698

17011699
rcu_read_lock();
1702-
list_for_each_entry_rcu(gtp, &gn->gtp_dev_list, list) {
1700+
for_each_netdev_rcu(net, dev) {
1701+
if (dev->rtnl_link_ops != &gtp_link_ops)
1702+
continue;
1703+
1704+
gtp = netdev_priv(dev);
1705+
17031706
if (last_gtp && last_gtp != gtp)
17041707
continue;
17051708
else
@@ -1891,9 +1894,9 @@ static void __net_exit gtp_net_exit_batch_rtnl(struct list_head *net_list,
18911894

18921895
list_for_each_entry(net, net_list, exit_list) {
18931896
struct gtp_net *gn = net_generic(net, gtp_net_id);
1894-
struct gtp_dev *gtp;
1897+
struct gtp_dev *gtp, *gtp_next;
18951898

1896-
list_for_each_entry(gtp, &gn->gtp_dev_list, list)
1899+
list_for_each_entry_safe(gtp, gtp_next, &gn->gtp_dev_list, list)
18971900
gtp_dellink(gtp->dev, dev_to_kill);
18981901
}
18991902
}

0 commit comments

Comments
 (0)