From patchwork Mon Jan 4 17:07:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 356417 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=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham 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 58847C433E0 for ; Mon, 4 Jan 2021 17:08:33 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 09F48224DE for ; Mon, 4 Jan 2021 17:08:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 09F48224DE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 34752167A; Mon, 4 Jan 2021 18:07:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 34752167A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1609780109; bh=a6Xa+o2Z1djjlfRar/fnWRZMiq5OiDxI350DX0sGuTk=; h=From:To:Subject:Date:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=biHuXVS85NUKgAZyhWQwIl4X/dARRY3LGUxMS1PPUkXwvWroHrS0U1Zi/AlYzB3mY kI1vBHzAxKtVj+iMBR/pLU7jJYnvofV9JC9+Km5XWFnlpMwGLQ6VffFoaHCQeHhODw i/aMjtZe8fta5XYCrILwby1wIxX/ag+b7+TX+OFY= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 87F0EF80165; Mon, 4 Jan 2021 18:07:38 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id AFD74F80166; Mon, 4 Jan 2021 18:07:36 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 59479F8012C for ; Mon, 4 Jan 2021 18:07:24 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 59479F8012C Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="RCx57qhm" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1609780043; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=2de/+aI5hpKlvLFsaL1DCMrkMJh+VBZyPlNqnu8zUTI=; b=RCx57qhmjY3+xNtTjdihKWPaJSLY8/8zgzbrpV5WMCnIL3E4z02Nfj6yJCcdtwy1cvID84 vwBiXGdc0DwFEx/JWJYuPZYSCIIcI5yT+jCm8s9I1j3gBdtTInsQ+hmprFvImYOXWMEzOG SlXXjV3NHx+qo5Vys6NWFkY6WGYoCdk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-429-AGzmScoiOH6WoGV6VKqzvQ-1; Mon, 04 Jan 2021 12:07:20 -0500 X-MC-Unique: AGzmScoiOH6WoGV6VKqzvQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 87FF4100F340; Mon, 4 Jan 2021 17:07:17 +0000 (UTC) Received: from x1.localdomain (ovpn-112-167.ams2.redhat.com [10.36.112.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 858C86F921; Mon, 4 Jan 2021 17:07:14 +0000 (UTC) From: Hans de Goede To: Johannes Berg , "David S . Miller" , Jakub Kicinski , Cezary Rojewski , Pierre-Louis Bossart , Liam Girdwood , Jie Yang , Mark Brown Subject: [PATCH] cfg80211: Fix "suspicious RCU usage in wiphy_apply_custom_regulatory" warning/backtrace Date: Mon, 4 Jan 2021 18:07:13 +0100 Message-Id: <20210104170713.66956-1-hdegoede@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Cc: alsa-devel@alsa-project.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Ilan Peer , Hans de Goede X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" Commit beee24695157 ("cfg80211: Save the regulatory domain when setting custom regulatory") adds a get_wiphy_regdom call to wiphy_apply_custom_regulatory. But as the comment above wiphy_apply_custom_regulatory says: "/* Used by drivers prior to wiphy registration */" this function is used by driver's probe function before the wiphy is registered and at this point wiphy->regd will typically by NULL and calling rcu_dereference_rtnl on a NULL pointer causes the following warning/backtrace: ============================= WARNING: suspicious RCU usage 5.11.0-rc1+ #19 Tainted: G W ----------------------------- net/wireless/reg.c:144 suspicious rcu_dereference_check() usage! other info that might help us debug this: rcu_scheduler_active = 2, debug_locks = 1 2 locks held by kworker/2:0/22: #0: ffff9a4bc104df38 ((wq_completion)events){+.+.}-{0:0}, at: process_one_work+0x1ee/0x570 #1: ffffb6e94010be78 ((work_completion)(&fw_work->work)){+.+.}-{0:0}, at: process_one_work+0x1ee/0x570 stack backtrace: CPU: 2 PID: 22 Comm: kworker/2:0 Tainted: G W 5.11.0-rc1+ #19 Hardware name: LENOVO 60073/INVALID, BIOS 01WT17WW 08/01/2014 Workqueue: events request_firmware_work_func Call Trace: dump_stack+0x8b/0xb0 get_wiphy_regdom+0x57/0x60 [cfg80211] wiphy_apply_custom_regulatory+0xa0/0xf0 [cfg80211] brcmf_cfg80211_attach+0xb02/0x1360 [brcmfmac] brcmf_attach+0x189/0x460 [brcmfmac] brcmf_sdio_firmware_callback+0x78a/0x8f0 [brcmfmac] brcmf_fw_request_done+0x67/0xf0 [brcmfmac] request_firmware_work_func+0x3d/0x70 process_one_work+0x26e/0x570 worker_thread+0x55/0x3c0 ? process_one_work+0x570/0x570 kthread+0x137/0x150 ? __kthread_bind_mask+0x60/0x60 ret_from_fork+0x22/0x30 Add a check for wiphy->regd being NULL before calling get_wiphy_regdom (as is already done in other places) to fix this. wiphy->regd will likely always be NULL when wiphy_apply_custom_regulatory gets called, so arguably the tmp = get_wiphy_regdom() and rcu_free_regdom(tmp) calls should simply be dropped, this patch keeps the 2 calls, to allow drivers to call wiphy_apply_custom_regulatory more then once if necessary. Cc: Ilan Peer Fixes: beee24695157 ("cfg80211: Save the regulatory domain when setting custom regulator") Signed-off-by: Hans de Goede --- net/wireless/reg.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index bb72447ad960..9254b9cbaa21 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -2547,7 +2547,7 @@ static void handle_band_custom(struct wiphy *wiphy, void wiphy_apply_custom_regulatory(struct wiphy *wiphy, const struct ieee80211_regdomain *regd) { - const struct ieee80211_regdomain *new_regd, *tmp; + const struct ieee80211_regdomain *new_regd, *tmp = NULL; enum nl80211_band band; unsigned int bands_set = 0; @@ -2571,7 +2571,8 @@ void wiphy_apply_custom_regulatory(struct wiphy *wiphy, if (IS_ERR(new_regd)) return; - tmp = get_wiphy_regdom(wiphy); + if (wiphy->regd) + tmp = get_wiphy_regdom(wiphy); rcu_assign_pointer(wiphy->regd, new_regd); rcu_free_regdom(tmp); }