Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3564618pxb; Mon, 24 Jan 2022 12:19:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJythJn5dR0pFQhap1uK1wXiynGuRK6uQEK7LkeSxufyD/bCVmIltXG6ZYiodnsqWXGkEZsI X-Received: by 2002:a05:6a00:883:b0:4bc:39c1:9644 with SMTP id q3-20020a056a00088300b004bc39c19644mr15280282pfj.14.1643055477055; Mon, 24 Jan 2022 12:17:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643055477; cv=none; d=google.com; s=arc-20160816; b=0B7XXUzinFCl8zooF8ry2G7+b+gJ/z9iz38oqe0HJbuNo4npU2mH6kmv8Hcn+9Y7Rj wuu9utJ2beoeBz7okjEsZD75/fd5U0HmFd3B7Ya9G3JiJ+6DSlnlcXQSwIk6LV96yzcl OLPbOMd0M+l/r96sAnlUqaDxLIXCeRuEAJuL0wAkmZbw7uVF4+fXKcjwpUssT4m3JxQf Ql7tLOCqS9wBF6oU4efZgRg3aClkM6lpYLXTOaEVFzV8EaszlNV697JyktREpKwYc+Gq f1nF2mCDnlfaaLYGUEYbI9mI+iFiJgn570iB0xTcu2lYhbwkC8hntCuIJtuO4sJfLgSR TXcQ== 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=QXaQNsBkmN9nPEVxs8I4qor/rrh0Ed6x/zeOwhV8tz8=; b=WzmgHaqCBfSkpp+fSzRpvMYYUabTjg6TPN6WAzvzKlQerAlBfWHQSXheirFFoP2veH Iey84dqiK2WXi4z4WjhvYn/UpW2RVhlU4KF5KzWAd3guC4TcfsyJ9xBGi/8VVfzIfK/u 1yI4fJDm2/ca/BlQ2dGAkCtnVmGZ1DvxPmgv7OxHNwj19/yUb/MxqFkTwGDVrfxmBWtE J/wNlIdIZ3rlBUJnVaGp5wbsiolH43yogYvj3pUKfKrrsDTXKTQIfEqntA1LOS5qeH2c g2O5pVVu+o21kXCVlxWF2SY4SwUW6jPeSgsZ5+4E6jMieYmMZjDixWEetwA+CZeXQT0n KpAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=00kg9WOJ; 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 j69si5855451pgd.352.2022.01.24.12.17.44; Mon, 24 Jan 2022 12:17:57 -0800 (PST) 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=00kg9WOJ; 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 S1349330AbiAXTUg (ORCPT + 99 others); Mon, 24 Jan 2022 14:20:36 -0500 Received: from ams.source.kernel.org ([145.40.68.75]:38010 "EHLO ams.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345760AbiAXTMM (ORCPT ); Mon, 24 Jan 2022 14:12:12 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 3AD62B8121B; Mon, 24 Jan 2022 19:12:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52FADC340E7; Mon, 24 Jan 2022 19:12:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643051530; bh=zpx+7nESMQRkYZtXzoI6bEZjlXJJH0cIuPu5M2wgOws=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=00kg9WOJAOv+tZQddc/KhDmkDMDjdp5VXbwdI48iuqezOthDJfSYMmBTWrKkFUcJk 07dvDb/XSnuAV+rdikWZwu7TkAepjwxBRLNx1JK+LW2dLycuvU/nSBbjh/1jnaUnJw p91Kxw0BZ3qTJJZ0eQfYeJvdwMznFK19fmAmnCZw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andy Spencer , Jim Gruen , "David S. Miller" , Ben Hutchings Subject: [PATCH 4.14 184/186] gianfar: simplify FCS handling and fix memory leak Date: Mon, 24 Jan 2022 19:44:19 +0100 Message-Id: <20220124183943.021876700@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183937.101330125@linuxfoundation.org> References: <20220124183937.101330125@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: Andy Spencer commit d903ec77118c09f93a610b384d83a6df33a64fe6 upstream. Previously, buffer descriptors containing only the frame check sequence (FCS) were skipped and not added to the skb. However, the page reference count was still incremented, leading to a memory leak. Fixing this inside gfar_add_rx_frag() is difficult due to reserved memory handling and page reuse. Instead, move the FCS handling to gfar_process_frame() and trim off the FCS before passing the skb up the networking stack. Signed-off-by: Andy Spencer Signed-off-by: Jim Gruen Signed-off-by: David S. Miller Cc: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/freescale/gianfar.c | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) --- a/drivers/net/ethernet/freescale/gianfar.c +++ b/drivers/net/ethernet/freescale/gianfar.c @@ -2936,29 +2936,17 @@ static bool gfar_add_rx_frag(struct gfar { int size = lstatus & BD_LENGTH_MASK; struct page *page = rxb->page; - bool last = !!(lstatus & BD_LFLAG(RXBD_LAST)); - - /* Remove the FCS from the packet length */ - if (last) - size -= ETH_FCS_LEN; if (likely(first)) { skb_put(skb, size); } else { /* the last fragments' length contains the full frame length */ - if (last) + if (lstatus & BD_LFLAG(RXBD_LAST)) size -= skb->len; - /* Add the last fragment if it contains something other than - * the FCS, otherwise drop it and trim off any part of the FCS - * that was already received. - */ - if (size > 0) - skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, - rxb->page_offset + RXBUF_ALIGNMENT, - size, GFAR_RXB_TRUESIZE); - else if (size < 0) - pskb_trim(skb, skb->len + size); + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, page, + rxb->page_offset + RXBUF_ALIGNMENT, + size, GFAR_RXB_TRUESIZE); } /* try reuse page */ @@ -3071,6 +3059,9 @@ static void gfar_process_frame(struct ne if (priv->padding) skb_pull(skb, priv->padding); + /* Trim off the FCS */ + pskb_trim(skb, skb->len - ETH_FCS_LEN); + if (ndev->features & NETIF_F_RXCSUM) gfar_rx_checksum(skb, fcb);