Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2111720ybl; Sat, 11 Jan 2020 09:19:39 -0800 (PST) X-Google-Smtp-Source: APXvYqz6NoTZl/VmO6HHa9pQut7k9T9jB8ydaIxYwxZk45pMnDLczmM/akYwZ2+Eu7JM7pwDUqxU X-Received: by 2002:a9d:5f13:: with SMTP id f19mr7650348oti.180.1578763179537; Sat, 11 Jan 2020 09:19:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578763179; cv=none; d=google.com; s=arc-20160816; b=FHaWkNePdFYIL9qr4kXa6yf6i1txZz+0kyu6zLoFVmuuQFH/HspAdnlvT1xAqw+N1C wemrZFjA9gtEBRZASbXbOVL4UEpvU1uGxtIG62KzaxqlqE4Ocx+poYRWQJxyRU9rx6iF 20aU/aKLNa+8uIPT0mxAGyBP7p/DRILkq+zdpIesOtnkWlygESiwmlNv5h1Tgs5A5Q/V nGfQALsvYVvz+SAPP9uJTjGdP2gD9SzPnpAQHlIi6lXUWN2PRbJPnmY1W4Pq6MUF3E7M PPxMrAmx8Ju72fo1jtFq3YfxCzQH7VFeROe6E0aEdWWi5dDAUj2vUIEpy/SsGILVFs4A nBiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Li992Inl6qlK9dLbIXMHvdL8lIRzO4/rvMMlJnBSYOA=; b=xyAF5VQvo1Xn1OhpxtehGyca6vqqxeyVBZSKiIU3VnJ40yjoBNSrSJfT+DeWw32UGf gGDDeY/rZjiOOCQV/5gJ3oBlIABqJ7HtOm7kRKAR5D0CzXsogs1ivlSLTYwXnF03Xsl9 OmS+bcfCuWhVIjH/6RYDstuwbLa/t4joKk1xlOwKAZ0ls7SByuO/PjYOFj1M4vfoCQ7z j7kNAnS+kZIIeuQ9EGv0FxBY/hYyUR85qEcWQY+SF3Kucqcb6ELQA7y2+I3+iNp78zMd 6yafxntP5/U6iyePi8w+UwhxsgFQY4aNGRQDi0uLr83C1VZo8xfuic/dOyYiNWvfV0mw aDDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aaVHG5LZ; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t20si3636453otr.64.2020.01.11.09.19.12; Sat, 11 Jan 2020 09:19:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-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=@gmail.com header.s=20161025 header.b=aaVHG5LZ; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730503AbgAKRQT (ORCPT + 99 others); Sat, 11 Jan 2020 12:16:19 -0500 Received: from mail-pf1-f194.google.com ([209.85.210.194]:40974 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730423AbgAKRQS (ORCPT ); Sat, 11 Jan 2020 12:16:18 -0500 Received: by mail-pf1-f194.google.com with SMTP id w62so2715871pfw.8; Sat, 11 Jan 2020 09:16:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Li992Inl6qlK9dLbIXMHvdL8lIRzO4/rvMMlJnBSYOA=; b=aaVHG5LZLJzn9bL5nsMjFha4VHzpuAjs6cHT4gm680uONrLp1NjmAcnK2gbfgXZWWD g9ZkOxjqGHvx0UYYTRKOnTYx0aM9So0HAirKrWrqu+H3OlJgHO0MInLT2j5JsNRyT97C H79SF6PvxoMrFwSiprsxRAyAo99s7AZ6t8kKgmze+k0doLozIZ4lHAk7vxS0Tshp0G7d fNhOgxHoI3o5yQo5tNzbYVheQYYbhOsDaiGQHlwnXa1+iWiVzUUIKwtF72kMnH2lav7r i4oaBufB8y5kK5QVN+n06cJ3S1FfO1VlHrqgnErgAdQdfSi16TCEVPnn7FMhPHX9BODu B2YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Li992Inl6qlK9dLbIXMHvdL8lIRzO4/rvMMlJnBSYOA=; b=pJdmu/sokonlQjqPtlfMQrWHgxjHm+M8EN+g6g1tfWsIk5eejOt48RKLVOyDLQ1A4Q cQeiC2uLvC+8uSy/0xbrfMNTGLJSV385UcG42m8dOIWeYFHLjiID9U0NyESEvX/YXHil LC9ypXKqZnBI8I8eFnqSCyHfucL/hZ0nzueygnvmr9uRn21zDThxcE/lYlnLKzoD10Fq MI/DqqtwHzPQjf5fqwldx4l4HlSs4XFVVh6c1vMOhwiKXNn+pXTwHpduSBCFYojbBWcs vHYT2lYxTwCtlObLpzaCgJsXKO59D7EhPTDAQk1BERp7G7aNE2oZB9s3WY2iMm3etLcr y6ZQ== X-Gm-Message-State: APjAAAWEWOrgWApMEzLjrYUzyfIaf/pMmfXFQEqiXraByUeyY/2tytJK aRVo/quu+82QJKaP1KAnGNk= X-Received: by 2002:a63:1853:: with SMTP id 19mr11774376pgy.170.1578762977781; Sat, 11 Jan 2020 09:16:17 -0800 (PST) Received: from oslab.tsinghua.edu.cn ([166.111.139.172]) by smtp.gmail.com with ESMTPSA id o184sm6997015pgo.62.2020.01.11.09.16.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jan 2020 09:16:17 -0800 (PST) From: Jia-Ju Bai To: ath9k-devel@qca.qualcomm.com, kvalo@codeaurora.org, davem@davemloft.net Cc: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] ath9k: Fix possible data races in ath_set_channel() Date: Sun, 12 Jan 2020 01:15:28 +0800 Message-Id: <20200111171528.7053-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org The functions ath9k_config() and ath_ani_calibrate() may be concurrently executed. A variable survey->filled is accessed with holding a spinlock common->cc_lock, through: ath_ani_calibrate() spin_lock_irqsave(&common->cc_lock, flags); ath_update_survey_stats() ath_update_survey_nf() survey->filled |= SURVEY_INFO_NOISE_DBM; The identical variables sc->cur_survey->filled and sc->survey[pos].filled is accessed without holding this lock, through: ath9k_config() ath_chanctx_set_channel() ath_set_channel() sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE; sc->cur_survey->filled |= SURVEY_INFO_IN_USE; else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) ath_update_survey_nf survey->filled |= SURVEY_INFO_NOISE_DBM; Thus, possible data races may occur. To fix these data races, in ath_set_channel(), these variables are accessed with holding the spinlock common->cc_lock. These data races are found by the runtime testing of our tool DILP-2. Signed-off-by: Jia-Ju Bai --- drivers/net/wireless/ath/ath9k/channel.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath9k/channel.c b/drivers/net/wireless/ath/ath9k/channel.c index fd61ae4782b6..b16f7f65e9c6 100644 --- a/drivers/net/wireless/ath/ath9k/channel.c +++ b/drivers/net/wireless/ath/ath9k/channel.c @@ -54,6 +54,7 @@ static int ath_set_channel(struct ath_softc *sc) * Reset the survey data for the new channel, unless we're switching * back to the operating channel from an off-channel operation. */ + spin_lock_irqsave(&common->cc_lock, flags); if (!sc->cur_chan->offchannel && sc->cur_survey != &sc->survey[pos]) { if (sc->cur_survey) sc->cur_survey->filled &= ~SURVEY_INFO_IN_USE; @@ -65,6 +66,7 @@ static int ath_set_channel(struct ath_softc *sc) } else if (!(sc->survey[pos].filled & SURVEY_INFO_IN_USE)) { memset(&sc->survey[pos], 0, sizeof(struct survey_info)); } + spin_unlock_irqrestore(&common->cc_lock, flags); hchan = &sc->sc_ah->channels[pos]; r = ath_reset(sc, hchan); @@ -75,8 +77,11 @@ static int ath_set_channel(struct ath_softc *sc) * channel is only available after the hardware reset. Copy it to * the survey stats now. */ - if (old_pos >= 0) + if (old_pos >= 0) { + spin_lock_irqsave(&common->cc_lock, flags); ath_update_survey_nf(sc, old_pos); + spin_unlock_irqrestore(&common->cc_lock, flags); + } /* Enable radar pulse detection if on a DFS channel. Spectral * scanning and radar detection can not be used concurrently. -- 2.17.1