Re: [PATCH v4] net: ethtool: do not call get_regs() for zero-length dumps
From: Andrew Lunn
Date: Sat Nov 28 2026 - 11:06:01 EST
On Fri, Nov 27, 2026 at 03:23:48PM +0800, YuanZhe Liu wrote:
> ethtool_get_regs() passes the user-supplied regs.len to the driver
> unchanged, including zero. A zero-length dump has nothing to fill in,
> but the driver callback still runs and may use that length for its own
> I/O. A zero-length transfer cannot move any data, and some transports
> report a warning for it, which becomes a denial of service when
> panic_on_warn is set.
>
> Return success without calling into the driver when the requested dump
> length is zero. The check comes after get_regs_len() so that drivers
> which cannot provide a dump still return their error to userspace:
> ethtool(8) sends a zero-length request when ETHTOOL_GDRVINFO reported
> no regdump_len, which is what happens when get_regs_len() fails.
>
> This does not remove a way to query the dump size: the uAPI tells users
> to obtain it from ETHTOOL_GDRVINFO.regdump_len, and the core only clamps
> an oversized regs.len down to get_regs_len(). Since a zero-length dump
> returns no data, the driver also cannot fill in regs.version; callers
> that need the version have to request the dump.
>
> The problem was found while testing the ethtool register dump path of
> an MCS7830 adapter.
>
> Co-developed-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
> Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
> Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
> Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
Reviewed-by: Andrew Lunn <andrew@xxxxxxx>
Andrew