Skip to content
/ linux Public

Commit 88f9a87

Browse files
idoschdavem330
authored andcommitted
ethtool: Validate module EEPROM offset as part of policy
Validate the offset to read from module EEPROM as part of the netlink policy and remove the corresponding check from the code. This also makes it possible to query the offset range from user space: $ genl ctrl policy name ethtool ... ID: 0x14 policy[32]:attr[2]: type=U32 range:[0,255] ... Signed-off-by: Ido Schimmel <idosch@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0dc7dd0 commit 88f9a87

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

net/ethtool/eeprom.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,6 @@ static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr *
177177
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
178178
"reading cross half page boundary is illegal");
179179
return -EINVAL;
180-
} else if (request->offset >= ETH_MODULE_EEPROM_PAGE_LEN * 2) {
181-
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_OFFSET],
182-
"offset is out of bounds");
183-
return -EINVAL;
184180
} else if (request->offset + request->length > ETH_MODULE_EEPROM_PAGE_LEN * 2) {
185181
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MODULE_EEPROM_LENGTH],
186182
"reading cross page boundary is illegal");
@@ -233,7 +229,8 @@ const struct ethnl_request_ops ethnl_module_eeprom_request_ops = {
233229

234230
const struct nla_policy ethnl_module_eeprom_get_policy[] = {
235231
[ETHTOOL_A_MODULE_EEPROM_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
236-
[ETHTOOL_A_MODULE_EEPROM_OFFSET] = { .type = NLA_U32 },
232+
[ETHTOOL_A_MODULE_EEPROM_OFFSET] =
233+
NLA_POLICY_MAX(NLA_U32, ETH_MODULE_EEPROM_PAGE_LEN * 2 - 1),
237234
[ETHTOOL_A_MODULE_EEPROM_LENGTH] =
238235
NLA_POLICY_RANGE(NLA_U32, 1, ETH_MODULE_EEPROM_PAGE_LEN),
239236
[ETHTOOL_A_MODULE_EEPROM_PAGE] = { .type = NLA_U8 },

0 commit comments

Comments
 (0)