linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hauke Mehrtens <hauke@hauke-m.de>
To: Aleksander Jan Bajkowski <olek2@wp.pl>,
	davem@davemloft.net, kuba@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net] lantiq: net: fix duplicated skb in rx descriptor ring
Date: Mon, 7 Jun 2021 00:25:17 +0200	[thread overview]
Message-ID: <71b611de-5f07-677c-f253-38adb562eb72@hauke-m.de> (raw)
In-Reply-To: <20210606200551.1609521-1-olek2@wp.pl>


[-- Attachment #1.1.1: Type: text/plain, Size: 2091 bytes --]

On 6/6/21 10:05 PM, Aleksander Jan Bajkowski wrote:
> The previous commit didn't fix the bug properly. By mistake, it replaces
> the pointer of the next skb in the descriptor ring instead of the current
> one. As a result, the two descriptors are assigned the same SKB. The error
> is seen during the iperf test when skb_put tries to insert a second packet
> and exceeds the available buffer.
> 
> Fixes: c7718ee96dbc ("net: lantiq: fix memory corruption in RX ring ")
> 
> Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
> ---
>   drivers/net/ethernet/lantiq_xrx200.c | 9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/lantiq_xrx200.c b/drivers/net/ethernet/lantiq_xrx200.c
> index 36dc3e5f6218..e710f83b3700 100644
> --- a/drivers/net/ethernet/lantiq_xrx200.c
> +++ b/drivers/net/ethernet/lantiq_xrx200.c
> @@ -193,17 +193,18 @@ static int xrx200_hw_receive(struct xrx200_chan *ch)
>   	int ret;
>   
>   	ret = xrx200_alloc_skb(ch);
> -
> -	ch->dma.desc++;
> -	ch->dma.desc %= LTQ_DESC_NUM;
> -
>   	if (ret) {
>   		ch->skb[ch->dma.desc] = skb;
>   		net_dev->stats.rx_dropped++;
> +		ch->dma.desc++;
> +		ch->dma.desc %= LTQ_DESC_NUM;

I would prefer if you handle this problem in the xrx200_alloc_skb() 
function.

You could also provide the skb to xrx200_alloc_skb() and use it in case 
a problem occurs, you would loose the current received packet, but the 
DMA ring stays valid.

An other solution would be to not set LTQ_DMA_OWN, then the DMA hardware 
will not use this memory, but we have to handle it somewhere else.

I am also not sure if the wmb() is needed, the desc_base was allocated 
with dma_alloc_coherent(), I assume that the changes are directly 
written to the memory and not reordered.

>   		netdev_err(net_dev, "failed to allocate new rx buffer\n");
>   		return ret;
>   	}
>   
> +	ch->dma.desc++;
> +	ch->dma.desc %= LTQ_DESC_NUM;
> +
>   	skb_put(skb, len);
>   	skb->protocol = eth_type_trans(skb, net_dev);
>   	netif_receive_skb(skb);
> 


[-- Attachment #1.1.2: OpenPGP public key --]
[-- Type: application/pgp-keys, Size: 10027 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2021-06-06 22:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-06 20:05 [PATCH net] lantiq: net: fix duplicated skb in rx descriptor ring Aleksander Jan Bajkowski
2021-06-06 22:25 ` Hauke Mehrtens [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=71b611de-5f07-677c-f253-38adb562eb72@hauke-m.de \
    --to=hauke@hauke-m.de \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=olek2@wp.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).