aboutsummaryrefslogtreecommitdiffstats
path: root/net/core
diff options
context:
space:
mode:
authorMichal Schmidt <mschmidt@redhat.com>2013-07-01 11:23:30 -0400
committerDavid S. Miller <davem@davemloft.net>2013-07-02 03:15:56 -0400
commitc590b5e2f05b5e98e614382582b7ae4cddb37599 (patch)
treeee104276146080fdf350eeb7a5f6d9586c2e209c /net/core
parent8cc2d927c26a677415a9d0d23b9a043107f948c3 (diff)
ethtool: make .get_dump_data() harder to misuse by drivers
As the patch "bnx2x: remove zeroing of dump data buffer" showed, it is too easy implement .get_dump_data incorrectly in a driver. Let's make sure drivers cannot get confused by userspace requesting a too big dump. Also WARN if the driver sets dump->len to something weird and make sure the length reported to userspace is the actual length of data copied to userspace. Signed-off-by: Michal Schmidt <mschmidt@redhat.com> Reviewed-by: Ben Hutchings <ben@decadent.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-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;