Received: by 10.192.165.148 with SMTP id m20csp3128734imm; Mon, 7 May 2018 07:09:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqj0LAN01nBtWl6Y7UJgDYSqRMylpXBH5CizAy5SYwSMuTuyUcW4ypTxFibi1eekaujdYOr X-Received: by 10.98.147.200 with SMTP id r69mr37016601pfk.59.1525702146426; Mon, 07 May 2018 07:09:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525702146; cv=none; d=google.com; s=arc-20160816; b=Kp7b3xIb5p0+8GEGSL69HaHKyzL9QEstW1dgxND+mKjF3gqDhjp+j3JY41dFyaYQhX HSuYU4e4iTE738gQxcU4ogNTQLhEET+eQfW8CbNkXQHFzWCn31ammFTHQIH2nUoB3yIG 6ZmY3s1yzJNVk+DrG5V+uwYI6SP4xId9fAjyojROEoi+CxFk/J0Ki1Zvx+r1GHVCVOT7 MlKUaXL74f/4EzD4n2oUkksjsU2g2JH12QqGVKcIziGdpkL2IQanpUKQWLf9aqF1sr1s oYUtAcTyVUiZq6GYjLQgUWPMYeO9CH7iKfT0gIhatALiAtwHDvC+wxjZqxg0p8aK1gE1 YZfA== 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:arc-authentication-results; bh=tKG5OxEMr9m7/S8t/A/keOs914xzDY2zD+i3LGuKNVM=; b=HBMeuYHQ12SyholPToK2NPazOXEziCAg1Bh9j79N6RXGAvx3y18Rglh1KD0F6BSU/h dTKSLrMUQ0jtUFd1abUjnUHF5FlwLW06+iEUl8ji1E6nFyXbcchwKjTaGKZJJOl/wcXE aFRLaIit7PPWGlWMV5DAq1BrHInKkTGm3IBFm82of2oBYUMz1C9oKrJn9CfWrYoAZWqj kR/sHI119cjYvVULp9yJ15xTsKoWlS7p/EbiiJZCPoEjeF6daSJHQxbpmPIEd5b9J2ub PKDmZoqH09uoFHK2b9OWF7FpOtJclOb1xz4yROfGq9a/O0zZCudl4XoosQgyYCUa8LWs QHjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PueRyCpA; 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; 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 c18-v6si20602783plo.185.2018.05.07.07.08.52; Mon, 07 May 2018 07:09:06 -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=@gmail.com header.s=20161025 header.b=PueRyCpA; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbeEGOI2 (ORCPT + 99 others); Mon, 7 May 2018 10:08:28 -0400 Received: from mail-io0-f194.google.com ([209.85.223.194]:46916 "EHLO mail-io0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751943AbeEGOIX (ORCPT ); Mon, 7 May 2018 10:08:23 -0400 Received: by mail-io0-f194.google.com with SMTP id f21-v6so33828643iob.13; Mon, 07 May 2018 07:08:23 -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=tKG5OxEMr9m7/S8t/A/keOs914xzDY2zD+i3LGuKNVM=; b=PueRyCpAT09a+PRx2JvwcIbLg+u8tr/V2N7khamIG3nPdR12yhFHcfNC5M/XzQYOIU onorvxB5IKV7yWjKB3XifTumil9ZOn6lzkF4+6quIpLxy38LZT0kfFtxx5oT2FpqApzD KCH5KvbOmBlRQ+z2ggC6xnQLgJlj0czpC5Ub7gwcKfQ8AlXpIqzXIb/9yUPbd7Bq5eBL a6DlCHh+yiF4wToFJ+okfdW/ipDNdwqpAJoNIsptShtCFAFSLcoINz6eMrIv1Mv+wjx2 /23NlHLQZdm+coxCpR2s8WHwQUbS7yZ28/qnPtefuRnD8zdXLo45yTpB80UlXChzO0XA 1Ptg== 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=tKG5OxEMr9m7/S8t/A/keOs914xzDY2zD+i3LGuKNVM=; b=ExrbaL27jXc2x+gfcMaWPpO9K4UF1vB+g2ZZTunmTOrJGrLRpkJwMUXy0flP/tS3Lk EtODyu/AeYbQDuNJ26sSpux5g/7e8gNUGbNUbpf6ydPi+8ohW5QYC40c4qBixWd4pLY7 LQ1em9Bi+rjgVXOFjomJrCa62/KxVBhkreqoFwGEX2dMXIYHbwSQGnX1Rb6q1JVbmbKt K6RWQh0DcFWJYpFNCCHZ1duKnhOH75nXITQYwicjEjVdj+vZvUWPUAUv8RCyxT2bwUsM m8z5wjASRuv140Z7w3C2/96APRuzDf5S2z7hyCiDzzo3EclZD2p4jEdviab/jssIBzJv lAbg== X-Gm-Message-State: ALQs6tBgo82AjuEMAegTQA+E+PYAvBYV1ctW0SQkbtHIRtFDsyUHgp/T rL9jN4Moo9o8NQ5HpMNVXYA= X-Received: by 2002:a63:7250:: with SMTP id c16-v6mr29706808pgn.385.1525702103206; Mon, 07 May 2018 07:08:23 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:1:4413:18bf:4b0b:7f52:49b]) by smtp.gmail.com with ESMTPSA id x186-v6sm36498489pgb.6.2018.05.07.07.08.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 May 2018 07:08:22 -0700 (PDT) From: Jia-Ju Bai To: davem@davemloft.net, fthain@telegraphics.com.au, joe@perches.com Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] net: 8390: Fix possible data races in __ei_get_stats Date: Mon, 7 May 2018 22:08:09 +0800 Message-Id: <20180507140809.28847-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The write operations to "dev->stats" are protected by the spinlock on line 862-864, but the read operations to this data on line 858 and 867 are not protected by the spinlock. Thus, there may exist data races for "dev->stats". To fix the data races, the read operations to "dev->stats" are protected by the spinlock, and a local variable is used for return. Signed-off-by: Jia-Ju Bai --- drivers/net/ethernet/8390/lib8390.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/8390/lib8390.c b/drivers/net/ethernet/8390/lib8390.c index c9c55c9eab9f..198952247d30 100644 --- a/drivers/net/ethernet/8390/lib8390.c +++ b/drivers/net/ethernet/8390/lib8390.c @@ -852,19 +852,25 @@ static struct net_device_stats *__ei_get_stats(struct net_device *dev) unsigned long ioaddr = dev->base_addr; struct ei_device *ei_local = netdev_priv(dev); unsigned long flags; + struct net_device_stats *stats; + + spin_lock_irqsave(&ei_local->page_lock, flags); /* If the card is stopped, just return the present stats. */ - if (!netif_running(dev)) - return &dev->stats; + if (!netif_running(dev)) { + stats = &dev->stats; + spin_unlock_irqrestore(&ei_local->page_lock, flags); + return stats; + } - spin_lock_irqsave(&ei_local->page_lock, flags); /* Read the counter registers, assuming we are in page 0. */ dev->stats.rx_frame_errors += ei_inb_p(ioaddr + EN0_COUNTER0); dev->stats.rx_crc_errors += ei_inb_p(ioaddr + EN0_COUNTER1); dev->stats.rx_missed_errors += ei_inb_p(ioaddr + EN0_COUNTER2); + stats = &dev->stats; spin_unlock_irqrestore(&ei_local->page_lock, flags); - return &dev->stats; + return stats; } /* -- 2.17.0