Received: by 10.192.165.156 with SMTP id m28csp1112894imm; Wed, 11 Apr 2018 12:40:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx48KG3xcQXwW0ensoHNx1dsjUhxbpDZ5Y8WC/KIIdM8Dy7tbfNj10xyRW2A86dO0+OLbAsiY X-Received: by 10.101.97.16 with SMTP id z16mr4467863pgu.23.1523475600338; Wed, 11 Apr 2018 12:40:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523475600; cv=none; d=google.com; s=arc-20160816; b=KkZ8xtERfYzW58gT1aDN947OmR0NNs5T1grCPwp6+qR9r6qZx5JgQ9DoUG3fg2tHtS 8YLJVIKHjEuEeogN7wsHBQk0i7WvjuBs7cxDE+EbhUVP7nwz/lvcKGr7gTbkc2tBICjJ CWqJiUfCGw/AOMjDcoI8znvDxSTagKwTv3EYOc4Aip+j2NiGbwpkLLxZiO6OB2NT/NWP FEU0ZhDFNGc/cBK8b8FmrjZlhDtsyWjPqwnc+NtOJBm9DHaZkSLx3V9h5AMCgxznPz61 G9mR/sPNNvOpcHV0XVJEPV73QJG0WtGlxoRjp5GYHrWA8hCwJiwVsj6JOxOOuC3sl1Bl sDQg== 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 :arc-authentication-results; bh=yfIAeNlb5FI5utVWo09nHOFqQo7Tiha5BfUIbTGfjS0=; b=zeOdjHeMj9+7/wzXqjbcgdry+4ip5tg3Hcrgm6FblzdH7ig8/Uf45UkqlatNKdDgJi C9t8KUfmRxSNSnVWn62okgAHXHvLhNjwZxu7QMrjkXvK7ofN5lXBVo4I2DnBbytp5nIO DyrFZaQzSftQJuC3CUdDVexTCOB9zEGoXQoEGDqLKML8UNjeLFpfk2QVGGsaWiFSnw+M N1z90Gn53LI4xCRLf0FGaiBxrAclNoXqHE1sZisO8gXjGFeed8K6FpE2ITlQj5zMnbVx It1ajacieNw3/+E6A5yW+su6ZdGLgQmorBOQt8g28gX/GBOVtOY7CL8paEj/m/rjNzqN 9aKg== ARC-Authentication-Results: i=1; mx.google.com; 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 j11-v6si1721912plk.655.2018.04.11.12.39.23; Wed, 11 Apr 2018 12:40:00 -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; 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 S934405AbeDKTCN (ORCPT + 99 others); Wed, 11 Apr 2018 15:02:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38398 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934376AbeDKTCE (ORCPT ); Wed, 11 Apr 2018 15:02:04 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0EC78DAC; Wed, 11 Apr 2018 19:02:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, David Mirabito , Jacob Keller , Aaron Brown , Jeff Kirsher , Sasha Levin Subject: [PATCH 4.9 205/310] e1000e: fix race condition around skb_tstamp_tx() Date: Wed, 11 Apr 2018 20:35:44 +0200 Message-Id: <20180411183631.389041225@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180411183622.305902791@linuxfoundation.org> References: <20180411183622.305902791@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.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jacob Keller [ Upstream commit 5012863b7347866764c4a4e58b62fb05346b0d06 ] The e1000e driver and related hardware has a limitation on Tx PTP packets which requires we limit to timestamping a single packet at once. We do this by verifying that we never request a new Tx timestamp while we still have a tx_hwtstamp_skb pointer. Unfortunately the driver suffers from a race condition around this. The tx_hwtstamp_skb pointer is not set to NULL until after skb_tstamp_tx() is called. This function notifies the stack and applications of a new timestamp. Even a well behaved application that only sends a new request when the first one is finished might be woken up and possibly send a packet before we can free the timestamp in the driver again. The result is that we needlessly ignore some Tx timestamp requests in this corner case. Fix this by assigning the tx_hwtstamp_skb pointer prior to calling skb_tstamp_tx() and use a temporary pointer to hold the timestamped skb until that function finishes. This ensures that the application is not woken up until the driver is ready to begin timestamping a new packet. This ensures that well behaved applications do not accidentally race with condition to skip Tx timestamps. Obviously an application which sends multiple Tx timestamp requests at once will still only timestamp one packet at a time. Unfortunately there is nothing we can do about this. Reported-by: David Mirabito Signed-off-by: Jacob Keller Tested-by: Aaron Brown Signed-off-by: Jeff Kirsher Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/intel/e1000e/netdev.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/net/ethernet/intel/e1000e/netdev.c +++ b/drivers/net/ethernet/intel/e1000e/netdev.c @@ -1182,6 +1182,7 @@ static void e1000e_tx_hwtstamp_work(stru struct e1000_hw *hw = &adapter->hw; if (er32(TSYNCTXCTL) & E1000_TSYNCTXCTL_VALID) { + struct sk_buff *skb = adapter->tx_hwtstamp_skb; struct skb_shared_hwtstamps shhwtstamps; u64 txstmp; @@ -1190,9 +1191,14 @@ static void e1000e_tx_hwtstamp_work(stru e1000e_systim_to_hwtstamp(adapter, &shhwtstamps, txstmp); - skb_tstamp_tx(adapter->tx_hwtstamp_skb, &shhwtstamps); - dev_kfree_skb_any(adapter->tx_hwtstamp_skb); + /* Clear the global tx_hwtstamp_skb pointer and force writes + * prior to notifying the stack of a Tx timestamp. + */ adapter->tx_hwtstamp_skb = NULL; + wmb(); /* force write prior to skb_tstamp_tx */ + + skb_tstamp_tx(skb, &shhwtstamps); + dev_kfree_skb_any(skb); } else if (time_after(jiffies, adapter->tx_hwtstamp_start + adapter->tx_timeout_factor * HZ)) { dev_kfree_skb_any(adapter->tx_hwtstamp_skb);