Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2072312imm; Thu, 24 May 2018 05:24:32 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrjNn4K/eMFbPKGUdeNk+7YUWKvAymtxCMM5Rc4ZrR2o8KxeibFG4YszNeIuzMsZ/qNigkd X-Received: by 2002:a65:64d9:: with SMTP id t25-v6mr5738780pgv.148.1527164672806; Thu, 24 May 2018 05:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527164672; cv=none; d=google.com; s=arc-20160816; b=ULfmc8iWo6lJ6LOqRi3CMVWKKlG7j2UnLK7knFN9KUO4tHSTOLhJtx3jMoOmIEaSh+ Y65FUbDI3Rk1SwC29B4FCO1zPam5dFWP1ao9mKXQZnvVf12sfCmxYnio1Bj2u2Hlkg+p 859bgemOwwVCpysSQh/m2GsiwUepVa3V4x2v+5NOeAGAehDI6pQXW3HRwoCa3onygVAQ Fv9HPgBWDTPqK3cdjJjboZELmWtWGLaRZPvx1RNtraWO3sPQS2FvpV/Prm+44XHSeVlC 8xBMnK2TXmpU5seKAQImYHeoufXgEHhu0xTkpLn8HY4kwgmMNLHf7l/8T76lRoIWMW/l yhvg== 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=aI3d/rXK4P/B+PbNvPsMD64yjHMCnrR8tNkgQcmeudU=; b=fAUSSBba4egCqWgfUe7Nz2UfGcKEuf8slanj3gd9LBQta5aMcRmb/T0RWkwKQY2LHw niBKzI+0TECeljnXMgcngvkL9tnSYMCzW3m3wt4eTyrGIsm5NBFY/WcZjJ4c8urFE9US JVIQ/epU9rqPCTYgxUry9qbcf2xNPhzjdg4fweNe4oNb3ZKesTnlOiBzI508FFliH2DN 7xTICJTE7qb0aCiMhvGqsAaEGzl/TOzKxYUbnOw3bwCFeoCoDAyD3MabmG9BhAWEu/yI nehaeX8alY7kulFyUCcyqyVAKwue0uoKiqxV1ny/9LcW2umC9mpU7+y1Pe5Dq6T4wnEQ 382g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QZGa+gHh; 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 3-v6si21508152plh.34.2018.05.24.05.24.18; Thu, 24 May 2018 05:24:32 -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=QZGa+gHh; 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 S970101AbeEXMXe (ORCPT + 99 others); Thu, 24 May 2018 08:23:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:52918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965995AbeEXJkz (ORCPT ); Thu, 24 May 2018 05:40:55 -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 481B42087E; Thu, 24 May 2018 09:40:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527154854; bh=x5PLnOeXcphCgRPgelaUZp6iEzqdPD1BiPW2ghHiI0Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QZGa+gHhqo+3asM42hk8wUld96lFpampgCL+ZoR1qP/2qRsUK1/v3SVlcRAMLZXYM VW8rnLOhGjzzEM5/nKHUfaTnpE7P+oMgh/ZtWNXl3KYtobDpDUirgyK+tbzxlKmnUb BwGNYP5iu2RbHq+FjU2j8gfV0dWFs85AcgXK5VhY= 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 3.18 12/45] tg3: Fix vunmap() BUG_ON() triggered from tg3_free_consistent(). Date: Thu, 24 May 2018 11:38:20 +0200 Message-Id: <20180524093122.018978144@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093120.599252450@linuxfoundation.org> References: <20180524093120.599252450@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 3.18-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 @@ -8705,14 +8705,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); } /* @@ -14137,7 +14138,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;