Skip to content

Commit 0dc7dd0

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

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

net/ethtool/eeprom.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ static int eeprom_parse_request(struct ethnl_req_info *req_info, struct nlattr *
159159
request->offset = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_OFFSET]);
160160
request->length = nla_get_u32(tb[ETHTOOL_A_MODULE_EEPROM_LENGTH]);
161161

162-
if (!request->length)
163-
return -EINVAL;
164-
165162
/* The following set of conditions limit the API to only dump 1/2
166163
* EEPROM page without crossing low page boundary located at offset 128.
167164
* This means user may only request dumps of length limited to 128 from
@@ -237,7 +234,8 @@ const struct ethnl_request_ops ethnl_module_eeprom_request_ops = {
237234
const struct nla_policy ethnl_module_eeprom_get_policy[] = {
238235
[ETHTOOL_A_MODULE_EEPROM_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
239236
[ETHTOOL_A_MODULE_EEPROM_OFFSET] = { .type = NLA_U32 },
240-
[ETHTOOL_A_MODULE_EEPROM_LENGTH] = { .type = NLA_U32 },
237+
[ETHTOOL_A_MODULE_EEPROM_LENGTH] =
238+
NLA_POLICY_RANGE(NLA_U32, 1, ETH_MODULE_EEPROM_PAGE_LEN),
241239
[ETHTOOL_A_MODULE_EEPROM_PAGE] = { .type = NLA_U8 },
242240
[ETHTOOL_A_MODULE_EEPROM_BANK] = { .type = NLA_U8 },
243241
[ETHTOOL_A_MODULE_EEPROM_I2C_ADDRESS] =

0 commit comments

Comments
 (0)