Commit 8248334d authored by Daniel Borkmann's avatar Daniel Borkmann Committed by Zefan Li

rtnetlink: verify IFLA_VF_INFO attributes before passing them to driver

commit 4f7d2cdf upstream.

Jason Gunthorpe reported that since commit c02db8c6 ("rtnetlink: make
SR-IOV VF interface symmetric"), we don't verify IFLA_VF_INFO attributes
anymore with respect to their policy, that is, ifla_vfinfo_policy[].

Before, they were part of ifla_policy[], but they have been nested since
placed under IFLA_VFINFO_LIST, that contains the attribute IFLA_VF_INFO,
which is another nested attribute for the actual VF attributes such as
IFLA_VF_MAC, IFLA_VF_VLAN, etc.

Despite the policy being split out from ifla_policy[] in this commit,
it's never applied anywhere. nla_for_each_nested() only does basic nla_ok()
testing for struct nlattr, but it doesn't know about the data context and
their requirements.

Fix, on top of Jason's initial work, does 1) parsing of the attributes
with the right policy, and 2) using the resulting parsed attribute table
from 1) instead of the nla_for_each_nested() loop (just like we used to
do when still part of ifla_policy[]).

Reference: http://thread.gmane.org/gmane.linux.network/368913
Fixes: c02db8c6 ("rtnetlink: make SR-IOV VF interface symmetric")
Reported-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Chris Wright <chrisw@sous-sol.org>
Cc: Sucheta Chakraborty <sucheta.chakraborty@qlogic.com>
Cc: Greg Rose <gregory.v.rose@intel.com>
Cc: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Cc: Rony Efraim <ronye@mellanox.com>
Cc: Vlad Zolotarov <vladz@cloudius-systems.com>
Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Cc: Thomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarJason Gunthorpe <jgunthorpe@obsidianresearch.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarVlad Zolotarov <vladz@cloudius-systems.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
[bwh: Backported to 3.2:
 - Drop unsupported attributes
 - Use ndo_set_vf_tx_rate operation, not ndo_set_vf_rate]
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent 2025b59c
...@@ -1139,10 +1139,6 @@ static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { ...@@ -1139,10 +1139,6 @@ static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
[IFLA_INFO_DATA] = { .type = NLA_NESTED }, [IFLA_INFO_DATA] = { .type = NLA_NESTED },
}; };
static const struct nla_policy ifla_vfinfo_policy[IFLA_VF_INFO_MAX+1] = {
[IFLA_VF_INFO] = { .type = NLA_NESTED },
};
static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = { static const struct nla_policy ifla_vf_policy[IFLA_VF_MAX+1] = {
[IFLA_VF_MAC] = { .len = sizeof(struct ifla_vf_mac) }, [IFLA_VF_MAC] = { .len = sizeof(struct ifla_vf_mac) },
[IFLA_VF_VLAN] = { .len = sizeof(struct ifla_vf_vlan) }, [IFLA_VF_VLAN] = { .len = sizeof(struct ifla_vf_vlan) },
...@@ -1216,58 +1212,53 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[]) ...@@ -1216,58 +1212,53 @@ static int validate_linkmsg(struct net_device *dev, struct nlattr *tb[])
return 0; return 0;
} }
static int do_setvfinfo(struct net_device *dev, struct nlattr *attr) static int do_setvfinfo(struct net_device *dev, struct nlattr **tb)
{ {
int rem, err = -EINVAL;
struct nlattr *vf;
const struct net_device_ops *ops = dev->netdev_ops; const struct net_device_ops *ops = dev->netdev_ops;
int err = -EINVAL;
nla_for_each_nested(vf, attr, rem) { if (tb[IFLA_VF_MAC]) {
switch (nla_type(vf)) { struct ifla_vf_mac *ivm = nla_data(tb[IFLA_VF_MAC]);
case IFLA_VF_MAC: {
struct ifla_vf_mac *ivm;
ivm = nla_data(vf);
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
if (ops->ndo_set_vf_mac) if (ops->ndo_set_vf_mac)
err = ops->ndo_set_vf_mac(dev, ivm->vf, err = ops->ndo_set_vf_mac(dev, ivm->vf,
ivm->mac); ivm->mac);
break; if (err < 0)
return err;
} }
case IFLA_VF_VLAN: {
struct ifla_vf_vlan *ivv; if (tb[IFLA_VF_VLAN]) {
ivv = nla_data(vf); struct ifla_vf_vlan *ivv = nla_data(tb[IFLA_VF_VLAN]);
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
if (ops->ndo_set_vf_vlan) if (ops->ndo_set_vf_vlan)
err = ops->ndo_set_vf_vlan(dev, ivv->vf, err = ops->ndo_set_vf_vlan(dev, ivv->vf, ivv->vlan,
ivv->vlan,
ivv->qos); ivv->qos);
break; if (err < 0)
return err;
} }
case IFLA_VF_TX_RATE: {
struct ifla_vf_tx_rate *ivt; if (tb[IFLA_VF_TX_RATE]) {
ivt = nla_data(vf); struct ifla_vf_tx_rate *ivt = nla_data(tb[IFLA_VF_TX_RATE]);
err = -EOPNOTSUPP;
if (ops->ndo_set_vf_tx_rate) if (ops->ndo_set_vf_tx_rate)
err = ops->ndo_set_vf_tx_rate(dev, ivt->vf, err = ops->ndo_set_vf_tx_rate(dev, ivt->vf,
ivt->rate); ivt->rate);
break; if (err < 0)
return err;
} }
case IFLA_VF_SPOOFCHK: {
struct ifla_vf_spoofchk *ivs; if (tb[IFLA_VF_SPOOFCHK]) {
ivs = nla_data(vf); struct ifla_vf_spoofchk *ivs = nla_data(tb[IFLA_VF_SPOOFCHK]);
err = -EOPNOTSUPP; err = -EOPNOTSUPP;
if (ops->ndo_set_vf_spoofchk) if (ops->ndo_set_vf_spoofchk)
err = ops->ndo_set_vf_spoofchk(dev, ivs->vf, err = ops->ndo_set_vf_spoofchk(dev, ivs->vf,
ivs->setting); ivs->setting);
break; if (err < 0)
} return err;
default:
err = -EINVAL;
break;
}
if (err)
break;
} }
return err; return err;
} }
...@@ -1450,14 +1441,21 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm, ...@@ -1450,14 +1441,21 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
} }
if (tb[IFLA_VFINFO_LIST]) { if (tb[IFLA_VFINFO_LIST]) {
struct nlattr *vfinfo[IFLA_VF_MAX + 1];
struct nlattr *attr; struct nlattr *attr;
int rem; int rem;
nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) { nla_for_each_nested(attr, tb[IFLA_VFINFO_LIST], rem) {
if (nla_type(attr) != IFLA_VF_INFO) { if (nla_type(attr) != IFLA_VF_INFO ||
nla_len(attr) < NLA_HDRLEN) {
err = -EINVAL; err = -EINVAL;
goto errout; goto errout;
} }
err = do_setvfinfo(dev, attr); err = nla_parse_nested(vfinfo, IFLA_VF_MAX, attr,
ifla_vf_policy);
if (err < 0)
goto errout;
err = do_setvfinfo(dev, vfinfo);
if (err < 0) if (err < 0)
goto errout; goto errout;
modified = 1; modified = 1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment