Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2713814pxj; Mon, 31 May 2021 08:55:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJziDwZsrYaYNdvRtM7Kpp8PRiNvLYYMeuupDYzXsk0jYzX29tAQ6v/SwUALEF2ew1kfrgUY X-Received: by 2002:a17:906:1952:: with SMTP id b18mr10506692eje.262.1622476508282; Mon, 31 May 2021 08:55:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622476508; cv=none; d=google.com; s=arc-20160816; b=GvAr85iOrOVwNsy/IIJYBoqxvZ3YtVDdwmf5PhrnBhkEfVpw5z+3aFUojvaFvwvT29 dGZYuYf6IzGYLJFrEVx/RZBMEyW/U8Wy1ezhNAciQg+J6qX9Wul83l/dbyqUAM2u7bap n8szbilNpkQhIChXZbeD2zto46fe+q3PEqScEANN9+LXvJAycKpFXeUjLG70Vzh5RRKX qyjStASQ/zDlQRo40OB6uYL5GKx3fgPnG7qzUCqcSsWsEvbHleoGCBWZCh9cgNx/IDo4 owwo8kfJVbobrqF0ZGwHNw3EQVBfaff+7RdN6qugNazBJI7kka6nLIK295tCmPKDREHF i2LA== 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=j81iJu6b7zLsxJE9JpEXHuEqa1BLz9ykCZOnwBbhxQo=; b=qBAFjXFlKfyjGYp44Mqjd7HAnKC1AlbxWTSVgmiCjhKhg/X4eu+bKDV9uDx5IlNiLP xlHsAwfQ2TAFIzZZm1BjCl2jntmKh7OQLnKC0W2v/s196Ipth4uI/m0GxwNad2+OYJSK e++EUCuZj7qIvRtfk5D5U4Z7+izG3uiwmWNu/FsNzQeHETirS/Nv9xOIC6YmX3pWp9uA wD5d8AsAkdDF3BUkNPmvmJkaOWzBmpigkemSxY7c4gExfKk3GxwEHMLPh9i/SG8jjKn9 JsJiexh8AyqDPO4AE1S+Zuc8J+IxrAV/EtA0THq6zM4GW3hL6JzRwW1XIFW8C2FXpWJn R5iQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DJ7cmN6C; 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 mb15si83526ejb.279.2021.05.31.08.54.45; Mon, 31 May 2021 08:55:08 -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=DJ7cmN6C; 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 S234509AbhEaPzL (ORCPT + 99 others); Mon, 31 May 2021 11:55:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:56328 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233996AbhEaO3h (ORCPT ); Mon, 31 May 2021 10:29:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id DCC7161C2C; Mon, 31 May 2021 13:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468922; bh=lxk174Ryk4cZ/o2Rr7e56WRgvltK8lnkiXY/ACDHFBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DJ7cmN6CCL9J6f5xbqXhTfRV13vFOaD8Fx8tXymkF2Z/wwLXzd+v7vUKUNkZqKoHF RQWPdvUxOHtnSDuvnRpc4of3D6XneU111Q/IIXTSSqL60wDnLRne4oC5aDkxI+Ropt IlgXD6RPbxr5fuedlmB+TbVMggktw38rTH8pv/rY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aleksander Jan Bajkowski , "David S. Miller" , Sasha Levin Subject: [PATCH 5.4 163/177] net: lantiq: fix memory corruption in RX ring Date: Mon, 31 May 2021 15:15:20 +0200 Message-Id: <20210531130653.557782387@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130647.887605866@linuxfoundation.org> References: <20210531130647.887605866@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: Aleksander Jan Bajkowski [ Upstream commit c7718ee96dbc2f9c5fc3b578abdf296dd44b9c20 ] In a situation where memory allocation or dma mapping fails, an invalid address is programmed into the descriptor. This can lead to memory corruption. If the memory allocation fails, DMA should reuse the previous skb and mapping and drop the packet. This patch also increments rx drop counter. Fixes: fe1a56420cf2 ("net: lantiq: Add Lantiq / Intel VRX200 Ethernet driver ") Signed-off-by: Aleksander Jan Bajkowski Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/ethernet/lantiq_xrx200.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c index 4e44a39267eb..6ece99e6b6dd 100644 --- a/drivers/net/ethernet/lantiq_xrx200.c +++ b/drivers/net/ethernet/lantiq_xrx200.c @@ -154,6 +154,7 @@ static int xrx200_close(struct net_device *net_dev) static int xrx200_alloc_skb(struct xrx200_chan *ch) { + dma_addr_t mapping; int ret = 0; ch->skb[ch->dma.desc] = netdev_alloc_skb_ip_align(ch->priv->net_dev, @@ -163,16 +164,17 @@ static int xrx200_alloc_skb(struct xrx200_chan *ch) goto skip; } - ch->dma.desc_base[ch->dma.desc].addr = dma_map_single(ch->priv->dev, - ch->skb[ch->dma.desc]->data, XRX200_DMA_DATA_LEN, - DMA_FROM_DEVICE); - if (unlikely(dma_mapping_error(ch->priv->dev, - ch->dma.desc_base[ch->dma.desc].addr))) { + mapping = dma_map_single(ch->priv->dev, ch->skb[ch->dma.desc]->data, + XRX200_DMA_DATA_LEN, DMA_FROM_DEVICE); + if (unlikely(dma_mapping_error(ch->priv->dev, mapping))) { dev_kfree_skb_any(ch->skb[ch->dma.desc]); ret = -ENOMEM; goto skip; } + ch->dma.desc_base[ch->dma.desc].addr = mapping; + /* Make sure the address is written before we give it to HW */ + wmb(); skip: ch->dma.desc_base[ch->dma.desc].ctl = LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) | @@ -196,6 +198,8 @@ static int xrx200_hw_receive(struct xrx200_chan *ch) ch->dma.desc %= LTQ_DESC_NUM; if (ret) { + ch->skb[ch->dma.desc] = skb; + net_dev->stats.rx_dropped++; netdev_err(net_dev, "failed to allocate new rx buffer\n"); return ret; } -- 2.30.2