Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3922506pxj; Mon, 21 Jun 2021 09:26:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSAIEXmI4KQjhsyVInq/X0M6E4kEqLE8tchjYXfkXN0bR6a0d2rL0vU8H5bgvLFGKGWw94 X-Received: by 2002:aa7:cfd7:: with SMTP id r23mr22648319edy.300.1624292787744; Mon, 21 Jun 2021 09:26:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624292787; cv=none; d=google.com; s=arc-20160816; b=b9ALg46XggSdusQHAsOM5hJ4WAADrm9WimGSstv1zzi3vD2SKHwTPMPVuNXakIC02e q1pgcoYbOvE8QgeuD5v4p//t3xQRfPM9M31188+IPPas+AUkB6sGicBzLcq1Uexh0dVA Pn0E3Z9DPk/KXq87Ef3kCC0bwZaIqz+8Qw3/LosEXkUkqIiCGX7f221C4tXFxj4ck6PA +GEc4W83DWVEplZhXwzQbY9zdd2GNbXB7rweREYXAvqv/Udm6ju7nabhqJkw71f/Qax3 IRyqD1UpLiSkLP25boEbaPQgGjYH+AwdPU1zV22cx60DhjdsVrsacXsf7SaB9k9M5rtR sGtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9H4i1xhlAE5CxOZW3dVuvUj1rlaKrSRNfoRbK3fVGjY=; b=TSNK1Vvu7Hp9aPz1e8Y2i3Ww/tPh7Sk/2YmV5v4CCfqxGQx/TQrrnbCVWoAmGnAswR OAHls1k7Z3Oc4a0sco0qxvuoxmBbXWGvpc6Gvdd3YvNUeAntl/fYldMyUw3sdJcgy+73 HbMEjUrjR780aNzIrEwGlKUCRPxARvGEdHv4DJa9qxq199/tEfiAoCQbO1KlNS97QArh eX5ogFZ0gN3qeoeYlN6vlBHvhM2ap9kVz0RhZlHApXpFMwXL7NtTyNvJRmg+kPyPE5Sg yQsSqgappG4wCD2YnN35sWPvs2B06pVkSVFw8duz1/SRPr0h8vnS+/H+kgFzfmbGDVGY L1Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="t/NbOgZe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o20si2521704edv.332.2021.06.21.09.26.05; Mon, 21 Jun 2021 09:26:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="t/NbOgZe"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232089AbhFUQZF (ORCPT + 99 others); Mon, 21 Jun 2021 12:25:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:42100 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231230AbhFUQXW (ORCPT ); Mon, 21 Jun 2021 12:23:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6575A61363; Mon, 21 Jun 2021 16:20:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292440; bh=69/h3NmfheCHr7ttZzHKFKTZxHSCHAoFWctmoomN2W8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t/NbOgZe6Opj0uw3Ltr1aJ0GfYllICwWrGnm0CLxbCznIfquvAJNEdJ4VLxbjN75j 72GSZp3RDhUkBcLQ+r1m4Zey3tHoZ6SnGLCqUi6dTgHFz3imvwbd/FaQmupjdikaGk HPLi7XD8b/BBF65pXIapNJ+5wABV6zRnEbXHNZrw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Esben Haabendal , "David S. Miller" Subject: [PATCH 5.4 74/90] net: ll_temac: Make sure to free skb when it is completely used Date: Mon, 21 Jun 2021 18:15:49 +0200 Message-Id: <20210621154906.661716874@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154904.159672728@linuxfoundation.org> References: <20210621154904.159672728@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Esben Haabendal commit 6aa32217a9a446275440ee8724b1ecaf1838df47 upstream. With the skb pointer piggy-backed on the TX BD, we have a simple and efficient way to free the skb buffer when the frame has been transmitted. But in order to avoid freeing the skb while there are still fragments from the skb in use, we need to piggy-back on the TX BD of the skb, not the first. Without this, we are doing use-after-free on the DMA side, when the first BD of a multi TX BD packet is seen as completed in xmit_done, and the remaining BDs are still being processed. Cc: stable@vger.kernel.org # v5.4+ Signed-off-by: Esben Haabendal Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/xilinx/ll_temac_main.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/net/ethernet/xilinx/ll_temac_main.c +++ b/drivers/net/ethernet/xilinx/ll_temac_main.c @@ -873,7 +873,6 @@ temac_start_xmit(struct sk_buff *skb, st return NETDEV_TX_OK; } cur_p->phys = cpu_to_be32(skb_dma_addr); - ptr_to_txbd((void *)skb, cur_p); for (ii = 0; ii < num_frag; ii++) { if (++lp->tx_bd_tail >= TX_BD_NUM) @@ -912,6 +911,11 @@ temac_start_xmit(struct sk_buff *skb, st } cur_p->app0 |= cpu_to_be32(STS_CTRL_APP0_EOP); + /* Mark last fragment with skb address, so it can be consumed + * in temac_start_xmit_done() + */ + ptr_to_txbd((void *)skb, cur_p); + tail_p = lp->tx_bd_p + sizeof(*lp->tx_bd_v) * lp->tx_bd_tail; lp->tx_bd_tail++; if (lp->tx_bd_tail >= TX_BD_NUM)