Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2690839ybl; Thu, 29 Aug 2019 11:31:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqyHi2pRGhngPRLcsuL//wlJuKrAX7ILsDWXBJtDpjbq85lOYRqOHEtj41PGJoGRi/YbGDDo X-Received: by 2002:a62:1d8a:: with SMTP id d132mr13240565pfd.187.1567103509259; Thu, 29 Aug 2019 11:31:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103509; cv=none; d=google.com; s=arc-20160816; b=O9Bhk5aki/zkwutI15BQI9MpuN9QZFNQozTOn+BTwKAI+lCx5AMQExfpVfGp2pmcqp yFk+BnS6ps0PK3aLjBXxTTvGv/TNfAMdI73Avxdf9ugN2M6fUZUmqClxJ6xuN4+BqCeH 7+vJ69BiuhqF6DOrUQIj1OJBOv5Y6bQcZwEWCmhx1V4MfDRE4EC/2dz0THKt+fbxgqtV mVthR866nD8lOaGIQDEe8THuGoW0jP2WKassrAu5FUXubxhDSb3UwWh0AMfU/zideW7c 6aQZLsTx/vVE7EQIF/yHECW1sUjYVpOS6ElpvOZd2SOvJTO79DKzlbq+rcfTY7XqKdnS ji9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fXjsiXYB+NIwJJkRU6s/pQYbFyQXGgVJFbRVcR0Txrk=; b=DFsdo5jlAftnRaEUxXG/C83YqZOVe+UqNHMQLWAq/vl4OGnpv0SrUqsMCLkuy2Qvf7 VtiUaYCT+LFWhTO+xHXhWt6OTPT1V8bB9BSZbwKpD8JNcQtGYXH5LBlihPZMDsteSsk0 7/x2nZEumYW3zWS79M6He4ZYhSyZcCJH5xydDZsX+6Ns3/vHW49h7qOQ1tp5eJGlwpgY iisjm+XX3m/xf5S1ZootcvE/Q5SZ7zYX2uT569ZL6d3xWMkesyqWAlyLPiJwW4MopaPt 2Vv+m7PGfoVjdG6G6dX/78EEEANFkKItA/GMqhs0j2YxL5T+En8xk3ARHniOxng3sUgL uxfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XzCjjG2e; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g10si1841588plo.203.2019.08.29.11.31.34; Thu, 29 Aug 2019 11:31:49 -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=XzCjjG2e; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728232AbfH2SOy (ORCPT + 99 others); Thu, 29 Aug 2019 14:14:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:56448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729022AbfH2SOv (ORCPT ); Thu, 29 Aug 2019 14:14:51 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 63E0D233FF; Thu, 29 Aug 2019 18:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102490; bh=bsmHAF33qlowc3EwOHE77PRfi/xEdY+utyNrN74QX1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XzCjjG2eZMYK1QwdiPK3TNRCHNs4daQaofwBZFgZSxHouye+b/xpF4b9k6H3M/PIB ub2/tCZ6RnDlRXcDEb0DUqXBYB+y91X1qbCXCj52KiFh1tRIFl/rWA6+EpWA1qhXhQ M5ETY2i6xgp9VCnh9aqZ6D3Nu9jQ5Jqs7JrQVm4U= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tho Vu , Kazuya Mizuguchi , Simon Horman , "David S . Miller" , Sasha Levin , netdev@vger.kernel.org, linux-renesas-soc@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 46/76] ravb: Fix use-after-free ravb_tstamp_skb Date: Thu, 29 Aug 2019 14:12:41 -0400 Message-Id: <20190829181311.7562-46-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tho Vu [ Upstream commit cfef46d692efd852a0da6803f920cc756eea2855 ] When a Tx timestamp is requested, a pointer to the skb is stored in the ravb_tstamp_skb struct. This was done without an skb_get. There exists the possibility that the skb could be freed by ravb_tx_free (when ravb_tx_free is called from ravb_start_xmit) before the timestamp was processed, leading to a use-after-free bug. Use skb_get when filling a ravb_tstamp_skb struct, and add appropriate frees/consumes when a ravb_tstamp_skb struct is freed. Fixes: c156633f1353 ("Renesas Ethernet AVB driver proper") Signed-off-by: Tho Vu Signed-off-by: Kazuya Mizuguchi Signed-off-by: Simon Horman Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/renesas/ravb_main.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/renesas/ravb_main.c b/drivers/net/ethernet/renesas/ravb_main.c index ef8f08931fe8b..6cacd5e893aca 100644 --- a/drivers/net/ethernet/renesas/ravb_main.c +++ b/drivers/net/ethernet/renesas/ravb_main.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Renesas Ethernet AVB device driver * - * Copyright (C) 2014-2015 Renesas Electronics Corporation + * Copyright (C) 2014-2019 Renesas Electronics Corporation * Copyright (C) 2015 Renesas Solutions Corp. * Copyright (C) 2015-2016 Cogent Embedded, Inc. * @@ -513,7 +513,10 @@ static void ravb_get_tx_tstamp(struct net_device *ndev) kfree(ts_skb); if (tag == tfa_tag) { skb_tstamp_tx(skb, &shhwtstamps); + dev_consume_skb_any(skb); break; + } else { + dev_kfree_skb_any(skb); } } ravb_modify(ndev, TCCR, TCCR_TFR, TCCR_TFR); @@ -1564,7 +1567,7 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev) } goto unmap; } - ts_skb->skb = skb; + ts_skb->skb = skb_get(skb); ts_skb->tag = priv->ts_skb_tag++; priv->ts_skb_tag &= 0x3ff; list_add_tail(&ts_skb->list, &priv->ts_skb_list); @@ -1693,6 +1696,7 @@ static int ravb_close(struct net_device *ndev) /* Clear the timestamp list */ list_for_each_entry_safe(ts_skb, ts_skb2, &priv->ts_skb_list, list) { list_del(&ts_skb->list); + kfree_skb(ts_skb->skb); kfree(ts_skb); } -- 2.20.1