Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3928211imm; Mon, 8 Oct 2018 11:50:19 -0700 (PDT) X-Google-Smtp-Source: ACcGV60la7YNgEEIg/kwJcegpoT9491sG/c+Y8/54+c+Qtd2peKlVYpeXrvNBiJUD3NC4HaaVLIP X-Received: by 2002:a62:8f:: with SMTP id 137-v6mr26160846pfa.24.1539024619336; Mon, 08 Oct 2018 11:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024619; cv=none; d=google.com; s=arc-20160816; b=Dj3wucYoesA0x3PP1CneKkWRL4w4oOLRPlwA+Q0OfgDgNR4hEQ0bfbmjNxjw8K05TS l2v4hOI22uQGzzcVjls1Z/4EG7PrPYYLaHWN05xtDhHo1Kae97G/Neh9ZGY2QAVhsMqb VdNYX/JDISzBvhTyuqLbCvgo0PnS2NZKkz/hLTYVjxkSHAN11QCkV7cWcB5sB9LfHpZC EGuyZtJ6xlObjDtNqmGFVg0PgvpIQE+81/Owm9oxWWSQgTMM7jwkhQWRxgLv5i80MtMp prFMQfoE7lUd01CCVgVUnf+oxV7XFr/odDXJnNaTdWKcnXUof45AmTxPXdpoDV1dI691 bXAg== 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=h8zeXo7Jq/9bEh4TPec80Vr0BOvZZJ8xJIAL4CuKiTI=; b=I/uGGHJDygPgLlJ0SChXf5f7est5tK/ove3wnNq84sO+omRjxbo7PWQ4tfu6qzvhBP 7d68rvi9PDxSG9AMwBmFntRHWZlVuDWERYGoCfxyHbw3NTXVo+Mqlp8HdJH8+7fQXqxS w+1XOwRCK16ukN22czyp1CucYoDAfeLDt47evSt6x1DCgOxRPD4/dBVkY/h/LYYj3CN9 jEL/VQWyj/A5aX6U8O4U7pvR89Jh1wiad9mbPj7eTE76geVa3FHZuT1QC4sP58jSvM6v f+GuZcRwsfZH3EsEt2r10ksDhW3621UsSwtXCsBamHrGN/pLtUHyRvbAAXHtZpfdMnZ5 kVAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mZDVPQsD; 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 1-v6si13942946plq.274.2018.10.08.11.50.04; Mon, 08 Oct 2018 11:50:19 -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=mZDVPQsD; 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 S1731723AbeJICBu (ORCPT + 99 others); Mon, 8 Oct 2018 22:01:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:50964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726991AbeJICBt (ORCPT ); Mon, 8 Oct 2018 22:01:49 -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 86D172087D; Mon, 8 Oct 2018 18:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024522; bh=5IAz/7CUgB4Zru5dRhdCVAp1LvsZZho0qhhaXihSkvY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mZDVPQsDiygYnE0obmyQ/E3TNmuxaj2fQ2tcXhARHLmf6Rpl0EoMXQPq15xW/2/iM HrUMdy9Vn0VIWYhznnbYpaQu0wxZQvSqpXMgJa67B8duQsPDQusx4U7MkdVo0pOSfa vA3GZ2fEtFBRpV8gMkqIjr+2C3GFxu9noMLSdPic= 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.18 060/168] mac80211: fix a race between restart and CSA flows Date: Mon, 8 Oct 2018 20:30:40 +0200 Message-Id: <20181008175622.332649152@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@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.18-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 */