Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3930587pxj; Mon, 21 Jun 2021 09:36:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZJitMerkIHMIugyzEpGXv8oPgRpsIYrOO+sruF1AYZn4WIXEAZ++sJHlDHGkIRx95SKu6 X-Received: by 2002:a05:6402:278a:: with SMTP id b10mr1249241ede.54.1624293399758; Mon, 21 Jun 2021 09:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624293399; cv=none; d=google.com; s=arc-20160816; b=R7MZAhj0h5odoMXpQA9aT5iZeIsFNcAj9XkclMxinJ2n6fo4QEOZmEsHS64yjKe+3J yV3etPF3MBFlNAU3TWFNbBwYEPmwop1fGdg5Cr4mcDiWDKjgczwFurIuJbFsY3DPWOoC dQWXapWfxa5GbsCWy+3qurGNfp1wCG0FctXC2O1hZnAdxjM+E/boFQK09myIJJzqoIYm 7+0YejszezJtdaL4oczWi4rxfvpP5577KnrreBD4REI8ngAFlNj3w4zSBB0hSeP8FZfM CNSeJp9iXfcwYXdYY7cSARIthCW/qlOKwl/4bPAetvEvG7dWHsskB2zYthvKsvSidu65 MUvA== 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=sm2KMxekQDqAb5pkW7L3+nbp9otlcXFC4nWEfwRH6HY=; b=VEmvawdF2z4Du3O5/8nIRjPujg7uVXcwpgvWB85ycCgYqWyIGOPPDizoqAOdiNwMWc 1HJKvA3KGxblS5oeogEJkGTJ0qBsQTcrfE9Gv62AYABFNNbR2t2M/HZae3Byp6IyQAvf Q2YIjf77lPwVwgN8OYpFQvNchAsiotrhy2P1u16S3RVzeLkT+2mk7LvF88caeP9pns+a D45ljJiE5f2YlZP9kkEDpLFj94A/MOix6gW0drzeo7Oa+PTCYOS+urbP2mJrsIpbDUsY mpHM6iDC8DJgYxt6fk/7tdUSa+pLydz0lu4NkvZN6p0Q4k1NI3SnTcV7xmCYyXcrVQgF 248w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="eD/CwHI8"; 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 w23si10529656ejf.188.2021.06.21.09.36.17; Mon, 21 Jun 2021 09:36:39 -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="eD/CwHI8"; 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 S232788AbhFUQhi (ORCPT + 99 others); Mon, 21 Jun 2021 12:37:38 -0400 Received: from mail.kernel.org ([198.145.29.99]:56118 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232335AbhFUQdR (ORCPT ); Mon, 21 Jun 2021 12:33:17 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5121561418; Mon, 21 Jun 2021 16:26:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624292790; bh=MsSNp23Mq1jV3Q5GrB1f+cvgk6IwxVyFRLbJw+MfcV4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eD/CwHI8kyn6RloAZ9fB7udveCjFYXAepjZZAlrsT0i+dGFJuylv8gQkSv+7/1wt5 PNerd8LT7ZaZDmpNvMdvHepTiZezIVyZZD1mZjQ3ocniBh7rCVBi9XBNxYSF4886mW L+ViZugcoMxQorGmJOFnYCUHtsyycFB6cPWhVrBE= 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.10 132/146] net: ll_temac: Make sure to free skb when it is completely used Date: Mon, 21 Jun 2021 18:16:02 +0200 Message-Id: <20210621154919.931906299@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210621154911.244649123@linuxfoundation.org> References: <20210621154911.244649123@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 @@ -876,7 +876,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 >= lp->tx_bd_num) @@ -915,6 +914,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 >= lp->tx_bd_num)