aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/core/ethtool.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 9255bbdf81ff..ab5fa6336c84 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -1320,10 +1320,19 @@ static int ethtool_get_dump_data(struct net_device *dev,
1320 if (ret) 1320 if (ret)
1321 return ret; 1321 return ret;
1322 1322
1323 len = (tmp.len > dump.len) ? dump.len : tmp.len; 1323 len = min(tmp.len, dump.len);
1324 if (!len) 1324 if (!len)
1325 return -EFAULT; 1325 return -EFAULT;
1326 1326
1327 /* Don't ever let the driver think there's more space available
1328 * than it requested with .get_dump_flag().
1329 */
1330 dump.len = len;
1331
1332 /* Always allocate enough space to hold the whole thing so that the
1333 * driver does not need to check the length and bother with partial
1334 * dumping.
1335 */
1327 data = vzalloc(tmp.len); 1336 data = vzalloc(tmp.len);
1328 if (!data) 1337 if (!data)
1329 return -ENOMEM; 1338 return -ENOMEM;
@@ -1331,6 +1340,16 @@ static int ethtool_get_dump_data(struct net_device *dev,
1331 if (ret) 1340 if (ret)
1332 goto out; 1341 goto out;
1333 1342
1343 /* There are two sane possibilities:
1344 * 1. The driver's .get_dump_data() does not touch dump.len.
1345 * 2. Or it may set dump.len to how much it really writes, which
1346 * should be tmp.len (or len if it can do a partial dump).
1347 * In any case respond to userspace with the actual length of data
1348 * it's receiving.
1349 */
1350 WARN_ON(dump.len != len && dump.len != tmp.len);
1351 dump.len = len;
1352
1334 if (copy_to_user(useraddr, &dump, sizeof(dump))) { 1353 if (copy_to_user(useraddr, &dump, sizeof(dump))) {
1335 ret = -EFAULT; 1354 ret = -EFAULT;
1336 goto out; 1355 goto out;