Commit 189e7a8d authored by Danielle Ratson's avatar Danielle Ratson Committed by Jakub Kicinski

ethtool: Validate master slave configuration before rtnl_lock()

Create a new function for input validations to be called before
rtnl_lock() and move the master slave validation to that function.

This would be a cleanup for next patch that would add another validation
to the new function.
Signed-off-by: default avatarDanielle Ratson <danieller@nvidia.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 99b8202b
...@@ -325,6 +325,21 @@ static bool ethnl_validate_master_slave_cfg(u8 cfg) ...@@ -325,6 +325,21 @@ static bool ethnl_validate_master_slave_cfg(u8 cfg)
return false; return false;
} }
static int ethnl_check_linkmodes(struct genl_info *info, struct nlattr **tb)
{
const struct nlattr *master_slave_cfg;
master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG];
if (master_slave_cfg &&
!ethnl_validate_master_slave_cfg(nla_get_u8(master_slave_cfg))) {
NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg,
"master/slave value is invalid");
return -EOPNOTSUPP;
}
return 0;
}
static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb, static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
struct ethtool_link_ksettings *ksettings, struct ethtool_link_ksettings *ksettings,
bool *mod) bool *mod)
...@@ -336,19 +351,11 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb, ...@@ -336,19 +351,11 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb,
master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG]; master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG];
if (master_slave_cfg) { if (master_slave_cfg) {
u8 cfg = nla_get_u8(master_slave_cfg);
if (lsettings->master_slave_cfg == MASTER_SLAVE_CFG_UNSUPPORTED) { if (lsettings->master_slave_cfg == MASTER_SLAVE_CFG_UNSUPPORTED) {
NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg, NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg,
"master/slave configuration not supported by device"); "master/slave configuration not supported by device");
return -EOPNOTSUPP; return -EOPNOTSUPP;
} }
if (!ethnl_validate_master_slave_cfg(cfg)) {
NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg,
"master/slave value is invalid");
return -EOPNOTSUPP;
}
} }
*mod = false; *mod = false;
...@@ -386,6 +393,10 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info) ...@@ -386,6 +393,10 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info)
bool mod = false; bool mod = false;
int ret; int ret;
ret = ethnl_check_linkmodes(info, tb);
if (ret < 0)
return ret;
ret = ethnl_parse_header_dev_get(&req_info, ret = ethnl_parse_header_dev_get(&req_info,
tb[ETHTOOL_A_LINKMODES_HEADER], tb[ETHTOOL_A_LINKMODES_HEADER],
genl_info_net(info), info->extack, genl_info_net(info), info->extack,
......
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