From patchwork Tue Aug 25 08:58:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= X-Patchwork-Id: 261974 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, RCVD_ILLEGAL_IP, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CE96C433E1 for ; Tue, 25 Aug 2020 09:00:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B7792067C for ; Tue, 25 Aug 2020 09:00:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=silabs.onmicrosoft.com header.i=@silabs.onmicrosoft.com header.b="dCygFhYQ" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729699AbgHYI7t (ORCPT ); Tue, 25 Aug 2020 04:59:49 -0400 Received: from mail-dm6nam12on2052.outbound.protection.outlook.com ([40.107.243.52]:53959 "EHLO NAM12-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729646AbgHYI7b (ORCPT ); Tue, 25 Aug 2020 04:59:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XCVwmowTOOdBcrCMXMsAHGnXXJ9Z9PcZmPu2VXiIKbd4FwHqLIh5xooEetipioHhDkDtVIZZkduE//FP2AQPGkUcF3HNzmsnZx84HtDzlSckvw9FUggfk9sS3HnZ6XobNRIsWm+aMPFXDw86zwqj8byWPYqLkurYcVW9qvoJeB+RT59t7H7VVEmE7dMR/EC3FGdkmqMeTCqbaHw6eoSZdeRjbtC6dR5NQsPrCkPnKKzaqRwaJRVenqcTOvF8V3Ok1YDiaXGDA9oNF6gOw/vYh7FdqEDjCvI5sARYj7iZRFPfgzTFMFEdwQUwADe5acxKJg8cYBkdqUEhcg/DmIp81A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vUCfAVxEEjw5fe6klsi9DKE0qPl2IHDqTZNcYCPBzxQ=; b=XfI3s2RnNLYEVlNoUiT58SbAsJY7SMLYxpAu08aw54Yy+BfEHSeNxoxAWhPSif8JtX3C9pArUb8tp1DPxvB+zTdVm8USusxueEJ19e49U9YvqwIrnesBnwlZD71Gk3mhG3+/NIk402l1FzhTQYmTp8MXAK1245tqbjL7c9CZweHHdZVYiBPj+SP5EMrBPdJckrYgqhD6p31/SpnDB+mi+xBJ5CYTKtNevJJ5Xh1GLbyJ2Jlne9KnbEfVI8rMwRJVYIOVH3vw4nhCH4g0s1x+2XQWaSY7oq3GtbVG3iPeHrY7oo6xOtE5cqzRwwyv7J2+RDGR9Cp2f5KFjtlIcOOn1w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=silabs.com; dmarc=pass action=none header.from=silabs.com; dkim=pass header.d=silabs.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=silabs.onmicrosoft.com; s=selector2-silabs-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vUCfAVxEEjw5fe6klsi9DKE0qPl2IHDqTZNcYCPBzxQ=; b=dCygFhYQ2C/qUcqC8Xhf34BNtyDqieAq6L4DqAy7SAUmOaHZIuM5yRMuH2nilwW1eLp/ZVDGuCbrsbyDFW2DOtY8WEysAMNL3Ce6+SKw2RTsIhqQNMJy8Y3cJH0D2URWo1iRp5JGvEVFdnwk4jhDToPRgHr7bcTJwBEvkCCzRE8= Authentication-Results: driverdev.osuosl.org; dkim=none (message not signed) header.d=none; driverdev.osuosl.org; dmarc=none action=none header.from=silabs.com; Received: from SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) by SN6PR11MB3501.namprd11.prod.outlook.com (2603:10b6:805:d4::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3305.26; Tue, 25 Aug 2020 08:59:07 +0000 Received: from SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::85c9:1aa9:aeab:3fa6]) by SN6PR11MB2718.namprd11.prod.outlook.com ([fe80::85c9:1aa9:aeab:3fa6%4]) with mapi id 15.20.3305.026; Tue, 25 Aug 2020 08:59:07 +0000 From: Jerome Pouiller To: devel@driverdev.osuosl.org, linux-wireless@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Greg Kroah-Hartman , Kalle Valo , "David S . Miller" , =?utf-8?b?SsOpcsO0bWUgUG91aWxsZXI=?= Subject: [PATCH v2 08/12] staging: wfx: fix potential use before init Date: Tue, 25 Aug 2020 10:58:24 +0200 Message-Id: <20200825085828.399505-8-Jerome.Pouiller@silabs.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200825085828.399505-1-Jerome.Pouiller@silabs.com> References: <20200825085828.399505-1-Jerome.Pouiller@silabs.com> X-ClientProxiedBy: PR3P192CA0002.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:56::7) To SN6PR11MB2718.namprd11.prod.outlook.com (2603:10b6:805:63::18) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by PR3P192CA0002.EURP192.PROD.OUTLOOK.COM (2603:10a6:102:56::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.19 via Frontend Transport; Tue, 25 Aug 2020 08:59:05 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [37.71.187.125] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 95f51a34-5838-43f9-974f-08d848d51f81 X-MS-TrafficTypeDiagnostic: SN6PR11MB3501: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: snfEWsImJyio9guHSCrMeH3/FFsoJvuwpe5rgKjIJ3DdQ1eNj/XLUus+Xg7+mbJPNtXn/BjZPArv4PmZ2gCzkU3GvezwFZuuaIKqsyO9HvQ7gUTmX4kKR+Xs1/8ifdUKEdp/bbjYJZ/YrRt8lYvCB2q8TZePUMKDdcdSe10R23v8WjD905sBGqFLSFH29fBUtm0YCWSfzezdpobBBXYJwoLfTwp/i+rTEuomFEwuLu4S4ZjJaNgnjY5V+fvU9WR0Rm0bPeJO7swQo+XUVWTWl1YG5rVRD0Spddk+r2csxT1yTD6Gfo66rjZRVvgc90h4 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:SN6PR11MB2718.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(136003)(39830400003)(396003)(346002)(376002)(366004)(316002)(5660300002)(478600001)(107886003)(1076003)(8936002)(83380400001)(16576012)(956004)(66556008)(66476007)(26005)(2616005)(186003)(8676002)(86362001)(66946007)(6486002)(54906003)(6666004)(36756003)(4326008)(66574015)(2906002)(52116002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData: 0dqNlV+XaIcVSytfSddL+5by+dPs2xeuzAwaGvRp8079faLgCmy22s4AUaverMnIyuaevCsSCnydcB555HtFuD7QcTBEwl04DrDqkRJ27T7pgvoMAcYNgsIuYU46/OuxnpK5hs7np43KSr6+465QxjxVwqJe3dVoe9Dlje8KhUzErUBZw4KY0HhtjX9rsacsFGD/QeRmhKUZWKXDu71jnijxb2MkirROFDaUlmYGpXMGXkv0I+aBXGaYwZtzE/OAEYGUdNfyt8IGlxxA1DUDHqExw9c6TIQ/Fvn+0c8Brto8IylPsZXab+0MpSiC04VJuhFjtaKBJkzS6mEeJ3J7SSl7EP2mOU07vn6nqUrQTbrYHLOmSe++SKJ4S3J17plz8eanDUe7mLfK6VnwbJqLlyDVj9eV0mzq8c5lCskIdMKTG+L1ga/swhSPzMcz8EQ9A6n2/+Dkpotb+cUDQMUvAU4zHxJiIuJqxgqlzXh34Y1gDVBhZdRhMh5oerqlZNPzU48+xzNX9+uoP2N7FlOiualShAxYMltIW4XeehMIhNSZBbztePV4xz1VwiKAR9HZyoOC2I/uI0ScT5kWTWvHN0EcjfM+wld0eZfzW+dYG57Dw6G3Zmoj8toYu8iRpn6CE7NfANmpZQDwxJHV65vRQw== X-OriginatorOrg: silabs.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95f51a34-5838-43f9-974f-08d848d51f81 X-MS-Exchange-CrossTenant-AuthSource: SN6PR11MB2718.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2020 08:59:06.9793 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 54dbd822-5231-4b20-944d-6f4abcd541fb X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: w321RENZLfi7gXx7jtMjs+Q+SLxRsZPM6coviv02wjPJ6aFIFKCzJ5YyQABXLpct06+4XtoEoLue59bvY50Q3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN6PR11MB3501 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jérôme Pouiller The trace below can appear: [83613.832200] INFO: trying to register non-static key. [83613.837248] the code is fine but needs lockdep annotation. [83613.842808] turning off the locking correctness validator. [83613.848375] CPU: 3 PID: 141 Comm: kworker/3:2H Tainted: G O 5.6.13-silabs15 #2 [83613.857019] Hardware name: BCM2835 [83613.860605] Workqueue: events_highpri bh_work [wfx] [83613.865552] Backtrace: [83613.868041] [] (dump_backtrace) from [] (show_stack+0x20/0x24) [83613.881463] [] (show_stack) from [] (dump_stack+0xe8/0x114) [83613.888882] [] (dump_stack) from [] (register_lock_class+0x748/0x768) [83613.905035] [] (register_lock_class) from [] (__lock_acquire+0x88/0x13dc) [83613.924192] [] (__lock_acquire) from [] (lock_acquire+0xe8/0x274) [83613.942644] [] (lock_acquire) from [] (_raw_spin_lock_irqsave+0x58/0x6c) [83613.961714] [] (_raw_spin_lock_irqsave) from [] (skb_dequeue+0x24/0x78) [83613.974967] [] (skb_dequeue) from [] (wfx_tx_queues_get+0x96c/0x1294 [wfx]) [83613.989728] [] (wfx_tx_queues_get [wfx]) from [] (bh_work+0x454/0x26d8 [wfx]) [83614.009337] [] (bh_work [wfx]) from [] (process_one_work+0x23c/0x7ec) [83614.028141] [] (process_one_work) from [] (worker_thread+0x4c/0x55c) [83614.046861] [] (worker_thread) from [] (kthread+0x138/0x168) [83614.064876] [] (kthread) from [] (ret_from_fork+0x14/0x20) [83614.072200] Exception stack(0xecad3fb0 to 0xecad3ff8) [83614.077323] 3fa0: 00000000 00000000 00000000 00000000 [83614.085620] 3fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 [83614.093914] 3fe0: 00000000 00000000 00000000 00000000 00000013 00000000 Indeed, the code of wfx_add_interface() shows that the interface is enabled to early. So, the spinlock associated with some skb_queue may not yet initialized when wfx_tx_queues_get() is called. Signed-off-by: Jérôme Pouiller --- drivers/staging/wfx/sta.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c index 7a4c9f63c4a2..a890fe32161c 100644 --- a/drivers/staging/wfx/sta.c +++ b/drivers/staging/wfx/sta.c @@ -759,17 +759,6 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) return -EOPNOTSUPP; } - for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) { - if (!wdev->vif[i]) { - wdev->vif[i] = vif; - wvif->id = i; - break; - } - } - if (i == ARRAY_SIZE(wdev->vif)) { - mutex_unlock(&wdev->conf_mutex); - return -EOPNOTSUPP; - } // FIXME: prefer use of container_of() to get vif wvif->vif = vif; wvif->wdev = wdev; @@ -786,12 +775,22 @@ int wfx_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) init_completion(&wvif->scan_complete); INIT_WORK(&wvif->scan_work, wfx_hw_scan_work); - mutex_unlock(&wdev->conf_mutex); - - hif_set_macaddr(wvif, vif->addr); - wfx_tx_queues_init(wvif); wfx_tx_policy_init(wvif); + + for (i = 0; i < ARRAY_SIZE(wdev->vif); i++) { + if (!wdev->vif[i]) { + wdev->vif[i] = vif; + wvif->id = i; + break; + } + } + WARN(i == ARRAY_SIZE(wdev->vif), "try to instantiate more vif than supported"); + + hif_set_macaddr(wvif, vif->addr); + + mutex_unlock(&wdev->conf_mutex); + wvif = NULL; while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { // Combo mode does not support Block Acks. We can re-enable them @@ -823,6 +822,7 @@ void wfx_remove_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) wvif->vif = NULL; mutex_unlock(&wdev->conf_mutex); + wvif = NULL; while ((wvif = wvif_iterate(wdev, wvif)) != NULL) { // Combo mode does not support Block Acks. We can re-enable them