Re: [PATCH net-next] net: ethtool: Fix out-of-bounds copy to user

From: Ding Hui
Date: Fri Jun 02 2023 - 21:51:54 EST


On 2023/6/3 2:02, Alexander Duyck wrote:
On Fri, Jun 2, 2023 at 9:37 AM Andrew Lunn <andrew@xxxxxxx> wrote:

What this change is essentially doing is clamping the copied data to
the lesser of the current value versus the value when the userspace
was allocated. However I am wondering now if we shouldn't just update
the size value and return that as some sort of error for the userspace
to potentially reallocate and repeat until it has the right size.

I'm not sure we should be putting any effort into the IOCTL
interface. It is deprecated. We should fix overrun problems, but i
would not change the API. Netlink handles this atomically, and that is
the interface tools should be using, not this IOCTL.

If that is the case maybe it would just make more sense to just return
an error if we are at risk of overrunning the userspace allocated
buffer.


In that case, I can modify to return an error, however, I think the
ENOSPC or EFBIG mentioned in a previous email may not be suitable,
maybe like others length/size checking return EINVAL.

Another thing I wondered is that should I update the current length
back to user if user buffer is not enough, assuming we update the new
length with error returned, the userspace can use it to reallocate
buffer if he wants to, which can avoid re-call previous ioctl to get
the new length.

--
Thanks,
- Ding Hui