Re: [BUG] net: macb: Use-After-Free when removing the module

From: Jakub Kicinski
Date: Thu Mar 03 2022 - 10:57:47 EST


On Thu, 3 Mar 2022 20:24:53 +0800 Zheyu Ma wrote:
> When removing the macb_pci module, the driver will cause a UAF bug.
>
> Commit d82d5303c4c5 ("net: macb: fix use after free on rmmod") moves
> the platform_device_unregister() after clk_unregister(), but this
> introduces another UAF bug.

The layering is all weird here. macb_probe() should allocate a private
structure for the _PCI driver_ which it can then attach to
struct pci_dev *pdev as driver data. Then free it in remove.
It shouldn't stuff its information into the platform device.

Are you willing to send a fix like that?