OSDN Git Service

ethtool: fix potential userspace buffer overflow
authorVivien Didelot <vivien.didelot@gmail.com>
Mon, 3 Jun 2019 20:57:13 +0000 (16:57 -0400)
committerDavid S. Miller <davem@davemloft.net>
Thu, 6 Jun 2019 00:15:27 +0000 (17:15 -0700)
commit0ee4e76937d69128a6a66861ba393ebdc2ffc8a2
treeaf339fbc4798df5ef78a3c3241327ef8c3556999
parent0a8dd9f67cd0da7dc284f48b032ce00db1a68791
ethtool: fix potential userspace buffer overflow

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>
net/core/ethtool.c