Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp1030121pxx; Tue, 27 Oct 2020 06:43:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwoKXBVcqNUAe2qQkVBhxCU17qs+4dIRc57IGo5M96/mtWG1oHRWxTnfXW5Ol7T82h7B+p X-Received: by 2002:a17:906:36cd:: with SMTP id b13mr2603133ejc.235.1603806231883; Tue, 27 Oct 2020 06:43:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603806231; cv=none; d=google.com; s=arc-20160816; b=X/TKZE64uSTA8G5UijY+OLmiqZ2hodcqhlT75vChK6N+aQN2FPJvjNAA2rPK0cVa/D 1EmLqKLhTQUmAVpQIcfRuMnaJfNteNLcrRUpONhOoQkha966RMi4BykUlF/tfBtJ6x0K STfbWHduferwjoGQxw1MKx89d/8evr7yN5VXHihle8vXSBawdH0WDHouGc20HQqmr8oD foy2aVy3poZL2MTM4Ibqjl7x6mqAqQ64Ob0pBWI1deiVQQC3OYFVos60f3wHLxcrUn7O 3GPAfzqmbFUkeIGbcIffR0v03XUGa1ii+X/pWE2QJawygt83/nUYEN5xzOoEPPG8BLVz lUVA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=f3/v/mJuMz825ePUYWRJ9nj2SnxZh3xDwCmaQmHt67A=; b=VxEU3LAZqw6Ey5y1rdUdOnEr/zWMwBunc0EwjThN+tzFRkiI8FWAdvNc55+mbBCvis 09KsDw6W03tWGPWeSJNUcMma1WGBih/CnJxFIl+Qp5Psajew/z5ECsetOCfPJ4/c1eEL 32gIb5CeflIqvcRImjcbJ12jxpzIKVAQVnd92TZezqmg7RVvfYGYl6qduitdVLoUq7cS d15v98H5QLWr3tuWIC+U4N+yxBGyF8ALROkfGR7VcBRr+lEwQP1Fi1zGt0FvxQJuzOep JlfYiIfNB/yDF1RrSYPdz7/SPp3mFb+JXuwI94PANlu4IGPUA21jECm2a6p2Jn1ivRWy VAEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="N/S22EE2"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si891140edt.471.2020.10.27.06.43.28; Tue, 27 Oct 2020 06:43:51 -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="N/S22EE2"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2444470AbgJ0Aiu (ORCPT + 99 others); Mon, 26 Oct 2020 20:38:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:48872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408991AbgJZXuD (ORCPT ); Mon, 26 Oct 2020 19:50:03 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8196421707; Mon, 26 Oct 2020 23:50:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756202; bh=FkpRkYZDBHzgwCdDMC+6K5UDKJIXKq4ENQKu9yOeDbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N/S22EE2JAtZj6cK9S/Vwl7gGXirdsxU9jcDn16DZe5suOyub5eN4yiA6f3vxw5Oe PzyvBnEVXm96Hl/JzLg0y/YiyveCo6SARprb+eedgK/XvTfqvA+pglkJLsmG00aMnw Z2+uJcxBKnFkypuwAYxVNmzxvH/zu+a6xunDCaaU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?J=C3=A9r=C3=B4me=20Pouiller?= , Greg Kroah-Hartman , Sasha Levin , devel@driverdev.osuosl.org Subject: [PATCH AUTOSEL 5.9 045/147] staging: wfx: fix potential use before init Date: Mon, 26 Oct 2020 19:47:23 -0400 Message-Id: <20201026234905.1022767-45-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026234905.1022767-1-sashal@kernel.org> References: <20201026234905.1022767-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Pouiller [ Upstream commit ce3653a8d3db096aa163fc80239d8ec1305c81fa ] 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 Link: https://lore.kernel.org/r/20200825085828.399505-8-Jerome.Pouiller@silabs.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/staging/wfx/sta.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/staging/wfx/sta.c b/drivers/staging/wfx/sta.c index 4e30ab17a93d4..b96c83671caeb 100644 --- a/drivers/staging/wfx/sta.c +++ b/drivers/staging/wfx/sta.c @@ -760,17 +760,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; @@ -787,12 +776,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); + 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); - wfx_tx_queues_init(wvif); - wfx_tx_policy_init(wvif); + 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 @@ -824,6 +823,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 -- 2.25.1