summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorVivien Didelot <vivien.didelot@gmail.com>2019-06-03 16:57:13 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-06-11 12:24:12 +0200
commite5c6de6694ed690ffa64f996b7488eb3776b12a6 (patch)
treef8a792faa444d6294ee3054669826b718562e658 /net
parent8795708bc9393885a43573c9bf41ca6d322dfd5f (diff)
downloadlinux-stable-e5c6de6694ed690ffa64f996b7488eb3776b12a6.tar.gz
linux-stable-e5c6de6694ed690ffa64f996b7488eb3776b12a6.tar.bz2
linux-stable-e5c6de6694ed690ffa64f996b7488eb3776b12a6.zip
ethtool: fix potential userspace buffer overflow
[ Upstream commit 0ee4e76937d69128a6a66861ba393ebdc2ffc8a2 ] ethtool_get_regs() allocates a buffer of size ops->get_regs_len(), and pass it to the kernel driver via ops->get_regs() for filling. There is no restriction about what the kernel drivers can or cannot do with the open ethtool_regs structure. They usually set regs->version and ignore regs->len or set it to the same size as ops->get_regs_len(). But if userspace allocates a smaller buffer for the registers dump, we would cause a userspace buffer overflow in the final copy_to_user() call, which uses the regs.len value potentially reset by the driver. To fix this, make this case obvious and store regs.len before calling ops->get_regs(), to only copy as much data as requested by userspace, up to the value returned by ops->get_regs_len(). While at it, remove the redundant check for non-null regbuf. Signed-off-by: Vivien Didelot <vivien.didelot@gmail.com> Reviewed-by: Michal Kubecek <mkubecek@suse.cz> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'net')
-rw-r--r--net/core/ethtool.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/net/core/ethtool.c b/net/core/ethtool.c
index 9a53c66deb64..666164e7a11c 100644
--- a/net/core/ethtool.c
+++ b/net/core/ethtool.c
@@ -893,13 +893,16 @@ static int ethtool_get_regs(struct net_device *dev, char __user *useraddr)
return -ENOMEM;
}
+ if (regs.len < reglen)
+ reglen = regs.len;
+
ops->get_regs(dev, &regs, regbuf);
ret = -EFAULT;
if (copy_to_user(useraddr, &regs, sizeof(regs)))
goto out;
useraddr += offsetof(struct ethtool_regs, data);
- if (regbuf && copy_to_user(useraddr, regbuf, regs.len))
+ if (copy_to_user(useraddr, regbuf, reglen))
goto out;
ret = 0;