Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3323696pxf; Mon, 15 Mar 2021 07:08:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPz2VsfaxIkqNdtxsgPpRGDXOq6Lj3FHqVIMATBPCqU5cCWP0TvG175uHk95SL4N+6Hm/T X-Received: by 2002:aa7:d156:: with SMTP id r22mr30655614edo.18.1615817327304; Mon, 15 Mar 2021 07:08:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615817327; cv=none; d=google.com; s=arc-20160816; b=ss1xjQwvs8IJrwXQE8IZyRYHAr+GrUW9Ob6OCVwvU2yd5+Rq+wa/nU12f3NOP0bCht D+EK3gUiD7L/sdSFo8rRn/tv4QBp7YsQDoFqA7bgwOKfRCWBKqeUN7Ft/UdQ8oA0gc/a 4C0x3DoiAPn4LK+ORFsmUXN3xQNToKgeOcBD+kUDpPITZTYGTzRROjhfdR4cpuyNG6FB xbylmzRrWW0F1MPydJJBHusD3yZA2u6xOMahCdBIENzilEEP/IVD14hWFbRXE53qMQdq ziuE4/zRud8HnDLfXABuSdruSnTiFCRoKInnAq9aoGzrzguMrTD0G/ywTjLk+L4Y2SAi 3jPA== 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=0JhNXokyPdQ3zZ1pQf0plS/B+oJbk2hafnG2VY98EYE=; b=rWjyJIdYhwcArZFW18rzExTkhd/ndbYs0vX6BHZwj4nx7vF/0j9/m1nOdC918kDxoq 3W2xEVf+lBdYiCdLXB4ExAnvJ3soywGfOWvkh4RKbnYHyORTVdiZI2vRtJzSaiNppXaK N+XJidQ8sD9h/qgarOHz2VpXUS4xsFzWVPs/a5lH/br9JKL0NssMZPm8KtlNItRT5qWo MyM+L3B5ow4hrV9LI0cuRIjzxMV9T2zGOZyhfYXIAcf4Y/X1sAqCTX7dqABSsbO1qXL3 We2lwCaqQWOdquiTdjkII4K1ehUUFoJJs0LDvc1WiIrxGb7fgIlZFw32prDH1Dh58WaI i1VQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=TdLn39i2; 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 gv18si11050125ejc.674.2021.03.15.07.08.22; Mon, 15 Mar 2021 07:08:47 -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=TdLn39i2; 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 S234790AbhCOOGF (ORCPT + 99 others); Mon, 15 Mar 2021 10:06:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:34930 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231773AbhCON5d (ORCPT ); Mon, 15 Mar 2021 09:57:33 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 46AD364F04; Mon, 15 Mar 2021 13:57:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816642; bh=VAKMwhZUhB+UP3gKr7StP1RfsiEAuHeGjIzf8ezS07I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TdLn39i2eVIvnHMxxqROrv7EU1aphyyF3JZqJz8/dKQPjwgSPh4CqE38PSVA/eCOJ q7r8yL5lU4jk40oojjAq+Hk+0dKDsPbt1xYS6OusbD/3lNmi1LU4V/sMJbasT6NrLW jLp4EmH12Bx6LUZHoYllxDbih6sT0ah6SanV5pqc= 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.4 021/168] mt76: dma: do not report truncated frames to mac80211 Date: Mon, 15 Mar 2021 14:54:13 +0100 Message-Id: <20210315135551.048571771@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135550.333963635@linuxfoundation.org> References: <20210315135550.333963635@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 @@ -454,13 +454,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); } @@ -469,7 +469,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