Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2057273imm; Thu, 24 May 2018 05:11:54 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpir6eE0S3SWJxn94fuZ6myxS59r2HqbusPoDRbrk/W0KgCUCJqqzunw2X2e52j05RVuIvO X-Received: by 2002:a62:1fc8:: with SMTP id l69-v6mr7055568pfj.49.1527163914728; Thu, 24 May 2018 05:11:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163914; cv=none; d=google.com; s=arc-20160816; b=UVroOTeT5mE5rtmSRnUOK6o7ajXiTCj7nj3bJaoZ8VUrsP5dHk1QeuX04D1rMVs4Fv sX3zeMQ+aX+wNAJr+uBPAKdPlid3lJ1lizM0ioigPYfT0slY1u1TncLiVIBwKbpWJF8I riWz/p7CGrE55oHbixvIiCR3KfRhfnp+RlB+LRB9A39GvnhS0mcdjKaf2G+EglGV9Qgj y17CEFGdj9RmaSOPixbGPTHj3JMdu1cJ63RbiQ8pGHSpv1yqT/L6MKUsekZLuGf0Oxar 0+Nq2C490N0RDhJ94JzETcAyzThNa239yOHtsK3ikXp/W1vtdG5YGYnJSCi24ErgT0oF 4C4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=WHdd52TkqWR4ikojmKyAm3Wr5bHImYi0nCrEt+ZWHg0=; b=xkEKDDIZWsk9vjAWYvzFO6BH22UTNU88B6ffEaYcI2HipI+tyisZmtaRwpUCWTWL/U im90orp8bLOR9ICXbcPojfz7sjSoXSWbZl3V+AEHGWL5GEpPXKoFP+cRBDeKeWk8RbTt 10zCP60+Zas7skhL/hXCVpJA0hxfWvrDT38DSRUrHLmm3wO56TANn1rb7kE6F9fCBZ2W iXMawkaFb8Mu47qxtmDmLl8vwdjoc6xxov4E2R5MUmMBf1gJX2gaopZLLLS0jwOOKTOy WXHRxDh+Bw0M/yb7VAy7gf9rvOzJ5tNbMTzN4W2oZTKLcFO9vsk3pjMmrAW7AwI1CgP4 XTng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=gfU0j+uN; 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 h14-v6si21172818pfj.178.2018.05.24.05.11.28; Thu, 24 May 2018 05:11:54 -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=gfU0j+uN; 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 S966452AbeEXJnQ (ORCPT + 99 others); Thu, 24 May 2018 05:43:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:54658 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966180AbeEXJnJ (ORCPT ); Thu, 24 May 2018 05:43:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (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 F415F208B7; Thu, 24 May 2018 09:43:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527154989; bh=Iw859FjWXE4LZWmbHOAsHZ9NxU3mNxQ/rhQzctD/izA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gfU0j+uNz36iSYLe9EPZpW9m9vokouMDlAch0H2ET/0kmSYcZ29lAbptR2GuCcxjm 6plsxcG9e6OEQrqiwwzzNEYtWSfOXWnKKlnOFYMbZqnBYd6cggURL6ogb8iKMLN6Y8 5nql+1jH0MD5y4Hzu9xqjLIr/nlTbwfKJbp/fDZU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zumeng Chen , Michael Chan , "David S. Miller" Subject: [PATCH 4.4 15/92] tg3: Fix vunmap() BUG_ON() triggered from tg3_free_consistent(). Date: Thu, 24 May 2018 11:37:52 +0200 Message-Id: <20180524093200.638969190@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Chan [ Upstream commit d89a2adb8bfe6f8949ff389acdb9fa298b6e8e12 ] tg3_free_consistent() calls dma_free_coherent() to free tp->hw_stats under spinlock and can trigger BUG_ON() in vunmap() because vunmap() may sleep. Fix it by removing the spinlock and relying on the TG3_FLAG_INIT_COMPLETE flag to prevent race conditions between tg3_get_stats64() and tg3_free_consistent(). TG3_FLAG_INIT_COMPLETE is always cleared under tp->lock before tg3_free_consistent() and therefore tg3_get_stats64() can safely access tp->hw_stats under tp->lock if TG3_FLAG_INIT_COMPLETE is set. Fixes: f5992b72ebe0 ("tg3: Fix race condition in tg3_get_stats64().") Reported-by: Zumeng Chen Signed-off-by: Michael Chan Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/broadcom/tg3.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/drivers/net/ethernet/broadcom/tg3.c +++ b/drivers/net/ethernet/broadcom/tg3.c @@ -8722,14 +8722,15 @@ static void tg3_free_consistent(struct t tg3_mem_rx_release(tp); tg3_mem_tx_release(tp); - /* Protect tg3_get_stats64() from reading freed tp->hw_stats. */ - tg3_full_lock(tp, 0); + /* tp->hw_stats can be referenced safely: + * 1. under rtnl_lock + * 2. or under tp->lock if TG3_FLAG_INIT_COMPLETE is set. + */ if (tp->hw_stats) { dma_free_coherent(&tp->pdev->dev, sizeof(struct tg3_hw_stats), tp->hw_stats, tp->stats_mapping); tp->hw_stats = NULL; } - tg3_full_unlock(tp); } /* @@ -14163,7 +14164,7 @@ static struct rtnl_link_stats64 *tg3_get struct tg3 *tp = netdev_priv(dev); spin_lock_bh(&tp->lock); - if (!tp->hw_stats) { + if (!tp->hw_stats || !tg3_flag(tp, INIT_COMPLETE)) { *stats = tp->net_stats_prev; spin_unlock_bh(&tp->lock); return stats;