Skip to content

Commit 2363d73

Browse files
mkubecekdavem330
authored andcommitted
ethtool: reject unrecognized request flags
As pointed out by Jakub Kicinski, we ethtool netlink code should respond with an error if request head has flags set which are not recognized by kernel, either as a mistake or because it expects functionality introduced in later kernel versions. To avoid unnecessary roundtrips, use extack cookie to provide the information about supported request flags. Signed-off-by: Michal Kubecek <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f1388ec commit 2363d73

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

net/ethtool/netlink.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ int ethnl_parse_header(struct ethnl_req_info *req_info,
4040
struct nlattr *tb[ETHTOOL_A_HEADER_MAX + 1];
4141
const struct nlattr *devname_attr;
4242
struct net_device *dev = NULL;
43+
u32 flags = 0;
4344
int ret;
4445

4546
if (!header) {
@@ -50,8 +51,17 @@ int ethnl_parse_header(struct ethnl_req_info *req_info,
5051
ethnl_header_policy, extack);
5152
if (ret < 0)
5253
return ret;
53-
devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
54+
if (tb[ETHTOOL_A_HEADER_FLAGS]) {
55+
flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
56+
if (flags & ~ETHTOOL_FLAG_ALL) {
57+
NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_HEADER_FLAGS],
58+
"unrecognized request flags");
59+
nl_set_extack_cookie_u32(extack, ETHTOOL_FLAG_ALL);
60+
return -EOPNOTSUPP;
61+
}
62+
}
5463

64+
devname_attr = tb[ETHTOOL_A_HEADER_DEV_NAME];
5565
if (tb[ETHTOOL_A_HEADER_DEV_INDEX]) {
5666
u32 ifindex = nla_get_u32(tb[ETHTOOL_A_HEADER_DEV_INDEX]);
5767

@@ -90,9 +100,7 @@ int ethnl_parse_header(struct ethnl_req_info *req_info,
90100
}
91101

92102
req_info->dev = dev;
93-
if (tb[ETHTOOL_A_HEADER_FLAGS])
94-
req_info->flags = nla_get_u32(tb[ETHTOOL_A_HEADER_FLAGS]);
95-
103+
req_info->flags = flags;
96104
return 0;
97105
}
98106

0 commit comments

Comments
 (0)