Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5028676pxb; Mon, 15 Feb 2021 07:44:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJzujBAugh+t0H6bQFsRJ6EC6Sa3Dpm6+N4Auaw4lgc6j4vSt+PsERHEy0OvblUpydc1h6J4 X-Received: by 2002:a50:a6ce:: with SMTP id f14mr16130861edc.346.1613403853935; Mon, 15 Feb 2021 07:44:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613403853; cv=none; d=google.com; s=arc-20160816; b=QAyAFknfmPwHgYLDANEDg8J1+g9UWF43kImc+5cKFMvM63ttrRPx5h4R/jEIeFcC9A 1rjwj29XPL86C6JGyZjei1CTpXIm3r4By2vKGlfSRqTvpX9MJSwo67n3JV3FkvBU/t7n RvzG/fUpLnnQhIrBkdHwa1pJ/sC2/yInlyu9aeGE5zwm7YZRh6Ty+uvu73hR3TBMoJBO Vsfrl8etdjlw0ECrp3fzhiSdgn9FDoaf4m7bYiOQxfjcY/+iGljXpmi4Fs/25TL9ttHW pgPGB8oOi6MmRD03GMSETn1/Fw0WFvrZmb+mPk3EWO903h4qe2LLqfxPhn5c2j1TQhgH EqLg== 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=olNcm7d0OTzuzyx6AGhYRAK29g9YNnkesv+prpU4i5g=; b=ujdzF4q3ZXk7dvd+Z80kkz2hxqBQ2U9E+yLmhs15STyskeGd3oKwEZB+sHARJOF1yj zWw4Pc7I9w5cg0ICZqHLursMRRQgbrB4pRv1JxGiIdqqtPF8tYaT0J/boo02++xqm2KV /f53vz+bBiePKPDY9bLGM3MIizJbzN+aJMl6HeT4hhzG2snhZnOmiZJwOAwGWvjrP4FS osP1bjUIBGWhTPP64WZ/+DQJeAqS61kGbuLnt5FxnmwbjJPg0Pm0Et+rpMWotfhwgnba N6Mi4U0j/+OSJZ3RH+8vLsQb6/Y6AMwwCkFtSa/8froGdGVxeKcJsdDzGq79rokQxD8c fYfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=V09svDXI; 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 ck13si12184155edb.505.2021.02.15.07.43.49; Mon, 15 Feb 2021 07:44:13 -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=V09svDXI; 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 S231537AbhBOPmv (ORCPT + 99 others); Mon, 15 Feb 2021 10:42:51 -0500 Received: from mail.kernel.org ([198.145.29.99]:45436 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230160AbhBOPat (ORCPT ); Mon, 15 Feb 2021 10:30:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 6A24564E7B; Mon, 15 Feb 2021 15:28:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1613402936; bh=4Bi+YtUSMojEFvriuXcLkjj3Lnw4Zl2BmQopFeoNn8s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V09svDXIVW7O6sQi6EjPPXonLTBebeYIQ1G0MzXKtXglSWY6Hk5ZOqHgM5AlF+tMb Lr/eShRgjzyeTKsDDuq9fWkjoAnpw1ApeJep7BXrpJNBMIkzq2l0f0o5UTA6Qx7MVy Uxww8kfNkf6JKH/HMfm3j64+oL5wX7byctUcu5vw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Felix Fietkau , Kalle Valo , Sasha Levin Subject: [PATCH 5.4 26/60] mt76: dma: fix a possible memory leak in mt76_add_fragment() Date: Mon, 15 Feb 2021 16:27:14 +0100 Message-Id: <20210215152716.189203864@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210215152715.401453874@linuxfoundation.org> References: <20210215152715.401453874@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: Lorenzo Bianconi [ Upstream commit 93a1d4791c10d443bc67044def7efee2991d48b7 ] Fix a memory leak in mt76_add_fragment routine returning the buffer to the page_frag_cache when we receive a new fragment and the skb_shared_info frag array is full. Fixes: b102f0c522cf6 ("mt76: fix array overflow on receiving too many fragments for a packet") Signed-off-by: Lorenzo Bianconi Acked-by: Felix Fietkau Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/4f9dd73407da88b2a552517ce8db242d86bf4d5c.1611616130.git.lorenzo@kernel.org Signed-off-by: Sasha Levin --- drivers/net/wireless/mediatek/mt76/dma.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index 026d996612fbe..781952b686ed2 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -452,15 +452,17 @@ static void mt76_add_fragment(struct mt76_dev *dev, struct mt76_queue *q, void *data, int len, bool more) { - struct page *page = virt_to_head_page(data); - int offset = data - page_address(page); struct sk_buff *skb = q->rx_head; struct skb_shared_info *shinfo = skb_shinfo(skb); if (shinfo->nr_frags < ARRAY_SIZE(shinfo->frags)) { - offset += q->buf_offset; + struct page *page = virt_to_head_page(data); + int offset = data - page_address(page) + q->buf_offset; + skb_add_rx_frag(skb, shinfo->nr_frags, page, offset, len, q->buf_size); + } else { + skb_free_frag(data); } if (more) -- 2.27.0