Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp13965638pxu; Mon, 4 Jan 2021 09:10:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzRZ8tTFiW7OrudXZII8AwB0AbtOBlw/W18kVk4D0xqqQEn5ZMAweNzvd5K+2j5hZDKuoFI X-Received: by 2002:a50:998f:: with SMTP id m15mr57299628edb.342.1609780206392; Mon, 04 Jan 2021 09:10:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609780206; cv=none; d=google.com; s=arc-20160816; b=DQ0RC7eX4oZulwpc4/RMr+0Al7akcQ+8WVbMKxWjFyy8vf6fl+GR9jeYdlhj6S/8CD 1QZ5UZglaBJa3btMkhIHJez8D94nvG4CmRhxOyIRlyrOtoCOLr7DvEnMCjMyhJdVtA3S XQdAS12321EtLq+sU4l9gsibyqX8C+q9yJdydD1ewpuig54/BxfVT4sHPBmQHMdqjzCT moLE1sFWFtPEiMPvIHC/ZEOYuzDfhu2cIm8Y1hiJJNSFXMq6pIYJAEnDENFiWvF241bb 5CG4oGiDlzQQzZraf283mo/Q13sIVaajaC7tIIutx/kKYSYwf2J4tX95fx+f3Hu9WfAs q3/Q== 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=2de/+aI5hpKlvLFsaL1DCMrkMJh+VBZyPlNqnu8zUTI=; b=VDWMqF4vpWYqFPqf9fP2pFA0A4dWjUvrDRQ3NEYilbp3YD9H093ho6toOmbdkfQt8e UK5SQ9oR9wu6oNXC3cZ/8XF3zhybK0FB4p2S4IZ8CgJLMaRhSpXcQ89h1ua2mKgx6nTt vUPdYNadAsm5tCAJKrGsuwrQcVE++3n5r7cVxZQjaXYvkUgmuQeThQWw3K9OgDDYQM63 tQBcZhNz6sVShERwTPuj/bfZdjR27SDT9Q8sru52KhEAXrIeRZOEhYEb7IAgPMUfkCKx X1XFBDTyPu/E8mDz7cZGeW/vEaXB67fF4ZAh8inLllWc0/XBpaEoDzaRSbZjnBO//VAO f0kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RCx57qhm; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f17si31740684edx.585.2021.01.04.09.09.43; Mon, 04 Jan 2021 09:10:06 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=RCx57qhm; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726148AbhADRIv (ORCPT + 99 others); Mon, 4 Jan 2021 12:08:51 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:41575 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726163AbhADRIu (ORCPT ); Mon, 4 Jan 2021 12:08:50 -0500 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 Cc: Hans de Goede , linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, alsa-devel@alsa-project.org, Ilan Peer 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 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); } -- 2.28.0