Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2296027ybl; Thu, 19 Dec 2019 11:09:54 -0800 (PST) X-Google-Smtp-Source: APXvYqyrYE0nfrAw+PPakUs7z12Q/FiSMK1rN/oWFdRPKnx/HnOWyMykD0nZ59jmRZtMhdk2qy1J X-Received: by 2002:a9d:12f1:: with SMTP id g104mr10784006otg.334.1576782594634; Thu, 19 Dec 2019 11:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576782594; cv=none; d=google.com; s=arc-20160816; b=zuiEYJgN2rh9wmyRDY0O+hPgMZDvnLRanA+leRAPxRDkB5amsQZtLYnY3+S4izcgzK 74064t5JCLJNP0MjVjOma2dIob6Hx2EsrXL2bE5Jzj1KxrDy27XleZBYxDYrbEYWMLzA V27wHzUQFWYigjS6olDYuiFrF8iitzfETeOuIzSmxeZVL2AjBOibsCGbEgUd4uaQoRn3 FQvLWMfwIhgikO01RTuM8UmcP3HF8y9+++DBqC8Z6zH24d3GdypPakBJikP5i/9mOs10 n8kWFazxB1Q6Nr5Sxn3Gwn6zuV+AKblyhF9+Rn4/eq76Ys4xXyR7/c/g94ulBDLh4mQ6 3LDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WSiqDyaIli7d6vSuf60NTgGvNldM0CMV1rNWhtiIbMc=; b=OScoWZDAa1HFtIpUdJ1IOhT4e3HpgKoVN02tjZwLDfN/eSMNcEgtBM5jZrZsoB28Wf KzVIrob81csZCAf7mUfwWw2kRAVXeLjTahbvUEm7+Rwntd+YIHACRthjiwhizeGb50kV XBl/idfaDap73rigs4w/sdgx+72cjo2Clmodgh8dYLZgL+M81PI2jXEFIHuI4PfsI41f uOw6DEQZKgWFK+myUD0ruHTGZM7G05EMzt5Bm5Q000FyZsbHxI2lxtiuDJRDs6uQGGFR n35F127CtveOvWp2G5f1p8vcSh/BYY02bp+W4Kmge4I8Z9e4YfdXT5ljwTcGDbtA6Dn/ JCHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WfUOBlR5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 194si3528223oii.2.2019.12.19.11.09.42; Thu, 19 Dec 2019 11:09:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WfUOBlR5; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728567AbfLSSli (ORCPT + 99 others); Thu, 19 Dec 2019 13:41:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:60606 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728137AbfLSSld (ORCPT ); Thu, 19 Dec 2019 13:41:33 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0F409206D7; Thu, 19 Dec 2019 18:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576780892; bh=CR7iJLBFC0p+I0svM9R3QUfqLgsXkDgcOEVVfc+aVFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WfUOBlR55DaqBjeB7w8mCh84jw9FxX1uhYqRcQC/dYPHbLPqhPx48uLzvpHpR1Bpt KPADiLcGHUeS3wck9wDY//cuY166UhxfOZrpoS18bkamyeL/p8ogJtnitqCFw+5f0d NdtrATjEx3rzlL4ybOWKAz9Y3kOP0lMscNHAnEGw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaro Koskinen , "David S. Miller" , Aviraj CJ Subject: [PATCH 4.4 161/162] net: stmmac: use correct DMA buffer size in the RX descriptor Date: Thu, 19 Dec 2019 19:34:29 +0100 Message-Id: <20191219183217.559737066@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183150.477687052@linuxfoundation.org> References: <20191219183150.477687052@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Aaro Koskinen commit 583e6361414903c5206258a30e5bd88cb03c0254 upstream. We always program the maximum DMA buffer size into the receive descriptor, although the allocated size may be less. E.g. with the default MTU size we allocate only 1536 bytes. If somebody sends us a bigger frame, then memory may get corrupted. Fix by using exact buffer sizes. Signed-off-by: Aaro Koskinen Signed-off-by: David S. Miller [acj: backport to v4.4 -stable : - Modified patch since v4.4 driver has no support for Big endian - Skipped the section modifying non-existent functions in dwmac4_descs.c and dwxgmac2_descs.c ] Signed-off-by: Aviraj CJ Signed-off-by: Greg Kroah-Hartman --- drivers/net/ethernet/stmicro/stmmac/common.h | 2 +- drivers/net/ethernet/stmicro/stmmac/descs_com.h | 14 ++++++++++---- drivers/net/ethernet/stmicro/stmmac/enh_desc.c | 10 +++++++--- drivers/net/ethernet/stmicro/stmmac/norm_desc.c | 10 +++++++--- drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 4 ++-- 5 files changed, 27 insertions(+), 13 deletions(-) --- a/drivers/net/ethernet/stmicro/stmmac/common.h +++ b/drivers/net/ethernet/stmicro/stmmac/common.h @@ -301,7 +301,7 @@ struct dma_features { struct stmmac_desc_ops { /* DMA RX descriptor ring initialization */ void (*init_rx_desc) (struct dma_desc *p, int disable_rx_ic, int mode, - int end); + int end, int bfsize); /* DMA TX descriptor ring initialization */ void (*init_tx_desc) (struct dma_desc *p, int mode, int end); --- a/drivers/net/ethernet/stmicro/stmmac/descs_com.h +++ b/drivers/net/ethernet/stmicro/stmmac/descs_com.h @@ -33,9 +33,10 @@ /* Specific functions used for Ring mode */ /* Enhanced descriptors */ -static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end) +static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize) { - p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1; + if (bfsize == BUF_SIZE_16KiB) + p->des01.erx.buffer2_size = BUF_SIZE_8KiB - 1; if (end) p->des01.erx.end_ring = 1; } @@ -61,9 +62,14 @@ static inline void enh_set_tx_desc_len_o } /* Normal descriptors */ -static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end) +static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize) { - p->des01.rx.buffer2_size = BUF_SIZE_2KiB - 1; + int size; + + if (bfsize >= BUF_SIZE_2KiB) { + size = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1); + p->des01.rx.buffer2_size = size; + } if (end) p->des01.rx.end_ring = 1; } --- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c @@ -238,16 +238,20 @@ static int enh_desc_get_rx_status(void * } static void enh_desc_init_rx_desc(struct dma_desc *p, int disable_rx_ic, - int mode, int end) + int mode, int end, int bfsize) { + int bfsize1; + p->des01.all_flags = 0; p->des01.erx.own = 1; - p->des01.erx.buffer1_size = BUF_SIZE_8KiB - 1; + + bfsize1 = min(bfsize, BUF_SIZE_8KiB - 1); + p->des01.erx.buffer1_size = bfsize1; if (mode == STMMAC_CHAIN_MODE) ehn_desc_rx_set_on_chain(p, end); else - ehn_desc_rx_set_on_ring(p, end); + ehn_desc_rx_set_on_ring(p, end, bfsize); if (disable_rx_ic) p->des01.erx.disable_ic = 1; --- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c @@ -121,16 +121,20 @@ static int ndesc_get_rx_status(void *dat } static void ndesc_init_rx_desc(struct dma_desc *p, int disable_rx_ic, int mode, - int end) + int end, int bfsize) { + int bfsize1; + p->des01.all_flags = 0; p->des01.rx.own = 1; - p->des01.rx.buffer1_size = BUF_SIZE_2KiB - 1; + + bfsize1 = min(bfsize, (BUF_SIZE_2KiB - 1)); + p->des01.rx.buffer1_size = bfsize1; if (mode == STMMAC_CHAIN_MODE) ndesc_rx_set_on_chain(p, end); else - ndesc_rx_set_on_ring(p, end); + ndesc_rx_set_on_ring(p, end, bfsize); if (disable_rx_ic) p->des01.rx.disable_ic = 1; --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -964,11 +964,11 @@ static void stmmac_clear_descriptors(str if (priv->extend_desc) priv->hw->desc->init_rx_desc(&priv->dma_erx[i].basic, priv->use_riwt, priv->mode, - (i == rxsize - 1)); + (i == rxsize - 1), priv->dma_buf_sz); else priv->hw->desc->init_rx_desc(&priv->dma_rx[i], priv->use_riwt, priv->mode, - (i == rxsize - 1)); + (i == rxsize - 1), priv->dma_buf_sz); for (i = 0; i < txsize; i++) if (priv->extend_desc) priv->hw->desc->init_tx_desc(&priv->dma_etx[i].basic,