Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp4292254rwb; Mon, 31 Jul 2023 04:56:37 -0700 (PDT) X-Google-Smtp-Source: APBJJlGT0p7YsN0QziDRhlSUnS8EXHoApYqUFnM7B4X+cd30m8SxzVoW0hLAtKABp7V7Y5OC4rpp X-Received: by 2002:a05:6a00:181c:b0:681:eddd:51fb with SMTP id y28-20020a056a00181c00b00681eddd51fbmr14049521pfa.18.1690804597587; Mon, 31 Jul 2023 04:56:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690804597; cv=none; d=google.com; s=arc-20160816; b=D6DwfFfJBa4vtWt82DwEVes5ttvSXjk/2THl6xXwKgf9a5Dxe6G/g4txgWbj19X0fs a0hqtYVqkrR3tIzmRIiGQQxE87mqywPnJ/o7x4wmgmlgOUK8L8K5lZWMDYa/nOOSWGVI SVbAjTmnEUaurs0neACEqgXX4J3odE9nvjdZG/p43QifF9uMZbnHqm0ZCu9UNnuQPSAb 5ZAg9PFb1gI8zgBRZonb+MoSCqRq8v81UJS0b/F15F5KX3Jgh4jfllE2/q8zOkyDCjER Wq1m1PxvxXRGbIwIRC7IFovZq6ucU2Hwn2zAekgLCxT0lWo4adSXJaCdtosA6vXqvZa6 +GCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9MdJiXGwyAkiC9mDh3NLqdU991BSWOeaVMH8LHr/VMM=; fh=TAfDNnOlyNVObujHdpXllERkS21nGVf5bQxmC/nrsxg=; b=iZvp8hlWHRauPa2vTuysi2zPZIGsfuoo/ioMGf4rKNEbgEQ5QxrB505igRqwbZYeja 79zkiVH1zTigrZPpFMYJEBMTdADSY5W/9ofshNRhbmlHlOK50GtuAprMPQqeEFPjSFa8 BOiQ7FYohFkwT3IzAubyLZB1IFkXe5PMF6a7THUvU3/0tZrjEFLVPmcHIn360YwpZBuG w9H4YDCzqqqgAzMlypZs7fZOYKrtMT1Tr3gab2cmE5jphQdGtMbN+1a54KYDC8Tp+Zr4 ZKqbUP9A7SM7v5TvVsSGh9d8fnWyc7UDIulY+BvTn7WddvShXg2e9LLY0Z734sNO0xTN LhqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gIBxG5FZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fi18-20020a056a00399200b006634db9e11dsi6902181pfb.313.2023.07.31.04.56.24; Mon, 31 Jul 2023 04:56:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gIBxG5FZ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231716AbjGaLGr (ORCPT + 99 others); Mon, 31 Jul 2023 07:06:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54362 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231934AbjGaLGo (ORCPT ); Mon, 31 Jul 2023 07:06:44 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA80098; Mon, 31 Jul 2023 04:06:37 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id a640c23a62f3a-98df3dea907so636468066b.3; Mon, 31 Jul 2023 04:06:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1690801596; x=1691406396; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=9MdJiXGwyAkiC9mDh3NLqdU991BSWOeaVMH8LHr/VMM=; b=gIBxG5FZsM49TCiOEwGy/nkwgZSwyZyL00R5QXTBVFthMK/oAShm4WhD/TXuiwXwAI QB3kFzfjjjuwFi2fcm3s5vDCHAHuDd3jTJwm7TrtmCgyiYZt4k7N//qivLlHeICX5pIZ cTZcmbMu1BF6jNF32D4oubDsjfLg/W9yzQdWHRQKetUsSeoMw5Hv7LlCK8B6CQuT0Ad+ rdrYY2KWMcfBDyHawpRcue8tCxUPRMPMmCpfN/J822SlEThnD31mYWEQGTpaVvVK4uwL FjR7WpEjzhRhV4O8IKbUmqEvhr4ZvNWg55NFSN+TUgszNG2BEnrCxZHfrgZBITOYELWa 9Nrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690801596; x=1691406396; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=9MdJiXGwyAkiC9mDh3NLqdU991BSWOeaVMH8LHr/VMM=; b=luvvtGZclaiNYlvi3k8TQCDD7M+9kT9sW3o2Iott9KFv+tBorfa55SUhA9F7YR/ci5 6/ZjiEk4tubtYc6dlxJAp7OpkoPPE4tBSrnoPwid6Jvav2nMEW8DemsOuhNPIZ7tSYlW Gc6dzTi3mz50XypHocgKIkuL6Bwuh3mbqFeVYkz6ahCv6psF1Sf7P+zO+wL0U4ajctHV 2bv2nCvQerqWJRACFUbvLgGeW19+gbwYC++QF4gtRAxT+AfcSw0fosJD+IAn/Q1asnCE enTaoBnxnfMv4GtZ3UwEXSnU3tCZQC7TrAZlZmXIW66XuEswwRNSh7hkUxSgYx4on8Dq jy/A== X-Gm-Message-State: ABy/qLbIOKocM0EQb1Th1Nnq088jjmAQQnpANERrD5+HpGBjE+8L7Xx+ RnY5pbPAFYyMAfHcDxAVU9LHt97czPirrg== X-Received: by 2002:a17:906:9b:b0:993:fba5:cdef with SMTP id 27-20020a170906009b00b00993fba5cdefmr6812802ejc.8.1690801595849; Mon, 31 Jul 2023 04:06:35 -0700 (PDT) Received: from nam-dell (ip-217-105-46-58.ip.prioritytelecom.net. [217.105.46.58]) by smtp.gmail.com with ESMTPSA id n26-20020a170906089a00b00992ddf46e65sm5961001eje.46.2023.07.31.04.06.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 04:06:35 -0700 (PDT) From: Nam Cao To: Larry Finger , Florian Schilhabel , Greg Kroah-Hartman , linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Cc: Nam Cao , syzbot+b08315e8cf5a78eed03c@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH] staging: rtl8712: fix race condition Date: Mon, 31 Jul 2023 13:06:20 +0200 Message-Id: <20230731110620.116562-1-namcaov@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In probe function, request_firmware_nowait() is called to load firmware asynchronously. At completion of firmware loading, register_netdev() is called. However, a mutex needed by netdev is initialized after the call to request_firmware_nowait(). Consequently, it can happen that register_netdev() is called before the driver is ready. Move the mutex initialization into r8712_init_drv_sw(), which is called before request_firmware_nowait(). Reported-by: syzbot+b08315e8cf5a78eed03c@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-staging/000000000000d9d4560601b8e0d7@google.com/T/#u Fixes: 8c213fa59199 ("staging: r8712u: Use asynchronous firmware loading") Cc: stable@vger.kernel.org Signed-off-by: Nam Cao --- drivers/staging/rtl8712/os_intfs.c | 1 + drivers/staging/rtl8712/usb_intf.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c index a2f3645be0cc..b18e6d9c832b 100644 --- a/drivers/staging/rtl8712/os_intfs.c +++ b/drivers/staging/rtl8712/os_intfs.c @@ -327,6 +327,7 @@ int r8712_init_drv_sw(struct _adapter *padapter) mp871xinit(padapter); init_default_value(padapter); r8712_InitSwLeds(padapter); + mutex_init(&padapter->mutex_start); return 0; diff --git a/drivers/staging/rtl8712/usb_intf.c b/drivers/staging/rtl8712/usb_intf.c index 37364d3101e2..df05213f922f 100644 --- a/drivers/staging/rtl8712/usb_intf.c +++ b/drivers/staging/rtl8712/usb_intf.c @@ -567,7 +567,6 @@ static int r871xu_drv_init(struct usb_interface *pusb_intf, if (rtl871x_load_fw(padapter)) goto deinit_drv_sw; init_completion(&padapter->rx_filter_ready); - mutex_init(&padapter->mutex_start); return 0; deinit_drv_sw: -- 2.34.1