Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp4423642pxa; Mon, 10 Aug 2020 08:45:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXB77ZEqDvuQ6jutPBRC0PbDwZQKGK2SbD3jBoXfb1CzboBbjgyOJFvdRenYtWo9SgGJDR X-Received: by 2002:a17:906:ccda:: with SMTP id ot26mr7195768ejb.389.1597074304955; Mon, 10 Aug 2020 08:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597074304; cv=none; d=google.com; s=arc-20160816; b=bk2q7G1ydssyak7Jy8/NOUFcl6BGnwgrtcQlwLXbLS8cycMSb3TOrsgaDDJMzKOGqz VcJGa+lk7IB5GJFPhM6GI434AqLrhmS6gnBdl77P5rZcHV8a3IbxSpdFslxVwIZpH7mW 0oOeYxnpBfO9wE2nQNEr/3rVRmPAz7iMfQxbOUuCGRWsjhyU4V9b/oQLYWMXe0vyIB38 HpODgEYbzCc5SmodcOt5T9t7ajg3Qxpc/porOlUDdrB1h3w/LZcoAaHxO6aMzdSBDiI9 BAWDY5eXA9/iJVGkWl4ZHYltVMgpxB/8ZN2BRE5AUVAUmPKAYNJ/u/w0JJxOAwVrh5lh q6cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=IMaz7y/l+feBTze7IDV9feWpXet7GX4xyYjTsSLO5kA=; b=0Wyp3qK+GNMBJ3ZyI9UN73xjvgLHubFKDzoJ1767FJjpfiQgk+GoauentEulV3voln gFW2UytpOIlgqHcUElnL9ruVGVZUAnfYCx+aMwCxfvHg7rY0/ZMRWQOosYGr2P/0hPeM SyrL+cc64W7AZ49TpeNsNaRB8pDYHq/OxGwHtPqa6kj8QsbNfJXsONGS8Q3yKL5b/XUe u2fMINbqe9MxIi9O8/+6TwwfaUISawEVSmdGC95c4nI+lSlBRQUtUyKLMNXXP3EjG54c d9Uu88gHb5U0By8Plw4h+Z9UV62RkXGX75HRbE2uQkFAo8Xw1T2ACcp4/6U+bZBqSG5k UHPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kcOcI9Zy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k27si10679558ejb.408.2020.08.10.08.44.41; Mon, 10 Aug 2020 08:45:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kcOcI9Zy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728730AbgHJPmM (ORCPT + 99 others); Mon, 10 Aug 2020 11:42:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:53236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725873AbgHJPW0 (ORCPT ); Mon, 10 Aug 2020 11:22:26 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C07E72075F; Mon, 10 Aug 2020 15:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597072945; bh=PvXo4XK8AZRqUTr2CoG0DPYsgX5nyXoeG9ZFRmeqqhI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcOcI9ZyhMQsy2+ifnffLh3YGgH3G1QcUt1B+6tV9iLSpCv1gwrOGefnd8Uz8sYMj TjFMGs/yUqHPGuvUgrBpcWJRmyRTTl8+eQLLKdngxLhLIj+SKRbr0cPkKuPzvpnTrM mvZaR3EZQFUJoKihdNFpPE+rld/yurb0QfTuzSUc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+80899a8a8efe8968cde7@syzkaller.appspotmail.com, Rustam Kovhaev Subject: [PATCH 5.7 13/79] staging: rtl8712: handle firmware load failure Date: Mon, 10 Aug 2020 17:20:32 +0200 Message-Id: <20200810151812.778369620@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200810151812.114485777@linuxfoundation.org> References: <20200810151812.114485777@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rustam Kovhaev commit b4383c971bc5263efe2b0915ba67ebf2bf3f1ee5 upstream. when firmware fails to load we should not call unregister_netdev() this patch fixes a race condition between rtl871x_load_fw_cb() and r871xu_dev_remove() and fixes the bug reported by syzbot Reported-by: syzbot+80899a8a8efe8968cde7@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?extid=80899a8a8efe8968cde7 Signed-off-by: Rustam Kovhaev Cc: stable Link: https://lore.kernel.org/r/20200716151324.1036204-1-rkovhaev@gmail.com Signed-off-by: Greg Kroah-Hartman --- drivers/staging/rtl8712/hal_init.c | 3 ++- drivers/staging/rtl8712/usb_intf.c | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) --- a/drivers/staging/rtl8712/hal_init.c +++ b/drivers/staging/rtl8712/hal_init.c @@ -33,7 +33,6 @@ static void rtl871x_load_fw_cb(const str { struct _adapter *adapter = context; - complete(&adapter->rtl8712_fw_ready); if (!firmware) { struct usb_device *udev = adapter->dvobjpriv.pusbdev; struct usb_interface *usb_intf = adapter->pusb_intf; @@ -41,11 +40,13 @@ static void rtl871x_load_fw_cb(const str dev_err(&udev->dev, "r8712u: Firmware request failed\n"); usb_put_dev(udev); usb_set_intfdata(usb_intf, NULL); + complete(&adapter->rtl8712_fw_ready); return; } adapter->fw = firmware; /* firmware available - start netdev */ register_netdev(adapter->pnetdev); + complete(&adapter->rtl8712_fw_ready); } static const char firmware_file[] = "rtlwifi/rtl8712u.bin"; --- a/drivers/staging/rtl8712/usb_intf.c +++ b/drivers/staging/rtl8712/usb_intf.c @@ -595,13 +595,17 @@ static void r871xu_dev_remove(struct usb if (pnetdev) { struct _adapter *padapter = netdev_priv(pnetdev); - usb_set_intfdata(pusb_intf, NULL); - release_firmware(padapter->fw); /* 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; + release_firmware(padapter->fw); if (drvpriv.drv_registered) padapter->surprise_removed = true; - unregister_netdev(pnetdev); /* will call netdev_close() */ + if (pnetdev->reg_state != NETREG_UNINITIALIZED) + unregister_netdev(pnetdev); /* will call netdev_close() */ flush_scheduled_work(); udelay(1); /* Stop driver mlme relation timer */ @@ -614,6 +618,7 @@ static void r871xu_dev_remove(struct usb */ usb_put_dev(udev); } +firmware_load_fail: /* If we didn't unplug usb dongle and remove/insert module, driver * fails on sitesurvey for the first time when device is up. * Reset usb port for sitesurvey fail issue.