Skip to content

Commit 90b2f49

Browse files
edumazetkuba-moo
authored andcommitted
openvswitch: use RCU protection in ovs_vport_cmd_fill_info()
ovs_vport_cmd_fill_info() can be called without RTNL or RCU. Use RCU protection and dev_net_rcu() to avoid potential UAF. Fixes: 9354d45 ("openvswitch: reliable interface indentification in port dumps") Signed-off-by: Eric Dumazet <edumazet@google.com> Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com> Link: https://patch.msgid.link/20250207135841.1948589-6-edumazet@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent a42b69f commit 90b2f49

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/openvswitch/datapath.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,7 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
21012101
{
21022102
struct ovs_header *ovs_header;
21032103
struct ovs_vport_stats vport_stats;
2104+
struct net *net_vport;
21042105
int err;
21052106

21062107
ovs_header = genlmsg_put(skb, portid, seq, &dp_vport_genl_family,
@@ -2117,12 +2118,15 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
21172118
nla_put_u32(skb, OVS_VPORT_ATTR_IFINDEX, vport->dev->ifindex))
21182119
goto nla_put_failure;
21192120

2120-
if (!net_eq(net, dev_net(vport->dev))) {
2121-
int id = peernet2id_alloc(net, dev_net(vport->dev), gfp);
2121+
rcu_read_lock();
2122+
net_vport = dev_net_rcu(vport->dev);
2123+
if (!net_eq(net, net_vport)) {
2124+
int id = peernet2id_alloc(net, net_vport, GFP_ATOMIC);
21222125

21232126
if (nla_put_s32(skb, OVS_VPORT_ATTR_NETNSID, id))
2124-
goto nla_put_failure;
2127+
goto nla_put_failure_unlock;
21252128
}
2129+
rcu_read_unlock();
21262130

21272131
ovs_vport_get_stats(vport, &vport_stats);
21282132
if (nla_put_64bit(skb, OVS_VPORT_ATTR_STATS,
@@ -2143,6 +2147,8 @@ static int ovs_vport_cmd_fill_info(struct vport *vport, struct sk_buff *skb,
21432147
genlmsg_end(skb, ovs_header);
21442148
return 0;
21452149

2150+
nla_put_failure_unlock:
2151+
rcu_read_unlock();
21462152
nla_put_failure:
21472153
err = -EMSGSIZE;
21482154
error:

0 commit comments

Comments
 (0)