From patchwork Wed Oct 3 14:07:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia-Ju Bai X-Patchwork-Id: 10624855 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1AC8815A6 for ; Wed, 3 Oct 2018 14:08:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CCF7289B1 for ; Wed, 3 Oct 2018 14:08:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3457289DA; Wed, 3 Oct 2018 14:08:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8E5CD289B1 for ; Wed, 3 Oct 2018 14:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726798AbeJCU4b (ORCPT ); Wed, 3 Oct 2018 16:56:31 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:45982 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726543AbeJCU4a (ORCPT ); Wed, 3 Oct 2018 16:56:30 -0400 Received: by mail-pl1-f194.google.com with SMTP id y15-v6so3540743plr.12; Wed, 03 Oct 2018 07:07:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/Z+rc/V0/D/CPK7OCB5tr9qDXZNzXfoCHcN9lstMRH0=; b=FII94jDg+ir8FJ3Q5F+jSO/5mbwPmldlEpa87xVeENO8hiQMMI9iAWv5bTZw8IT/GD Xg2srs+lbcSUqTWVq+uco/xWicnWzv+kjcSnXnEF43PZDHsJEmgpUQ6LImZ3Y9SwcW+G CZFCRqoBCzySBXjQzPplRPrY20y7cqCPIWoNMavoJkcvPajXyjdfmp6joho8D0IyerS8 V05fMvV4G7IJKMPcxa5wZem5dXaFqk0g5oJnIFXFFq0FvdhmqwjHMgG8QaIxG+BctjTr Bl1VM9opXqCKZdqiZn8UAj6DUOC/qemfaIgdBbwydzYAXM77Eo+V8X+EhMNq3JTev94M h+dw== 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=/Z+rc/V0/D/CPK7OCB5tr9qDXZNzXfoCHcN9lstMRH0=; b=cx57BcVzKNGQFnfW5zLdu5VlD0UwIjTM/qJW9K5oDTl3tLu/GnezrY8a8Vykzuzjug DQS04iimbQIpWBYxvSpbfsNFRxxpR1DZr9/vmGfz5ZItSiYavjqsCTaIJZShl8J+nZkv MU64TGtSR8NmMiOC17Y651EGVPvfCBcEB6bw2RhWwLxPo/m36plYsOC0hgjZ0j6a4glY UShmaZgKuVqu8M1LUWwM0pZb2IcdFT3IyO3uxyCBUtpntJo59wQDBfj1SB1Qb6KGr8HW Km9k42s4TiKkGiStinWzxXl+bsUtwt02WA2Ro1dlES/jlEL1qFlNkjXNAsCm3AeK4x6K bpuw== X-Gm-Message-State: ABuFfog0TukZ7MCUFlqEDUSVvFhp147EwRQcisOeyaYLrNKqVIjU5oZj AgnByq21Ipw4hpsH6Tdyzms= X-Google-Smtp-Source: ACcGV63e/owXLtSXeX9KfNGH9e0IcFFS25QZnM3kRwLrSEEEsQlBeernILgAd9qNTPJ6ogh7Sy219w== X-Received: by 2002:a17:902:4d45:: with SMTP id o5-v6mr1818537plh.42.1538575677412; Wed, 03 Oct 2018 07:07:57 -0700 (PDT) Received: from localhost.localdomain ([2402:f000:1:4414:4910:e0f1:49f2:a6db]) by smtp.gmail.com with ESMTPSA id 76-v6sm4343684pfk.134.2018.10.03.07.07.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 07:07:56 -0700 (PDT) From: Jia-Ju Bai To: sgruszka@redhat.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] net: wireless: iwlegacy: Fix possible data races in il4965_send_rxon_assoc() Date: Wed, 3 Oct 2018 22:07:45 +0800 Message-Id: <20181003140745.7650-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP CPU0: il4965_configure_filter mutex_lock() line 6183: il->staging.filter_flags &= ... [WRITE] line 6184: il->staging.filter_flags |= ... [WRITE] CPU1: il4965_send_rxon_assoc line 1301: rxon1->filter_flags, rxon1->filter_flags [READ] line 1314: il->staging.filter_flags [READ] The WRITE operations in CPU0 are performed with holding a mutex lock, but the READ operations in CPU1 are performed without holding this lock, so there may exist data races. These possible races are detected by a runtime testing. To fix these races, the mutex lock is used in il4965_send_rxon_assoc() to protect the data. Signed-off-by: Jia-Ju Bai --- drivers/net/wireless/intel/iwlegacy/4965.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/wireless/intel/iwlegacy/4965.c b/drivers/net/wireless/intel/iwlegacy/4965.c index c3c638ed0ed7..45342777a5f1 100644 --- a/drivers/net/wireless/intel/iwlegacy/4965.c +++ b/drivers/net/wireless/intel/iwlegacy/4965.c @@ -1297,6 +1297,7 @@ il4965_send_rxon_assoc(struct il_priv *il) const struct il_rxon_cmd *rxon1 = &il->staging; const struct il_rxon_cmd *rxon2 = &il->active; + mutex_lock(&il->mutex); if (rxon1->flags == rxon2->flags && rxon1->filter_flags == rxon2->filter_flags && rxon1->cck_basic_rates == rxon2->cck_basic_rates && @@ -1307,6 +1308,7 @@ il4965_send_rxon_assoc(struct il_priv *il) rxon1->rx_chain == rxon2->rx_chain && rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) { D_INFO("Using current RXON_ASSOC. Not resending.\n"); + mutex_unlock(&il->mutex); return 0; } @@ -1321,6 +1323,8 @@ il4965_send_rxon_assoc(struct il_priv *il) il->staging.ofdm_ht_dual_stream_basic_rates; rxon_assoc.rx_chain_select_flags = il->staging.rx_chain; + mutex_unlock(&il->mutex); + ret = il_send_cmd_pdu_async(il, C_RXON_ASSOC, sizeof(rxon_assoc), &rxon_assoc, NULL);