Re: general protection fault in ethtool_get_drvinfo

From: Andrew Lunn
Date: Thu Sep 15 2022 - 16:03:06 EST


On Fri, Sep 16, 2022 at 12:02:22AM +0800, Rondreis wrote:
> Hello,
>
> When fuzzing the Linux kernel driver v6.0-rc4, the following crash was
> triggered.
>
> HEAD commit: 7e18e42e4b280c85b76967a9106a13ca61c16179
> git tree: upstream
>
> kernel config: https://pastebin.com/raw/xtrgsXP3
> C reproducer: https://pastebin.com/raw/RtX3naYU
> console output: https://pastebin.com/raw/HqjSMu2n
>
> Basically, in the c reproducer, we use the gadget module to emulate
> attaching a USB device(vendor id: 0x1b3d, product id: 0x19c, with the
> midi function) and executing some simple sequence of system calls.
> To reproduce this crash, we utilize a third-party library to emulate
> the attaching process: https://github.com/linux-usb-gadgets/libusbgx.
> Just clone this repository, install it, and compile the c
> reproducer with ``` gcc crash.c -lusbgx -lconfig -o crash ``` will do
> the trick.
>
> I would appreciate it if you have any idea how to solve this bug.
>
> The crash report is as follows:
> general protection fault, probably for non-canonical address
> 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007]
> CPU: 1 PID: 6495 Comm: systemd-udevd Not tainted 6.0.0-rc4+ #20
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
> 1.13.0-1ubuntu1.1 04/01/2014
> RIP: 0010:ethtool_get_drvinfo+0x533/0x7d0 net/ethtool/ioctl.c:723

If this can be trusted:

723: strlcpy(rsp->info.driver, dev->dev.parent->driver->name,
724: sizeof(rsp->info.driver));

So it looks like dev->dev.parent->driver->name is invalid. That i
would say is a driver bug, a driver should always have a name.

What driver is dev->dev.parent->driver?

Andrew