Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3923059imm; Mon, 8 Oct 2018 11:45:04 -0700 (PDT) X-Google-Smtp-Source: ACcGV61xb4T5v7LIFGn66UO5ThBhtmZwbUm0apDHTf9vHkAGX1xF3Mlsv6rfHAqrZoqOn+LK5rSp X-Received: by 2002:a63:541e:: with SMTP id i30-v6mr22542745pgb.413.1539024304136; Mon, 08 Oct 2018 11:45:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024304; cv=none; d=google.com; s=arc-20160816; b=edNZzsICYWak8cRsj87DREQtjuXm1zvJvklTAkW9vapIORJgxSd22z3XDdRmW8oLr/ VZ2pwkkQBqPnTnej/gs5399/Cqg9Lec1PY130iWJ6jhccNvZg+RMHZ3qwGwIDJ/imlJL khiPyE/AR1y+HUTE515dntmjUUvQGDGM4oabxy9QW91EvhULYVjFFj6IBA/ITnaitpF+ J5fXFxuw4Ik+hg6Upq8Xp1zdjn2w58SWvQxV5iJnSI0rXxgjoJfXwXrx6wQX8MMPHlO7 kw9CXoukWISXhbyeIMBv1rxNRyWCgZ8Yinn1noKqdy+Gi/UCHfAkp6R45oPAih/IWF9Q +S9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=d1z0du7rBFF1wiBfwZcJ+w7kBwx6jVgSW3k2CM2/Ed0=; b=iYZKbSW8oXReqby19D0CN/FwcpPnrwodG+dAnaUORx1TlTIVkQAGx5irPZW5VJUjcw 6r/sK9otr83asjmAPhUPtxDSJnluOjuZStLtJLDkDRUgVR+z7iAozzifa2Ck8XA3nZBQ +JTcMYYBASE60F+RV0n8kED8ShV/jB0ilv5uIorQohyD3iaZPiuJjqt66ITMKPC5tF18 x0OjynvOyGG4NzSfjwZqrEhuHWgGv4ixYr3BTattaFQHckcrVBDJf8ZCEO5IGgyqIf4g T8Qko0EdXk3goV3hIhqU+3WC3Lf/gFXHlV76vWVdPslbQakUNZ+kSD5Y+X976YFEftHU Iy5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YT51bdIW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z12-v6si16437711pgp.274.2018.10.08.11.44.49; Mon, 08 Oct 2018 11:45:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YT51bdIW; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730509AbeJIB4b (ORCPT + 99 others); Mon, 8 Oct 2018 21:56:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:44370 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726672AbeJIB4b (ORCPT ); Mon, 8 Oct 2018 21:56:31 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1319A21479; Mon, 8 Oct 2018 18:43:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024205; bh=hlR6VqPFEIRO4eKMVDkwxhhOGt60Qg+yRWgNnqA7oXQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YT51bdIW9FgHjaR7nzKdXRUAH3pHNipn3Rm39F14g161SQ4fmbv5mbmqOeFcd4qyU wqWfyXzrbKyFul50a0nzhB04W3CgORVJc+SmJWYTvwvUfE7L89oQweSP6LSWt+3U6B PoNIg7Mn7MscJTaFC9LrTCrmEHldSpYkRUAJUaJA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Emmanuel Grumbach , Luca Coelho , Johannes Berg , Sasha Levin Subject: [PATCH 4.14 34/94] mac80211: fix a race between restart and CSA flows Date: Mon, 8 Oct 2018 20:31:15 +0200 Message-Id: <20181008175606.635153489@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175605.067676667@linuxfoundation.org> References: <20181008175605.067676667@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Emmanuel Grumbach [ Upstream commit f3ffb6c3a28963657eb8b02a795d75f2ebbd5ef4 ] We hit a problem with iwlwifi that was caused by a bug in mac80211. A bug in iwlwifi caused the firwmare to crash in certain cases in channel switch. Because of that bug, drv_pre_channel_switch would fail and trigger the restart flow. Now we had the hw restart worker which runs on the system's workqueue and the csa_connection_drop_work worker that runs on mac80211's workqueue that can run together. This is obviously problematic since the restart work wants to reconfigure the connection, while the csa_connection_drop_work worker does the exact opposite: it tries to disconnect. Fix this by cancelling the csa_connection_drop_work worker in the restart worker. Note that this can sound racy: we could have: driver iface_work CSA_work restart_work +++++++++++++++++++++++++++++++++++++++++++++ | <--drv_cs ---| -CS FAILED--> | | | cancel_work(CSA) schedule | CSA work | | | Race between those 2 But this is not possible because we flush the workqueue in the restart worker before we cancel the CSA worker. That would be bullet proof if we could guarantee that we schedule the CSA worker only from the iface_work which runs on the workqueue (and not on the system's workqueue), but unfortunately we do have an instance in which we schedule the CSA work outside the context of the workqueue (ieee80211_chswitch_done). Note also that we should probably cancel other workers like beacon_connection_loss_work and possibly others for different types of interfaces, at the very least, IBSS should suffer from the exact same problem, but for now, do the minimum to fix the actual bug that was actually experienced and reproduced. Signed-off-by: Emmanuel Grumbach Signed-off-by: Luca Coelho Signed-off-by: Johannes Berg Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- net/mac80211/main.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) --- a/net/mac80211/main.c +++ b/net/mac80211/main.c @@ -255,8 +255,27 @@ static void ieee80211_restart_work(struc flush_work(&local->radar_detected_work); rtnl_lock(); - list_for_each_entry(sdata, &local->interfaces, list) + list_for_each_entry(sdata, &local->interfaces, list) { + /* + * XXX: there may be more work for other vif types and even + * for station mode: a good thing would be to run most of + * the iface type's dependent _stop (ieee80211_mg_stop, + * ieee80211_ibss_stop) etc... + * For now, fix only the specific bug that was seen: race + * between csa_connection_drop_work and us. + */ + if (sdata->vif.type == NL80211_IFTYPE_STATION) { + /* + * This worker is scheduled from the iface worker that + * runs on mac80211's workqueue, so we can't be + * scheduling this worker after the cancel right here. + * The exception is ieee80211_chswitch_done. + * Then we can have a race... + */ + cancel_work_sync(&sdata->u.mgd.csa_connection_drop_work); + } flush_delayed_work(&sdata->dec_tailroom_needed_wk); + } ieee80211_scan_cancel(local); /* make sure any new ROC will consider local->in_reconfig */