]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit
staging: rtl8712: fix memory leak in rtl871x_load_fw_cb
authorPavel Skripkin <paskripkin@gmail.com>
Sun, 13 Jun 2021 22:00:19 +0000 (01:00 +0300)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 13 Aug 2021 07:46:18 +0000 (09:46 +0200)
commit9a9f3937462bdfc344b29c309d533a3f6ce81c25
treee7564395d660d23a6a505b5693dabf6c80be1280
parent9eccafaf9b95913053909cdd7af91b1b2ed9b0ba
staging: rtl8712: fix memory leak in rtl871x_load_fw_cb

BugLink: https://bugs.launchpad.net/bugs/1938199
[ Upstream commit e02a3b945816a77702a2769a70ef5f9b06e49d54 ]

There is a leak in rtl8712 driver.
The problem was in non-freed adapter data if
firmware load failed.

This leak can be reproduced with this code:
https://syzkaller.appspot.com/text?tag=ReproC&x=16612f02d00000,
Autoload must fail (to not hit memory leak reported by syzkaller)

There are 2 possible ways how rtl871x_load_fw_cb() and
r871xu_dev_remove() can be called (in case of fw load error).

1st case:
r871xu_dev_remove() then rtl871x_load_fw_cb()

In this case r871xu_dev_remove() will wait for
completion and then will jump to the end, because
rtl871x_load_fw_cb() set intfdata to NULL:

if (pnetdev) {
struct _adapter *padapter = netdev_priv(pnetdev);

/* never exit with a firmware callback pending */
wait_for_completion(&padapter->rtl8712_fw_ready);
pnetdev = usb_get_intfdata(pusb_intf);
usb_set_intfdata(pusb_intf, NULL);
if (!pnetdev)
goto firmware_load_fail;

... clean up code here ...
}

2nd case:
rtl871x_load_fw_cb() then r871xu_dev_remove()

In this case pnetdev (from code snippet above) will
be zero (because rtl871x_load_fw_cb() set it to NULL)
And clean up code won't be executed again.

So, in all cases we need to free adapted data in rtl871x_load_fw_cb(),
because disconnect function cannot take care of it. And there won't be
any race conditions, because complete() call happens after setting
intfdata to NULL.

In previous patch I moved out free_netdev() from r8712_free_drv_sw()
and that's why now it's possible to free adapter data and then call
complete.

Fixes: 8c213fa59199 ("staging: r8712u: Use asynchronous firmware loading")
Signed-off-by: Pavel Skripkin <paskripkin@gmail.com>
Link: https://lore.kernel.org/r/81e68fe0194499cc2e7692d35bc4dcf167827d8f.1623620630.git.paskripkin@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Kamal Mostafa <kamal@canonical.com>
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
drivers/staging/rtl8712/hal_init.c