netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
To: netdev@vger.kernel.org
Cc: Woojung Huh <woojung.huh@microchip.com>,
	Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>
Subject: [PATCH] lan78xx: fix ip header misalignment
Date: Mon, 21 Jan 2019 15:48:11 +0300	[thread overview]
Message-ID: <53800bc3-397a-ed1a-958d-a1dbc887d249@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1315 bytes --]

lan78xx.c:rx_submit() allocates space for frame-to-be-received with 
netdev_alloc_skb_ip_align(), which misalign start of buffer by 2 bytes 
in expectation that frame will start from 14-byte ethernet header, then 
ip header; if start of buffer misaligned by 2 bytes, ip header will be 
16-byte aligned.

Unfortunately, usb frame that is sent by lan78xx starts with another 
10-byte header (lan78xx_rx(): rx_cmd_a/rx_cmd_b/rx_cmd_c), *then* 
follows ethernet header, and *then* ip header (which ends up being 
misaligned).

This issue was observed on arm platform (where misaligned 32-bit word 
access triggers exception and leaves traces in /proc/cpu/alignment, see
https://github.com/raspberrypi/linux/issues/2599 ; for me, about any 
ipv6 traffic that hits machine - `ping -I eth0 ip6-allnodes`, tcp/udp 
packets, etc triggered increase in this counter, with 
ip6_datagram_recv_common_ctl, icmpv6_echo_reply, etc as culprit).

If we just allocate skb data without any misalignment tricks, ip header 
will end up and at offset 24 (8-byte aligned).

Patch attached; runtime-tested with raspbian fork of stable/4.14.y 
[4.14.92] on Raspberry pi 3B+ (it is slightly different from mainline, 
but patch should not have any conflicts, all affected code is pretty same).

P.S. I'm not subscribed, please CC me on reply.

[-- Attachment #2: 0001-lan78xx-fix-ip-header-misalignment.patch --]
[-- Type: text/x-patch, Size: 991 bytes --]

From 2bd6b0a11e222be2df97da948924c71bf13d7192 Mon Sep 17 00:00:00 2001
From: "Yuriy M. Kaminskiy" <yumkam@gmail.com>
Date: Mon, 21 Jan 2019 02:51:24 +0300
Subject: [PATCH] lan78xx: fix ip header misalignment

As lan78xx prepends 10-byte header before ether_hdr, skb->data
misalignment trick by netdev_alloc_skb_ip_align() made things
worse (ip_hdr becomes always misaligned).

See https://github.com/raspberrypi/linux/issues/2599
---
 drivers/net/usb/lan78xx.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 9b782cdf8..d64b0d3b8 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -3143,7 +3143,7 @@ static int rx_submit(struct lan78xx_net *dev, struct urb *urb, gfp_t flags)
 	size_t size = dev->rx_urb_size;
 	int ret = 0;
 
-	skb = netdev_alloc_skb_ip_align(dev->net, size);
+	skb = netdev_alloc_skb(dev->net, size);
 	if (!skb) {
 		usb_free_urb(urb);
 		return -ENOMEM;
-- 
2.11.0



             reply	other threads:[~2019-01-21 12:48 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-21 12:48 Yuriy M. Kaminskiy [this message]
2019-01-27 13:14 ` [PATCH] lan78xx: fix ip header misalignment RaghuramChary.Jallipalli
     [not found] <f770ea9d-645f-e9f3-5b02-8b913f6e3c9c@gmail.com>
2019-01-21 13:36 ` Yuriy M. Kaminskiy

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=53800bc3-397a-ed1a-958d-a1dbc887d249@gmail.com \
    --to=yumkam@gmail.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=woojung.huh@microchip.com \
    /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).