Skip to content

Commit a934151

Browse files
committed
openvswitch: Preallocate reply skb in ovs_vport_cmd_set().
Allocation of the Netlink notification skb can potentially fail after changing vport configuration. In general, we try to avoid this by undoing any change we made but that is difficult for existing objects. This avoids the problem by preallocating the buffer (which is fixed size). Signed-off-by: Jesse Gross <jesse@nicira.com>
1 parent 330305c commit a934151

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎net/openvswitch/datapath.c‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,10 +1593,8 @@ struct sk_buff *ovs_vport_cmd_build_info(struct vport *vport, u32 portid,
15931593
return ERR_PTR(-ENOMEM);
15941594

15951595
retval = ovs_vport_cmd_fill_info(vport, skb, portid, seq, 0, cmd);
1596-
if (retval < 0) {
1597-
kfree_skb(skb);
1598-
return ERR_PTR(retval);
1599-
}
1596+
BUG_ON(retval < 0);
1597+
16001598
return skb;
16011599
}
16021600

@@ -1726,24 +1724,32 @@ static int ovs_vport_cmd_set(struct sk_buff *skb, struct genl_info *info)
17261724
nla_get_u32(a[OVS_VPORT_ATTR_TYPE]) != vport->ops->type)
17271725
err = -EINVAL;
17281726

1727+
reply = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
1728+
if (!reply) {
1729+
err = -ENOMEM;
1730+
goto exit_unlock;
1731+
}
1732+
17291733
if (!err && a[OVS_VPORT_ATTR_OPTIONS])
17301734
err = ovs_vport_set_options(vport, a[OVS_VPORT_ATTR_OPTIONS]);
17311735
if (err)
1732-
goto exit_unlock;
1736+
goto exit_free;
1737+
17331738
if (a[OVS_VPORT_ATTR_UPCALL_PID])
17341739
vport->upcall_portid = nla_get_u32(a[OVS_VPORT_ATTR_UPCALL_PID]);
17351740

1736-
reply = ovs_vport_cmd_build_info(vport, info->snd_portid, info->snd_seq,
1737-
OVS_VPORT_CMD_NEW);
1738-
if (IS_ERR(reply)) {
1739-
netlink_set_err(sock_net(skb->sk)->genl_sock, 0,
1740-
ovs_dp_vport_multicast_group.id, PTR_ERR(reply));
1741-
goto exit_unlock;
1742-
}
1741+
err = ovs_vport_cmd_fill_info(vport, reply, info->snd_portid,
1742+
info->snd_seq, 0, OVS_VPORT_CMD_NEW);
1743+
BUG_ON(err < 0);
17431744

17441745
genl_notify(reply, genl_info_net(info), info->snd_portid,
17451746
ovs_dp_vport_multicast_group.id, info->nlhdr, GFP_KERNEL);
17461747

1748+
rtnl_unlock();
1749+
return 0;
1750+
1751+
exit_free:
1752+
kfree_skb(reply);
17471753
exit_unlock:
17481754
rtnl_unlock();
17491755
return err;

0 commit comments

Comments
 (0)