From 6ad15a601f4cc5b8070d09a30a2d8d6059e0df97 Mon Sep 17 00:00:00 2001 From: Danielle Ratson Date: Tue, 2 Feb 2021 20:06:05 +0200 Subject: [PATCH] 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: Danielle Ratson Signed-off-by: Jakub Kicinski Signed-off-by: hongrongxuan Conflicts: net/ethtool/linkmodes.c --- net/ethtool/linkmodes.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/net/ethtool/linkmodes.c b/net/ethtool/linkmodes.c index 29dcd675b65a..0edf503012e2 100644 --- a/net/ethtool/linkmodes.c +++ b/net/ethtool/linkmodes.c @@ -338,6 +338,21 @@ static bool ethnl_validate_master_slave_cfg(u8 cfg) 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, struct ethtool_link_ksettings *ksettings, bool *mod) @@ -349,19 +364,11 @@ static int ethnl_update_linkmodes(struct genl_info *info, struct nlattr **tb, master_slave_cfg = tb[ETHTOOL_A_LINKMODES_MASTER_SLAVE_CFG]; if (master_slave_cfg) { - u8 cfg = nla_get_u8(master_slave_cfg); - if (lsettings->master_slave_cfg == MASTER_SLAVE_CFG_UNSUPPORTED) { NL_SET_ERR_MSG_ATTR(info->extack, master_slave_cfg, "master/slave configuration not supported by device"); 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; @@ -404,6 +411,11 @@ int ethnl_set_linkmodes(struct sk_buff *skb, struct genl_info *info) info->extack); if (ret < 0) return ret; + + ret = ethnl_check_linkmodes(info, tb); + if (ret < 0) + return ret; + ret = ethnl_parse_header_dev_get(&req_info, tb[ETHTOOL_A_LINKMODES_HEADER], genl_info_net(info), info->extack,