Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3322265pxf; Mon, 15 Mar 2021 07:07:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxI2tG64JC8wbc+MYkNI2m66rpmcp+JyNr1c3gU/gv81uLx3JJv+kdkOVDXRc8OhgjUTRL/ X-Received: by 2002:a17:906:340d:: with SMTP id c13mr13612076ejb.29.1615817239308; Mon, 15 Mar 2021 07:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817239; cv=none; d=google.com; s=arc-20160816; b=s+ysULbRFbeGUsyeVzSOzOWj2yb4w+7qj3UZet0IcZ4PHscVbwaazd9WBpDt5zKREX uezRfmLAA1UQuC20guAHtrPUG7wz1vaTS9q9wy9Ccj5brseVuEz1BavYRiJM89lADm8L urh76sCoIe91N0kKVrcbzLBsz87cBRw02mORuehss/LljCzgV5AlyBeESpRrZ5TZ/puq CjGknBXk+U3v5Tz0BiEctaqJgGFksGSa21pRmFYg3QBH4rWraLZJJzFyMT0UAJyC0z5t ivQtGMj1Qzs68RcdtLpGVvK0wykcbvrM4s0XhRqp7U25OaBK2k5AgYfqB8HsnZd3mwCp rW8g== 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=UI6UF7DQ9ahqaucpiKpabDyjruah/ic4/vheHwQOw7M=; b=vDvZ3QXL4AL5brHqC/xkV9DxLdktiHMs/1KrG3za4ll7Lg5WLE9TGGANmSKIGnpvhd 5uuFh2R285AffpxbHjtGIQ0toFAa98UVx/LfNdqQ6dvIBz487Ux9rHBc8yRzImRGqGUY tmgm0yoBxSKtmh5vwZtnyVRV7RU5c97SrAPDR54Y+tcUM6rGeueGwC3HXveqxrbWJm8T YegHoG8NUPjW3U1txVGpzgZwTTJtPXhWGKOXk4YdVCzg+F9K85RwZwd/a2mdImw00dgq BTBTM0MRmBWiNzd+ODw06E/V6YWhmCxQcsIKERhAGjFIpsq760tD2DktRai8/f6LyDZO zpyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QiPQccQ8; 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 c25si2573385edw.293.2021.03.15.07.06.55; Mon, 15 Mar 2021 07:07:19 -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=QiPQccQ8; 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 S234763AbhCOOFU (ORCPT + 99 others); Mon, 15 Mar 2021 10:05:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:34914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231954AbhCON5W (ORCPT ); Mon, 15 Mar 2021 09:57:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 204D764EF3; Mon, 15 Mar 2021 13:57:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816642; bh=aneOWmOOWmIl8hRLCnsyajJWidVl5RoYKKE83iHcykw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QiPQccQ8AxTJpdboYgs3aGlpFQQK3eiFYJ7Esn3/YaLM1SiZ2bqwdRr9aXY8fxeua iKELuuIPz4zuEDlg7/wlrpN/gCy9XqorJxWi0Lu0AHcPBNWkhyRUyoEwkWN/OlHvyb RqKG5Td53Rq1I3KC8WejKsvK4tLJwF+u2ZQtfN4A= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lorenzo Bianconi , Kalle Valo Subject: [PATCH 5.11 037/306] mt76: dma: do not report truncated frames to mac80211 Date: Mon, 15 Mar 2021 14:51:40 +0100 Message-Id: <20210315135508.893642039@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@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: Greg Kroah-Hartman From: Lorenzo Bianconi commit d0bd52c591a1070c54dc428e926660eb4f981099 upstream. Commit b102f0c522cf6 ("mt76: fix array overflow on receiving too many fragments for a packet") fixes a possible OOB access but it introduces a memory leak since the pending frame is not released to page_frag_cache if the frag array of skb_shared_info is full. Commit 93a1d4791c10 ("mt76: dma: fix a possible memory leak in mt76_add_fragment()") fixes the issue but does not free the truncated skb that is forwarded to mac80211 layer. Fix the leftover issue discarding even truncated skbs. Fixes: 93a1d4791c10 ("mt76: dma: fix a possible memory leak in mt76_add_fragment()") Signed-off-by: Lorenzo Bianconi Signed-off-by: Kalle Valo Link: https://lore.kernel.org/r/a03166fcc8214644333c68674a781836e0f57576.1612697217.git.lorenzo@kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/net/wireless/mediatek/mt76/dma.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -511,13 +511,13 @@ mt76_add_fragment(struct mt76_dev *dev, { struct sk_buff *skb = q->rx_head; struct skb_shared_info *shinfo = skb_shinfo(skb); + int nr_frags = shinfo->nr_frags; - if (shinfo->nr_frags < ARRAY_SIZE(shinfo->frags)) { + if (nr_frags < ARRAY_SIZE(shinfo->frags)) { 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); + skb_add_rx_frag(skb, nr_frags, page, offset, len, q->buf_size); } else { skb_free_frag(data); } @@ -526,7 +526,10 @@ mt76_add_fragment(struct mt76_dev *dev, return; q->rx_head = NULL; - dev->drv->rx_skb(dev, q - dev->q_rx, skb); + if (nr_frags < ARRAY_SIZE(shinfo->frags)) + dev->drv->rx_skb(dev, q - dev->q_rx, skb); + else + dev_kfree_skb(skb); } static int