Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3973513pxb; Tue, 25 Jan 2022 00:21:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJxkdiOtE/6fMqwMJpHCDslx3IedGcywwO9LCvhwrv6Q70zjRXSQfN3sRdVsbc7ZmC9qv1Yt X-Received: by 2002:a17:906:c099:: with SMTP id f25mr16029428ejz.458.1643098901274; Tue, 25 Jan 2022 00:21:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643098901; cv=none; d=google.com; s=arc-20160816; b=EZohjh1OikTR8OJF/jUXcGiyCEzSdds70/NHNkQnt80AeuFwPPY/sNtwj3Eo5k8J+c 4LvwMrrInFAPTZHUIbJqy7FZQ+M58K4oZNvCTTisC9Ob3sJyBFCVoa4HRy3owN/6Xmk0 OfvzfqDXdXdtarL54AodQflQrxoJzup4+meWvhqpLPmh8xtxhLeYhbHqsARSFhOH3Ued cE819QFcKSNOx9N+0yt6Vht1brwQFBaAI3YHBHJ0NN5oeRz3FVP4mRT6HyuudFIpJRD6 pUOFik6OA6kExHWYHUnixdTq8GQMSmEbfyLLaQlgxn6DB7Sl1oorLoN259E1V+iFavXC n50w== 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=YnHqeBXVoaERynvjcKp1GDouLZmyCi/q+YLkW19o8MI=; b=VzxtcxMq9eaSnh+xJV6vTrzMfmYDgY0vl3zqGdTcQ4wLSCNi3rB+i5t0kkOQPrr7kF 4GKuRj9hOHK7HSxpYRg5D3Ag/HspgqHrLEJ5mQzNY+QK7akQQ5b0IIDfezS7fPrOG9Yz acuRQ7SRsJxk4LF/CfgOwK9NP0vwpdioWatqDDnGL0PL5ris295r52vbZszJ0PPZVis1 eeLIdsL8MBEBs2UUs4f5cM37ayaE1fubpxCYAqQgP1Y9aSc4/i8hcIOV2WurHCEwkiZi xc73mYTS0H/+nV6b9Rtc7HCdK53FLnp2cDC+/5nLtoCevOxsZMw89n8osRevG9TcaV8g YxDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=lfOllt7y; 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 30si9153487ejq.841.2022.01.25.00.21.16; Tue, 25 Jan 2022 00:21:41 -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=lfOllt7y; 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 S1353293AbiAYCVj (ORCPT + 99 others); Mon, 24 Jan 2022 21:21:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345378AbiAXTJO (ORCPT ); Mon, 24 Jan 2022 14:09:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2B10C08C5C8; Mon, 24 Jan 2022 11:02:10 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id 4270B60B88; Mon, 24 Jan 2022 19:02:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2BF9CC340E5; Mon, 24 Jan 2022 19:02:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643050929; bh=QCtmgIcGnpfCyyzcV5Uihv/WnmLZGb5ICQw+jPbJ7zQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lfOllt7y4kt6cl8JiDFcmBh3RD8gXxTYUNJid4Je3l8LtVJFw8MQ00QzYYEi8PemF RWrAZTJfj5801+6xC66HOENXaqLwlucRaorV+1gmCOMqzMJ3sL6hOhvJOIQVleG6K0 b/o9yiMOfRupgMoIlUwX3w7UgMNOqsclc44l2KHI= 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.9 149/157] gianfar: simplify FCS handling and fix memory leak Date: Mon, 24 Jan 2022 19:43:59 +0100 Message-Id: <20220124183937.491196016@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124183932.787526760@linuxfoundation.org> References: <20220124183932.787526760@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 @@ -2939,29 +2939,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 */ @@ -3074,6 +3062,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);