Commit 4d1fb7cd authored by Jakub Kicinski's avatar Jakub Kicinski Committed by David S. Miller

ethtool: add a stricter length check

There has been a few errors in the ethtool reply size calculations,
most of those are hard to trigger during basic testing because of
skb size rounding up and netdev names being shorter than max.
Add a more precise check.

This change will affect the value of payload length displayed in
case of -EMSGSIZE but that should be okay, "payload length" isn't
a well defined term here.
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1b3fc771
...@@ -315,9 +315,9 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) ...@@ -315,9 +315,9 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
struct ethnl_req_info *req_info = NULL; struct ethnl_req_info *req_info = NULL;
const u8 cmd = info->genlhdr->cmd; const u8 cmd = info->genlhdr->cmd;
const struct ethnl_request_ops *ops; const struct ethnl_request_ops *ops;
int hdr_len, reply_len;
struct sk_buff *rskb; struct sk_buff *rskb;
void *reply_payload; void *reply_payload;
int reply_len;
int ret; int ret;
ops = ethnl_default_requests[cmd]; ops = ethnl_default_requests[cmd];
...@@ -346,15 +346,20 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info) ...@@ -346,15 +346,20 @@ static int ethnl_default_doit(struct sk_buff *skb, struct genl_info *info)
ret = ops->reply_size(req_info, reply_data); ret = ops->reply_size(req_info, reply_data);
if (ret < 0) if (ret < 0)
goto err_cleanup; goto err_cleanup;
reply_len = ret + ethnl_reply_header_size(); reply_len = ret;
ret = -ENOMEM; ret = -ENOMEM;
rskb = ethnl_reply_init(reply_len, req_info->dev, ops->reply_cmd, rskb = ethnl_reply_init(reply_len + ethnl_reply_header_size(),
req_info->dev, ops->reply_cmd,
ops->hdr_attr, info, &reply_payload); ops->hdr_attr, info, &reply_payload);
if (!rskb) if (!rskb)
goto err_cleanup; goto err_cleanup;
hdr_len = rskb->len;
ret = ops->fill_reply(rskb, req_info, reply_data); ret = ops->fill_reply(rskb, req_info, reply_data);
if (ret < 0) if (ret < 0)
goto err_msg; goto err_msg;
WARN_ONCE(rskb->len - hdr_len > reply_len,
"ethnl cmd %d: calculated reply length %d, but consumed %d\n",
cmd, reply_len, rskb->len - hdr_len);
if (ops->cleanup_data) if (ops->cleanup_data)
ops->cleanup_data(reply_data); ops->cleanup_data(reply_data);
......
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