Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp4122598ybe; Mon, 9 Sep 2019 04:42:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzLHz9q3g4g9VD0+n4Ykd6VbpaoAi1rPoZflbrQEyL8Sm4d1aDQOQcNbSi0aoCSpIDQL0Fu X-Received: by 2002:a17:906:1c46:: with SMTP id l6mr19004944ejg.304.1568029336386; Mon, 09 Sep 2019 04:42:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568029336; cv=none; d=google.com; s=arc-20160816; b=HwzBVnlFjrF30QHOD69nSyUEVjpC16KIRVAmevjJGrZfd2bn08XY7f4M3xNfEh6rjq W3IjE8xV7/5eZpcE9Z3r9mhrVzP8sEMzJwaNjgIuPZLE7R6XmJYL1otLdx1svYfUhQxj O3Hppct2Ln6QWimoKkxRav7lqRva2UFyQJL6cVp3tZ0CKxeJ87whZW+FAA0PrT07JEYK 6s4nwobACeoXKqHy3I45ffvbdKL+K3HLaBOC9sBuwahtV2/H0WEr7/fTZYl7FxAS0bvH z8CF5OzdqU/v+pSoUMPosBwXwjjX3eOM0m3zFnffBM4bcczAeP1iuwj1I0JhatL5JC6P 1uhQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yXPwwoRQ9mdVsuVMROdexeoxqpL2MBaEGcQNygptffQ=; b=T9+W3sgf87RkJ58V3BjupkyMfd2O8P20E9wswarEnTa22v9/TlQqlXBQbWHGVEfMwO jrjAnMIJ1eoWTCSjASh0Lk4o6DVXvWeXCwBiWb1MZYtd1CcahMmIZ1R7UDazLCxd9Zr6 chYZx6h1Y6Llm4qsrwVfXAb7A+mXVlgcqz0lhJmH7ZTkzdP/IN2OCLDYe4dn1jJFmKxk DI63+XWoxkD0eu2Chi8Z5yj7gXDSE0D5eQ6RR2GcwbMhvBckBjh6StHWRWXKo3TGg/oe 4/rf1i6yOjolGRbVKBaBkAD6RgV5XSCfWLtD1LnVhB+7fya9BVNzbvb9Gy/X4VOAApcD wjoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=M6B3cEMx; 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 h17si9220687eda.54.2019.09.09.04.41.53; Mon, 09 Sep 2019 04:42:16 -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=M6B3cEMx; 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 S1731341AbfIHMtM (ORCPT + 99 others); Sun, 8 Sep 2019 08:49:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:38740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731305AbfIHMtG (ORCPT ); Sun, 8 Sep 2019 08:49:06 -0400 Received: from localhost (unknown [62.28.240.114]) (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 D470E218AC; Sun, 8 Sep 2019 12:49:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567946946; bh=VRPsPuIBY4yMxezp/2v4CZXX5VnhYHXSUl8WZGQ8Cno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M6B3cEMx3Yh1SAZD3aDSmh4daWtPF83vpMHqgh9+3koEmtneU7uVH40yqS6oLxQMB N1Cbk3bXitfxczGc0g/nFArCXBvotkUkd/0yS4UnnHEMpCkwbtulD2qdYy6hsa7sgJ 5Px7zHXy+mV/vWSIDt1a+VaX4BsvDFlMxW7MHy8E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tho Vu , Kazuya Mizuguchi , Simon Horman , "David S. Miller" , Sasha Levin Subject: [PATCH 4.19 37/57] ravb: Fix use-after-free ravb_tstamp_skb Date: Sun, 8 Sep 2019 13:42:01 +0100 Message-Id: <20190908121141.858142099@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190908121125.608195329@linuxfoundation.org> References: <20190908121125.608195329@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ 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 5f092bbd05148..5462d2e8a1b71 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. * @@ -514,7 +514,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); @@ -1556,7 +1559,7 @@ static netdev_tx_t ravb_start_xmit(struct sk_buff *skb, struct net_device *ndev) DMA_TO_DEVICE); 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); @@ -1685,6 +1688,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