• Aaro Koskinen's avatar
    net: stmmac: fix memory corruption with large MTUs · 8dcf078d
    Aaro Koskinen authored
    [ Upstream commit 223a960c ]
    
    When using 16K DMA buffers and ring mode, the DES3 refill is not working
    correctly as the function is using a bogus pointer for checking the
    private data. As a result stale pointers will remain in the RX descriptor
    ring, so DMA will now likely overwrite/corrupt some already freed memory.
    
    As simple reproducer, just receive some UDP traffic:
    
    	# ifconfig eth0 down; ifconfig eth0 mtu 9000; ifconfig eth0 up
    	# iperf3 -c 192.168.253.40 -u -b 0 -R
    
    If you didn't crash by now check the RX descriptors to find non-contiguous
    RX buffers:
    
    	cat /sys/kernel/debug/stmmaceth/eth0/descriptors_status
    	[...]
    	1 [0x2be5020]: 0xa3220321 0x9ffc1ffc 0x72d70082 0x130e207e
    					     ^^^^^^^^^^^^^^^^^^^^^
    	2 [0x2be5040]: 0xa3220321 0x9ffc1ffc 0x72998082 0x1311a07e
    					     ^^^^^^^^^^^^^^^^^^^^^
    
    A simple ping test will now report bad data:
    
    	# ping -s 8200 192.168.253.40
    	PING 192.168.253.40 (192.168.253.40) 8200(8228) bytes of data.
    	8208 bytes from 192.168.253.40: icmp_seq=1 ttl=64 time=1.00 ms
    	wrong data byte #8144 should be 0xd0 but was 0x88
    
    Fix the wrong pointer. Also we must refill DES3 only if the DMA buffer
    size is 16K.
    
    Fixes: 54139cf3 ("net: stmmac: adding multiple buffers for rx")
    Signed-off-by: default avatarAaro Koskinen <aaro.koskinen@nokia.com>
    Acked-by: default avatarJose Abreu <joabreu@synopsys.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    8dcf078d
ring_mode.c 4.54 KB