Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3722198pxb; Tue, 26 Jan 2021 03:07:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJxMLkE/SR8TXWPsDwjVwTMRivck2xYFLCxN+r7pp9JoUB2wop1t1rcyD2X7KzC80ANcGX/v X-Received: by 2002:a05:6402:13c8:: with SMTP id a8mr4079119edx.191.1611659222911; Tue, 26 Jan 2021 03:07:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611659222; cv=none; d=google.com; s=arc-20160816; b=Hft+/wBTpgV7xHu3TzUH2K0nM1/1xlHIyAyMIdt1jfzyIQupvpA8UwOYM2bka3SkQx xd1z038OqLTxiP6pMiwuWI8Kvh/C0TbWPimPj4ocyTDD6R3MQfF6NssqIckEaPBtPngr uYsfv3pdvoO6MzctIoapajwHmEKVFhBKWYZ4IJyKvYm2Yi9mV2yCvzro6WaLCY9/j76t qwP8tRCUSZoDM4NXScdbr/ERppG5rwWqnx9NsbOlC78p+2LTZ9rzwGwUSXDBmSID/G0g e64qyv6wUfwr/j0VhMmKPG7pNQqjZtm/dCloe8l80ANeKfcXncJbSsLOZ3NomtVch9Y4 SaFw== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=Qy4FZVOEmf86L8RnVZ3/nOt2oVR3yOVekKUL8giLY10=; b=ewdK7vxE6NR3oixOUJj0tTcmUb87iDeW+kOxlJvZxkNFp2EJnBpG/j7Ru3ts0jeeZg oiOJfaUOeweZHs0+MCUJcihkGkwcUH09D6p9UP/m9/LG/Ih0Y7pDh8avVA4bt1u2fU2G Px+l9RERrfX9F9Ux/ey41UcVIohi4cB6JiD2bomlKzdplxXktXD+zzt9QpxOThiMj2xs Gcsghy6DRn5SqFAUpc5e6bLTahC0G+hdyMb9W/7jFK2VHjBKJXv/i3qW2A4UJP/Rb9r/ r9jF/fh24Sbljj/r7RGPVRKB+JsugjmkZiJC81YG/Gp4jAPX/Q4wyMEWiRXTuLpOFmWm f9Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dGtoip9H; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h10si7005347ejb.554.2021.01.26.03.06.28; Tue, 26 Jan 2021 03:07:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-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=@kernel.org header.s=k20201202 header.b=dGtoip9H; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404786AbhAZLDJ (ORCPT + 99 others); Tue, 26 Jan 2021 06:03:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:35818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404774AbhAZLDF (ORCPT ); Tue, 26 Jan 2021 06:03:05 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5A3E423104; Tue, 26 Jan 2021 11:02:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611658945; bh=cuf+7kki04NnMhtDTTOevd4ortyvy8aAh/LrEWAERVc=; h=From:To:Cc:Subject:Date:From; b=dGtoip9HJAD1+QL2NOncQ4BFY0MtNeUhLiih1izREzeRpN4i2FhAJAzYEf/kumlko 7nULR6UaVaHfpzINWDUc/DaOif6T5Sv+WbuoRua9TX73jD8+13xlZJmQ4HdxcqaCOk aq6qF6fGefP6IhdavEpo9lUcaCWUkEbHrtIUim0FcICwINPsi2sfgKuQh/wIEJQegv QV8dfgmLXydHu3gxfBUetsswALjCnVWjHNHuy3znKyso1JAUu0IhUonXWVlHslSVnM p5PPn8I00sf/Fh+BbrWob1Ti0oxtZddAdb6xwqAav0HsDMXGBzThWgzAw14jgTtjFC DsyJYcX0CMVbA== From: Lorenzo Bianconi To: linux-wireless@vger.kernel.org Cc: nbd@nbd.name, lorenzo.bianconi@redhat.com Subject: [PATCH wireless-drivers] mt76: dma: fix a possible memory leak in mt76_add_fragment() Date: Tue, 26 Jan 2021 12:02:13 +0100 Message-Id: <4f9dd73407da88b2a552517ce8db242d86bf4d5c.1611616130.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 --- 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 73eeb00d5aa6..e81dfaf99bcb 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -509,15 +509,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.29.2