fb8c4e6a02375a6ef77601699311ed74a8d9e551
[openwrt/openwrt.git] / target / linux / ar71xx / patches-4.14 / 910-unaligned_access_hacks.patch
1 Index: linux-4.14.61/arch/mips/include/asm/checksum.h
2 ===================================================================
3 --- linux-4.14.61.orig/arch/mips/include/asm/checksum.h
4 +++ linux-4.14.61/arch/mips/include/asm/checksum.h
5 @@ -134,26 +134,30 @@ static inline __sum16 ip_fast_csum(const
6 const unsigned int *stop = word + ihl;
7 unsigned int csum;
8 int carry;
9 + unsigned int w;
10
11 - csum = word[0];
12 - csum += word[1];
13 - carry = (csum < word[1]);
14 + csum = net_hdr_word(word++);
15 +
16 + w = net_hdr_word(word++);
17 + csum += w;
18 + carry = (csum < w);
19 csum += carry;
20
21 - csum += word[2];
22 - carry = (csum < word[2]);
23 + w = net_hdr_word(word++);
24 + csum += w;
25 + carry = (csum < w);
26 csum += carry;
27
28 - csum += word[3];
29 - carry = (csum < word[3]);
30 + w = net_hdr_word(word++);
31 + csum += w;
32 + carry = (csum < w);
33 csum += carry;
34
35 - word += 4;
36 do {
37 - csum += *word;
38 - carry = (csum < *word);
39 + w = net_hdr_word(word++);
40 + csum += w;
41 + carry = (csum < w);
42 csum += carry;
43 - word++;
44 } while (word != stop);
45
46 return csum_fold(csum);
47 @@ -214,73 +218,6 @@ static inline __sum16 ip_compute_csum(co
48 return csum_fold(csum_partial(buff, len, 0));
49 }
50
51 -#define _HAVE_ARCH_IPV6_CSUM
52 -static __inline__ __sum16 csum_ipv6_magic(const struct in6_addr *saddr,
53 - const struct in6_addr *daddr,
54 - __u32 len, __u8 proto,
55 - __wsum sum)
56 -{
57 - __wsum tmp;
58 -
59 - __asm__(
60 - " .set push # csum_ipv6_magic\n"
61 - " .set noreorder \n"
62 - " .set noat \n"
63 - " addu %0, %5 # proto (long in network byte order)\n"
64 - " sltu $1, %0, %5 \n"
65 - " addu %0, $1 \n"
66 -
67 - " addu %0, %6 # csum\n"
68 - " sltu $1, %0, %6 \n"
69 - " lw %1, 0(%2) # four words source address\n"
70 - " addu %0, $1 \n"
71 - " addu %0, %1 \n"
72 - " sltu $1, %0, %1 \n"
73 -
74 - " lw %1, 4(%2) \n"
75 - " addu %0, $1 \n"
76 - " addu %0, %1 \n"
77 - " sltu $1, %0, %1 \n"
78 -
79 - " lw %1, 8(%2) \n"
80 - " addu %0, $1 \n"
81 - " addu %0, %1 \n"
82 - " sltu $1, %0, %1 \n"
83 -
84 - " lw %1, 12(%2) \n"
85 - " addu %0, $1 \n"
86 - " addu %0, %1 \n"
87 - " sltu $1, %0, %1 \n"
88 -
89 - " lw %1, 0(%3) \n"
90 - " addu %0, $1 \n"
91 - " addu %0, %1 \n"
92 - " sltu $1, %0, %1 \n"
93 -
94 - " lw %1, 4(%3) \n"
95 - " addu %0, $1 \n"
96 - " addu %0, %1 \n"
97 - " sltu $1, %0, %1 \n"
98 -
99 - " lw %1, 8(%3) \n"
100 - " addu %0, $1 \n"
101 - " addu %0, %1 \n"
102 - " sltu $1, %0, %1 \n"
103 -
104 - " lw %1, 12(%3) \n"
105 - " addu %0, $1 \n"
106 - " addu %0, %1 \n"
107 - " sltu $1, %0, %1 \n"
108 -
109 - " addu %0, $1 # Add final carry\n"
110 - " .set pop"
111 - : "=&r" (sum), "=&r" (tmp)
112 - : "r" (saddr), "r" (daddr),
113 - "0" (htonl(len)), "r" (htonl(proto)), "r" (sum));
114 -
115 - return csum_fold(sum);
116 -}
117 -
118 #include <asm-generic/checksum.h>
119 #endif /* CONFIG_GENERIC_CSUM */
120
121 Index: linux-4.14.61/include/uapi/linux/ip.h
122 ===================================================================
123 --- linux-4.14.61.orig/include/uapi/linux/ip.h
124 +++ linux-4.14.61/include/uapi/linux/ip.h
125 @@ -103,7 +103,7 @@ struct iphdr {
126 __be32 saddr;
127 __be32 daddr;
128 /*The options start here. */
129 -};
130 +} __attribute__((packed, aligned(2)));
131
132
133 struct ip_auth_hdr {
134 Index: linux-4.14.61/include/uapi/linux/ipv6.h
135 ===================================================================
136 --- linux-4.14.61.orig/include/uapi/linux/ipv6.h
137 +++ linux-4.14.61/include/uapi/linux/ipv6.h
138 @@ -131,7 +131,7 @@ struct ipv6hdr {
139
140 struct in6_addr saddr;
141 struct in6_addr daddr;
142 -};
143 +} __attribute__((packed, aligned(2)));
144
145
146 /* index values for the variables in ipv6_devconf */
147 Index: linux-4.14.61/include/uapi/linux/tcp.h
148 ===================================================================
149 --- linux-4.14.61.orig/include/uapi/linux/tcp.h
150 +++ linux-4.14.61/include/uapi/linux/tcp.h
151 @@ -55,7 +55,7 @@ struct tcphdr {
152 __be16 window;
153 __sum16 check;
154 __be16 urg_ptr;
155 -};
156 +} __attribute__((packed, aligned(2)));
157
158 /*
159 * The union cast uses a gcc extension to avoid aliasing problems
160 @@ -65,7 +65,7 @@ struct tcphdr {
161 union tcp_word_hdr {
162 struct tcphdr hdr;
163 __be32 words[5];
164 -};
165 +} __attribute__((packed, aligned(2)));
166
167 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
168
169 Index: linux-4.14.61/include/uapi/linux/udp.h
170 ===================================================================
171 --- linux-4.14.61.orig/include/uapi/linux/udp.h
172 +++ linux-4.14.61/include/uapi/linux/udp.h
173 @@ -25,7 +25,7 @@ struct udphdr {
174 __be16 dest;
175 __be16 len;
176 __sum16 check;
177 -};
178 +} __attribute__((packed, aligned(2)));
179
180 /* UDP socket options */
181 #define UDP_CORK 1 /* Never send partially complete segments */
182 Index: linux-4.14.61/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
183 ===================================================================
184 --- linux-4.14.61.orig/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
185 +++ linux-4.14.61/net/ipv4/netfilter/nf_conntrack_l3proto_ipv4.c
186 @@ -48,8 +48,8 @@ static bool ipv4_pkt_to_tuple(const stru
187 if (ap == NULL)
188 return false;
189
190 - tuple->src.u3.ip = ap[0];
191 - tuple->dst.u3.ip = ap[1];
192 + tuple->src.u3.ip = net_hdr_word(ap++);
193 + tuple->dst.u3.ip = net_hdr_word(ap);
194
195 return true;
196 }
197 Index: linux-4.14.61/include/uapi/linux/icmp.h
198 ===================================================================
199 --- linux-4.14.61.orig/include/uapi/linux/icmp.h
200 +++ linux-4.14.61/include/uapi/linux/icmp.h
201 @@ -82,7 +82,7 @@ struct icmphdr {
202 } frag;
203 __u8 reserved[4];
204 } un;
205 -};
206 +} __attribute__((packed, aligned(2)));
207
208
209 /*
210 Index: linux-4.14.61/include/uapi/linux/in6.h
211 ===================================================================
212 --- linux-4.14.61.orig/include/uapi/linux/in6.h
213 +++ linux-4.14.61/include/uapi/linux/in6.h
214 @@ -43,7 +43,7 @@ struct in6_addr {
215 #define s6_addr16 in6_u.u6_addr16
216 #define s6_addr32 in6_u.u6_addr32
217 #endif
218 -};
219 +} __attribute__((packed, aligned(2)));
220 #endif /* __UAPI_DEF_IN6_ADDR */
221
222 #if __UAPI_DEF_SOCKADDR_IN6
223 Index: linux-4.14.61/net/ipv6/tcp_ipv6.c
224 ===================================================================
225 --- linux-4.14.61.orig/net/ipv6/tcp_ipv6.c
226 +++ linux-4.14.61/net/ipv6/tcp_ipv6.c
227 @@ -39,6 +39,7 @@
228 #include <linux/ipsec.h>
229 #include <linux/times.h>
230 #include <linux/slab.h>
231 +#include <asm/unaligned.h>
232 #include <linux/uaccess.h>
233 #include <linux/ipv6.h>
234 #include <linux/icmpv6.h>
235 @@ -819,10 +820,10 @@ static void tcp_v6_send_response(const s
236 topt = (__be32 *)(t1 + 1);
237
238 if (tsecr) {
239 - *topt++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
240 - (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP);
241 - *topt++ = htonl(tsval);
242 - *topt++ = htonl(tsecr);
243 + put_unaligned_be32((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
244 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP, topt++);
245 + put_unaligned_be32(tsval, topt++);
246 + put_unaligned_be32(tsecr, topt++);
247 }
248
249 #ifdef CONFIG_TCP_MD5SIG
250 Index: linux-4.14.61/include/linux/ipv6.h
251 ===================================================================
252 --- linux-4.14.61.orig/include/linux/ipv6.h
253 +++ linux-4.14.61/include/linux/ipv6.h
254 @@ -6,6 +6,7 @@
255
256 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
257 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
258 +
259 /*
260 * This structure contains configuration options per IPv6 link.
261 */
262 Index: linux-4.14.61/net/ipv6/datagram.c
263 ===================================================================
264 --- linux-4.14.61.orig/net/ipv6/datagram.c
265 +++ linux-4.14.61/net/ipv6/datagram.c
266 @@ -485,7 +485,7 @@ int ipv6_recv_error(struct sock *sk, str
267 ipv6_iface_scope_id(&sin->sin6_addr,
268 IP6CB(skb)->iif);
269 } else {
270 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
271 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
272 &sin->sin6_addr);
273 sin->sin6_scope_id = 0;
274 }
275 @@ -836,12 +836,12 @@ int ip6_datagram_send_ctl(struct net *ne
276 }
277
278 if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
279 - if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
280 + if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
281 err = -EINVAL;
282 goto exit_f;
283 }
284 }
285 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
286 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
287 break;
288
289 case IPV6_2292HOPOPTS:
290 Index: linux-4.14.61/net/ipv6/ip6_gre.c
291 ===================================================================
292 --- linux-4.14.61.orig/net/ipv6/ip6_gre.c
293 +++ linux-4.14.61/net/ipv6/ip6_gre.c
294 @@ -397,7 +397,7 @@ static void ip6gre_err(struct sk_buff *s
295 return;
296 ipv6h = (const struct ipv6hdr *)skb->data;
297 greh = (const struct gre_base_hdr *)(skb->data + offset);
298 - key = key_off ? *(__be32 *)(skb->data + key_off) : 0;
299 + key = key_off ? net_hdr_word((__be32 *)(skb->data + key_off)) : 0;
300
301 t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr,
302 key, greh->protocol);
303 Index: linux-4.14.61/net/ipv6/exthdrs.c
304 ===================================================================
305 --- linux-4.14.61.orig/net/ipv6/exthdrs.c
306 +++ linux-4.14.61/net/ipv6/exthdrs.c
307 @@ -733,7 +733,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
308 goto drop;
309 }
310
311 - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
312 + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
313 if (pkt_len <= IPV6_MAXPLEN) {
314 __IP6_INC_STATS(net, ipv6_skb_idev(skb),
315 IPSTATS_MIB_INHDRERRORS);
316 Index: linux-4.14.61/include/linux/types.h
317 ===================================================================
318 --- linux-4.14.61.orig/include/linux/types.h
319 +++ linux-4.14.61/include/linux/types.h
320 @@ -229,5 +229,11 @@ struct callback_head {
321 typedef void (*rcu_callback_t)(struct rcu_head *head);
322 typedef void (*call_rcu_func_t)(struct rcu_head *head, rcu_callback_t func);
323
324 +struct net_hdr_word {
325 + u32 words[1];
326 +} __attribute__((packed, aligned(2)));
327 +
328 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
329 +
330 #endif /* __ASSEMBLY__ */
331 #endif /* _LINUX_TYPES_H */
332 Index: linux-4.14.61/net/ipv4/af_inet.c
333 ===================================================================
334 --- linux-4.14.61.orig/net/ipv4/af_inet.c
335 +++ linux-4.14.61/net/ipv4/af_inet.c
336 @@ -1351,8 +1351,8 @@ struct sk_buff **inet_gro_receive(struct
337 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
338 goto out_unlock;
339
340 - id = ntohl(*(__be32 *)&iph->id);
341 - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
342 + id = ntohl(net_hdr_word(&iph->id));
343 + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
344 id >>= 16;
345
346 for (p = *head; p; p = p->next) {
347 Index: linux-4.14.61/net/ipv4/route.c
348 ===================================================================
349 --- linux-4.14.61.orig/net/ipv4/route.c
350 +++ linux-4.14.61/net/ipv4/route.c
351 @@ -465,7 +465,7 @@ static struct neighbour *ipv4_neigh_look
352 else if (skb)
353 pkey = &ip_hdr(skb)->daddr;
354
355 - n = __ipv4_neigh_lookup(dev, *(__force u32 *)pkey);
356 + n = __ipv4_neigh_lookup(dev, net_hdr_word(pkey));
357 if (n)
358 return n;
359 return neigh_create(&arp_tbl, pkey, dev);
360 Index: linux-4.14.61/net/ipv4/tcp_output.c
361 ===================================================================
362 --- linux-4.14.61.orig/net/ipv4/tcp_output.c
363 +++ linux-4.14.61/net/ipv4/tcp_output.c
364 @@ -454,48 +454,53 @@ static void tcp_options_write(__be32 *pt
365 u16 options = opts->options; /* mungable copy */
366
367 if (unlikely(OPTION_MD5 & options)) {
368 - *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
369 - (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
370 + net_hdr_word(ptr++) =
371 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
372 + (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
373 /* overload cookie hash location */
374 opts->hash_location = (__u8 *)ptr;
375 ptr += 4;
376 }
377
378 if (unlikely(opts->mss)) {
379 - *ptr++ = htonl((TCPOPT_MSS << 24) |
380 - (TCPOLEN_MSS << 16) |
381 - opts->mss);
382 + net_hdr_word(ptr++) =
383 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
384 + opts->mss);
385 }
386
387 if (likely(OPTION_TS & options)) {
388 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
389 - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
390 - (TCPOLEN_SACK_PERM << 16) |
391 - (TCPOPT_TIMESTAMP << 8) |
392 - TCPOLEN_TIMESTAMP);
393 + net_hdr_word(ptr++) =
394 + htonl((TCPOPT_SACK_PERM << 24) |
395 + (TCPOLEN_SACK_PERM << 16) |
396 + (TCPOPT_TIMESTAMP << 8) |
397 + TCPOLEN_TIMESTAMP);
398 options &= ~OPTION_SACK_ADVERTISE;
399 } else {
400 - *ptr++ = htonl((TCPOPT_NOP << 24) |
401 - (TCPOPT_NOP << 16) |
402 - (TCPOPT_TIMESTAMP << 8) |
403 - TCPOLEN_TIMESTAMP);
404 + net_hdr_word(ptr++) =
405 + htonl((TCPOPT_NOP << 24) |
406 + (TCPOPT_NOP << 16) |
407 + (TCPOPT_TIMESTAMP << 8) |
408 + TCPOLEN_TIMESTAMP);
409 }
410 - *ptr++ = htonl(opts->tsval);
411 - *ptr++ = htonl(opts->tsecr);
412 + net_hdr_word(ptr++) = htonl(opts->tsval);
413 + net_hdr_word(ptr++) = htonl(opts->tsecr);
414 }
415
416 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
417 - *ptr++ = htonl((TCPOPT_NOP << 24) |
418 - (TCPOPT_NOP << 16) |
419 - (TCPOPT_SACK_PERM << 8) |
420 - TCPOLEN_SACK_PERM);
421 + net_hdr_word(ptr++) =
422 + htonl((TCPOPT_NOP << 24) |
423 + (TCPOPT_NOP << 16) |
424 + (TCPOPT_SACK_PERM << 8) |
425 + TCPOLEN_SACK_PERM);
426 }
427
428 if (unlikely(OPTION_WSCALE & options)) {
429 - *ptr++ = htonl((TCPOPT_NOP << 24) |
430 - (TCPOPT_WINDOW << 16) |
431 - (TCPOLEN_WINDOW << 8) |
432 - opts->ws);
433 + net_hdr_word(ptr++) =
434 + htonl((TCPOPT_NOP << 24) |
435 + (TCPOPT_WINDOW << 16) |
436 + (TCPOLEN_WINDOW << 8) |
437 + opts->ws);
438 }
439
440 if (unlikely(opts->num_sack_blocks)) {
441 @@ -503,16 +508,17 @@ static void tcp_options_write(__be32 *pt
442 tp->duplicate_sack : tp->selective_acks;
443 int this_sack;
444
445 - *ptr++ = htonl((TCPOPT_NOP << 24) |
446 - (TCPOPT_NOP << 16) |
447 - (TCPOPT_SACK << 8) |
448 - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
449 + net_hdr_word(ptr++) =
450 + htonl((TCPOPT_NOP << 24) |
451 + (TCPOPT_NOP << 16) |
452 + (TCPOPT_SACK << 8) |
453 + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
454 TCPOLEN_SACK_PERBLOCK)));
455
456 for (this_sack = 0; this_sack < opts->num_sack_blocks;
457 ++this_sack) {
458 - *ptr++ = htonl(sp[this_sack].start_seq);
459 - *ptr++ = htonl(sp[this_sack].end_seq);
460 + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
461 + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
462 }
463
464 tp->rx_opt.dsack = 0;
465 @@ -525,13 +531,14 @@ static void tcp_options_write(__be32 *pt
466
467 if (foc->exp) {
468 len = TCPOLEN_EXP_FASTOPEN_BASE + foc->len;
469 - *ptr = htonl((TCPOPT_EXP << 24) | (len << 16) |
470 + net_hdr_word(ptr) =
471 + htonl((TCPOPT_EXP << 24) | (len << 16) |
472 TCPOPT_FASTOPEN_MAGIC);
473 p += TCPOLEN_EXP_FASTOPEN_BASE;
474 } else {
475 len = TCPOLEN_FASTOPEN_BASE + foc->len;
476 - *p++ = TCPOPT_FASTOPEN;
477 - *p++ = len;
478 + net_hdr_word(p++) = TCPOPT_FASTOPEN;
479 + net_hdr_word(p++) = len;
480 }
481
482 memcpy(p, foc->val, foc->len);
483 Index: linux-4.14.61/net/ipv4/igmp.c
484 ===================================================================
485 --- linux-4.14.61.orig/net/ipv4/igmp.c
486 +++ linux-4.14.61/net/ipv4/igmp.c
487 @@ -537,7 +537,7 @@ static struct sk_buff *add_grec(struct s
488 if (!skb)
489 return NULL;
490 psrc = skb_put(skb, sizeof(__be32));
491 - *psrc = psf->sf_inaddr;
492 + net_hdr_word(psrc) = psf->sf_inaddr;
493 scount++; stotal++;
494 if ((type == IGMPV3_ALLOW_NEW_SOURCES ||
495 type == IGMPV3_BLOCK_OLD_SOURCES) && psf->sf_crcount) {
496 Index: linux-4.14.61/include/uapi/linux/igmp.h
497 ===================================================================
498 --- linux-4.14.61.orig/include/uapi/linux/igmp.h
499 +++ linux-4.14.61/include/uapi/linux/igmp.h
500 @@ -33,7 +33,7 @@ struct igmphdr {
501 __u8 code; /* For newer IGMP */
502 __sum16 csum;
503 __be32 group;
504 -};
505 +} __attribute__((packed, aligned(2)));
506
507 /* V3 group record types [grec_type] */
508 #define IGMPV3_MODE_IS_INCLUDE 1
509 @@ -49,7 +49,7 @@ struct igmpv3_grec {
510 __be16 grec_nsrcs;
511 __be32 grec_mca;
512 __be32 grec_src[0];
513 -};
514 +} __attribute__((packed, aligned(2)));
515
516 struct igmpv3_report {
517 __u8 type;
518 @@ -58,7 +58,7 @@ struct igmpv3_report {
519 __be16 resv2;
520 __be16 ngrec;
521 struct igmpv3_grec grec[0];
522 -};
523 +} __attribute__((packed, aligned(2)));
524
525 struct igmpv3_query {
526 __u8 type;
527 @@ -79,7 +79,7 @@ struct igmpv3_query {
528 __u8 qqic;
529 __be16 nsrcs;
530 __be32 srcs[0];
531 -};
532 +} __attribute__((packed, aligned(2)));
533
534 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
535 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
536 Index: linux-4.14.61/net/core/flow_dissector.c
537 ===================================================================
538 --- linux-4.14.61.orig/net/core/flow_dissector.c
539 +++ linux-4.14.61/net/core/flow_dissector.c
540 @@ -108,7 +108,7 @@ __be32 __skb_flow_get_ports(const struct
541 ports = __skb_header_pointer(skb, thoff + poff,
542 sizeof(_ports), data, hlen, &_ports);
543 if (ports)
544 - return *ports;
545 + return (__be32)net_hdr_word(ports);
546 }
547
548 return 0;
549 Index: linux-4.14.61/include/uapi/linux/icmpv6.h
550 ===================================================================
551 --- linux-4.14.61.orig/include/uapi/linux/icmpv6.h
552 +++ linux-4.14.61/include/uapi/linux/icmpv6.h
553 @@ -77,7 +77,7 @@ struct icmp6hdr {
554 #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
555 #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
556 #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
557 -};
558 +} __attribute__((packed, aligned(2)));
559
560
561 #define ICMPV6_ROUTER_PREF_LOW 0x3
562 Index: linux-4.14.61/include/net/ndisc.h
563 ===================================================================
564 --- linux-4.14.61.orig/include/net/ndisc.h
565 +++ linux-4.14.61/include/net/ndisc.h
566 @@ -89,7 +89,7 @@ struct ra_msg {
567 struct icmp6hdr icmph;
568 __be32 reachable_time;
569 __be32 retrans_timer;
570 -};
571 +} __attribute__((packed, aligned(2)));
572
573 struct rd_msg {
574 struct icmp6hdr icmph;
575 @@ -368,10 +368,10 @@ static inline u32 ndisc_hashfn(const voi
576 {
577 const u32 *p32 = pkey;
578
579 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
580 - (p32[1] * hash_rnd[1]) +
581 - (p32[2] * hash_rnd[2]) +
582 - (p32[3] * hash_rnd[3]));
583 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
584 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
585 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
586 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
587 }
588
589 static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
590 Index: linux-4.14.61/net/sched/cls_u32.c
591 ===================================================================
592 --- linux-4.14.61.orig/net/sched/cls_u32.c
593 +++ linux-4.14.61/net/sched/cls_u32.c
594 @@ -165,7 +165,7 @@ next_knode:
595 data = skb_header_pointer(skb, toff, 4, &hdata);
596 if (!data)
597 goto out;
598 - if ((*data ^ key->val) & key->mask) {
599 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
600 n = rcu_dereference_bh(n->next);
601 goto next_knode;
602 }
603 @@ -218,8 +218,8 @@ check_terminal:
604 &hdata);
605 if (!data)
606 goto out;
607 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
608 - n->fshift);
609 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
610 + &n->sel, n->fshift);
611 }
612 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
613 goto next_ht;
614 Index: linux-4.14.61/net/ipv6/ip6_offload.c
615 ===================================================================
616 --- linux-4.14.61.orig/net/ipv6/ip6_offload.c
617 +++ linux-4.14.61/net/ipv6/ip6_offload.c
618 @@ -220,7 +220,7 @@ static struct sk_buff **ipv6_gro_receive
619 continue;
620
621 iph2 = (struct ipv6hdr *)(p->data + off);
622 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
623 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
624
625 /* All fields must match except length and Traffic Class.
626 * XXX skbs on the gro_list have all been parsed and pulled
627 Index: linux-4.14.61/include/net/addrconf.h
628 ===================================================================
629 --- linux-4.14.61.orig/include/net/addrconf.h
630 +++ linux-4.14.61/include/net/addrconf.h
631 @@ -47,7 +47,7 @@ struct prefix_info {
632 __be32 reserved2;
633
634 struct in6_addr prefix;
635 -};
636 +} __attribute__((packed, aligned(2)));
637
638 #include <linux/netdevice.h>
639 #include <net/if_inet6.h>
640 Index: linux-4.14.61/include/net/inet_ecn.h
641 ===================================================================
642 --- linux-4.14.61.orig/include/net/inet_ecn.h
643 +++ linux-4.14.61/include/net/inet_ecn.h
644 @@ -125,9 +125,9 @@ static inline int IP6_ECN_set_ce(struct
645 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
646 return 0;
647
648 - from = *(__be32 *)iph;
649 + from = net_hdr_word(iph);
650 to = from | htonl(INET_ECN_CE << 20);
651 - *(__be32 *)iph = to;
652 + net_hdr_word(iph) = to;
653 if (skb->ip_summed == CHECKSUM_COMPLETE)
654 skb->csum = csum_add(csum_sub(skb->csum, (__force __wsum)from),
655 (__force __wsum)to);
656 @@ -136,7 +136,7 @@ static inline int IP6_ECN_set_ce(struct
657
658 static inline void IP6_ECN_clear(struct ipv6hdr *iph)
659 {
660 - *(__be32*)iph &= ~htonl(INET_ECN_MASK << 20);
661 + net_hdr_word(iph) &= ~htonl(INET_ECN_MASK << 20);
662 }
663
664 static inline void ipv6_copy_dscp(unsigned int dscp, struct ipv6hdr *inner)
665 Index: linux-4.14.61/include/net/ipv6.h
666 ===================================================================
667 --- linux-4.14.61.orig/include/net/ipv6.h
668 +++ linux-4.14.61/include/net/ipv6.h
669 @@ -108,7 +108,7 @@ struct frag_hdr {
670 __u8 reserved;
671 __be16 frag_off;
672 __be32 identification;
673 -};
674 +} __attribute__((packed, aligned(2)));
675
676 #define IP6_MF 0x0001
677 #define IP6_OFFSET 0xFFF8
678 @@ -451,8 +451,8 @@ static inline void __ipv6_addr_set_half(
679 }
680 #endif
681 #endif
682 - addr[0] = wh;
683 - addr[1] = wl;
684 + net_hdr_word(&addr[0]) = wh;
685 + net_hdr_word(&addr[1]) = wl;
686 }
687
688 static inline void ipv6_addr_set(struct in6_addr *addr,
689 @@ -511,6 +511,8 @@ static inline bool ipv6_prefix_equal(con
690 const __be32 *a1 = addr1->s6_addr32;
691 const __be32 *a2 = addr2->s6_addr32;
692 unsigned int pdw, pbi;
693 + /* Used for last <32-bit fraction of prefix */
694 + u32 pbia1, pbia2;
695
696 /* check complete u32 in prefix */
697 pdw = prefixlen >> 5;
698 @@ -519,7 +521,9 @@ static inline bool ipv6_prefix_equal(con
699
700 /* check incomplete u32 in prefix */
701 pbi = prefixlen & 0x1f;
702 - if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
703 + pbia1 = net_hdr_word(&a1[pdw]);
704 + pbia2 = net_hdr_word(&a2[pdw]);
705 + if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
706 return false;
707
708 return true;
709 @@ -663,13 +667,13 @@ static inline void ipv6_addr_set_v4mappe
710 */
711 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
712 {
713 - const __be32 *a1 = token1, *a2 = token2;
714 + const struct in6_addr *a1 = token1, *a2 = token2;
715 int i;
716
717 addrlen >>= 2;
718
719 for (i = 0; i < addrlen; i++) {
720 - __be32 xb = a1[i] ^ a2[i];
721 + __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
722 if (xb)
723 return i * 32 + 31 - __fls(ntohl(xb));
724 }
725 @@ -838,17 +842,18 @@ static inline int ip6_default_np_autolab
726 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
727 __be32 flowlabel)
728 {
729 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
730 + net_hdr_word((__be32 *)hdr) =
731 + htonl(0x60000000 | (tclass << 20)) | flowlabel;
732 }
733
734 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
735 {
736 - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
737 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
738 }
739
740 static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
741 {
742 - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
743 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
744 }
745
746 static inline u8 ip6_tclass(__be32 flowinfo)
747 Index: linux-4.14.61/include/net/secure_seq.h
748 ===================================================================
749 --- linux-4.14.61.orig/include/net/secure_seq.h
750 +++ linux-4.14.61/include/net/secure_seq.h
751 @@ -3,6 +3,7 @@
752 #define _NET_SECURE_SEQ
753
754 #include <linux/types.h>
755 +#include <linux/in6.h>
756
757 u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
758 u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
759 Index: linux-4.14.61/include/uapi/linux/in.h
760 ===================================================================
761 --- linux-4.14.61.orig/include/uapi/linux/in.h
762 +++ linux-4.14.61/include/uapi/linux/in.h
763 @@ -84,7 +84,7 @@ enum {
764 /* Internet address. */
765 struct in_addr {
766 __be32 s_addr;
767 -};
768 +} __attribute__((packed, aligned(2)));
769 #endif
770
771 #define IP_TOS 1
772 Index: linux-4.14.61/net/ipv6/ip6_fib.c
773 ===================================================================
774 --- linux-4.14.61.orig/net/ipv6/ip6_fib.c
775 +++ linux-4.14.61/net/ipv6/ip6_fib.c
776 @@ -137,7 +137,7 @@ static __be32 addr_bit_set(const void *t
777 * See include/asm-generic/bitops/le.h.
778 */
779 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
780 - addr[fn_bit >> 5];
781 + net_hdr_word(&addr[fn_bit >> 5]);
782 }
783
784 static struct fib6_node *node_alloc(void)
785 Index: linux-4.14.61/net/netfilter/nf_conntrack_proto_tcp.c
786 ===================================================================
787 --- linux-4.14.61.orig/net/netfilter/nf_conntrack_proto_tcp.c
788 +++ linux-4.14.61/net/netfilter/nf_conntrack_proto_tcp.c
789 @@ -447,7 +447,7 @@ static void tcp_sack(const struct sk_buf
790
791 /* Fast path for timestamp-only option */
792 if (length == TCPOLEN_TSTAMP_ALIGNED
793 - && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
794 + && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
795 | (TCPOPT_NOP << 16)
796 | (TCPOPT_TIMESTAMP << 8)
797 | TCPOLEN_TIMESTAMP))
798 Index: linux-4.14.61/net/xfrm/xfrm_input.c
799 ===================================================================
800 --- linux-4.14.61.orig/net/xfrm/xfrm_input.c
801 +++ linux-4.14.61/net/xfrm/xfrm_input.c
802 @@ -193,8 +193,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
803 if (!pskb_may_pull(skb, hlen))
804 return -EINVAL;
805
806 - *spi = *(__be32 *)(skb_transport_header(skb) + offset);
807 - *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
808 + *spi = net_hdr_word(skb_transport_header(skb) + offset);
809 + *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
810 return 0;
811 }
812 EXPORT_SYMBOL(xfrm_parse_spi);
813 Index: linux-4.14.61/net/ipv4/tcp_input.c
814 ===================================================================
815 --- linux-4.14.61.orig/net/ipv4/tcp_input.c
816 +++ linux-4.14.61/net/ipv4/tcp_input.c
817 @@ -3858,14 +3858,16 @@ static bool tcp_parse_aligned_timestamp(
818 {
819 const __be32 *ptr = (const __be32 *)(th + 1);
820
821 - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
822 - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
823 + if (net_hdr_word(ptr) ==
824 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
825 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
826 tp->rx_opt.saw_tstamp = 1;
827 ++ptr;
828 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
829 + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
830 ++ptr;
831 - if (*ptr)
832 - tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
833 + if (net_hdr_word(ptr))
834 + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
835 + tp->tsoffset;
836 else
837 tp->rx_opt.rcv_tsecr = 0;
838 return true;
839 Index: linux-4.14.61/include/uapi/linux/if_pppox.h
840 ===================================================================
841 --- linux-4.14.61.orig/include/uapi/linux/if_pppox.h
842 +++ linux-4.14.61/include/uapi/linux/if_pppox.h
843 @@ -51,6 +51,7 @@ struct pppoe_addr {
844 */
845 struct pptp_addr {
846 __u16 call_id;
847 + __u16 pad;
848 struct in_addr sin_addr;
849 };
850
851 Index: linux-4.14.61/net/ipv6/netfilter/nf_log_ipv6.c
852 ===================================================================
853 --- linux-4.14.61.orig/net/ipv6/netfilter/nf_log_ipv6.c
854 +++ linux-4.14.61/net/ipv6/netfilter/nf_log_ipv6.c
855 @@ -66,9 +66,9 @@ static void dump_ipv6_packet(struct nf_l
856 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
857 nf_log_buf_add(m, "LEN=%zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
858 ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
859 - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
860 + (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
861 ih->hop_limit,
862 - (ntohl(*(__be32 *)ih) & 0x000fffff));
863 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
864
865 fragment = 0;
866 ptr = ip6hoff + sizeof(struct ipv6hdr);
867 Index: linux-4.14.61/include/net/neighbour.h
868 ===================================================================
869 --- linux-4.14.61.orig/include/net/neighbour.h
870 +++ linux-4.14.61/include/net/neighbour.h
871 @@ -265,8 +265,10 @@ static inline bool neigh_key_eq128(const
872 const u32 *n32 = (const u32 *)n->primary_key;
873 const u32 *p32 = pkey;
874
875 - return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
876 - (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
877 + return ((n32[0] ^ net_hdr_word(&p32[0])) |
878 + (n32[1] ^ net_hdr_word(&p32[1])) |
879 + (n32[2] ^ net_hdr_word(&p32[2])) |
880 + (n32[3] ^ net_hdr_word(&p32[3]))) == 0;
881 }
882
883 static inline struct neighbour *___neigh_lookup_noref(
884 Index: linux-4.14.61/include/uapi/linux/netfilter_arp/arp_tables.h
885 ===================================================================
886 --- linux-4.14.61.orig/include/uapi/linux/netfilter_arp/arp_tables.h
887 +++ linux-4.14.61/include/uapi/linux/netfilter_arp/arp_tables.h
888 @@ -70,7 +70,7 @@ struct arpt_arp {
889 __u8 flags;
890 /* Inverse flags */
891 __u16 invflags;
892 -};
893 +} __attribute__((aligned(4)));
894
895 /* Values for "flag" field in struct arpt_ip (general arp structure).
896 * No flags defined yet.
897 Index: linux-4.14.61/net/core/utils.c
898 ===================================================================
899 --- linux-4.14.61.orig/net/core/utils.c
900 +++ linux-4.14.61/net/core/utils.c
901 @@ -424,8 +424,14 @@ void inet_proto_csum_replace16(__sum16 *
902 bool pseudohdr)
903 {
904 __be32 diff[] = {
905 - ~from[0], ~from[1], ~from[2], ~from[3],
906 - to[0], to[1], to[2], to[3],
907 + ~net_hdr_word(&from[0]),
908 + ~net_hdr_word(&from[1]),
909 + ~net_hdr_word(&from[2]),
910 + ~net_hdr_word(&from[3]),
911 + net_hdr_word(&to[0]),
912 + net_hdr_word(&to[1]),
913 + net_hdr_word(&to[2]),
914 + net_hdr_word(&to[3]),
915 };
916 if (skb->ip_summed != CHECKSUM_PARTIAL) {
917 *sum = csum_fold(csum_partial(diff, sizeof(diff),
918 Index: linux-4.14.61/drivers/net/vxlan.c
919 ===================================================================
920 --- linux-4.14.61.orig/drivers/net/vxlan.c
921 +++ linux-4.14.61/drivers/net/vxlan.c
922 @@ -1857,15 +1857,15 @@ static int vxlan_build_skb(struct sk_buf
923 return err;
924
925 vxh = __skb_push(skb, sizeof(*vxh));
926 - vxh->vx_flags = VXLAN_HF_VNI;
927 - vxh->vx_vni = vxlan_vni_field(vni);
928 + net_hdr_word(&vxh->vx_flags) = VXLAN_HF_VNI;
929 + net_hdr_word(&vxh->vx_vni) = vxlan_vni_field(vni);
930
931 if (type & SKB_GSO_TUNNEL_REMCSUM) {
932 unsigned int start;
933
934 start = skb_checksum_start_offset(skb) - sizeof(struct vxlanhdr);
935 - vxh->vx_vni |= vxlan_compute_rco(start, skb->csum_offset);
936 - vxh->vx_flags |= VXLAN_HF_RCO;
937 + net_hdr_word(&vxh->vx_vni) |= vxlan_compute_rco(start, skb->csum_offset);
938 + net_hdr_word(&vxh->vx_flags) |= VXLAN_HF_RCO;
939
940 if (!skb_is_gso(skb)) {
941 skb->ip_summed = CHECKSUM_NONE;
942 Index: linux-4.14.61/include/linux/etherdevice.h
943 ===================================================================
944 --- linux-4.14.61.orig/include/linux/etherdevice.h
945 +++ linux-4.14.61/include/linux/etherdevice.h
946 @@ -480,7 +480,7 @@ static inline bool is_etherdev_addr(cons
947 * @b: Pointer to Ethernet header
948 *
949 * Compare two Ethernet headers, returns 0 if equal.
950 - * This assumes that the network header (i.e., IP header) is 4-byte
951 + * This assumes that the network header (i.e., IP header) is 2-byte
952 * aligned OR the platform can handle unaligned access. This is the
953 * case for all packets coming into netif_receive_skb or similar
954 * entry points.
955 @@ -503,11 +503,12 @@ static inline unsigned long compare_ethe
956 fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
957 return fold;
958 #else
959 - u32 *a32 = (u32 *)((u8 *)a + 2);
960 - u32 *b32 = (u32 *)((u8 *)b + 2);
961 + const u16 *a16 = a;
962 + const u16 *b16 = b;
963
964 - return (*(u16 *)a ^ *(u16 *)b) | (a32[0] ^ b32[0]) |
965 - (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);
966 + return (a16[0] ^ b16[0]) | (a16[1] ^ b16[1]) | (a16[2] ^ b16[2]) |
967 + (a16[3] ^ b16[3]) | (a16[4] ^ b16[4]) | (a16[5] ^ b16[5]) |
968 + (a16[6] ^ b16[6]);
969 #endif
970 }
971
972 Index: linux-4.14.61/net/ipv4/tcp_offload.c
973 ===================================================================
974 --- linux-4.14.61.orig/net/ipv4/tcp_offload.c
975 +++ linux-4.14.61/net/ipv4/tcp_offload.c
976 @@ -226,7 +226,7 @@ struct sk_buff **tcp_gro_receive(struct
977
978 th2 = tcp_hdr(p);
979
980 - if (*(u32 *)&th->source ^ *(u32 *)&th2->source) {
981 + if (net_hdr_word(&th->source) ^ net_hdr_word(&th2->source)) {
982 NAPI_GRO_CB(p)->same_flow = 0;
983 continue;
984 }
985 @@ -244,8 +244,8 @@ found:
986 ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH));
987 flush |= (__force int)(th->ack_seq ^ th2->ack_seq);
988 for (i = sizeof(*th); i < thlen; i += 4)
989 - flush |= *(u32 *)((u8 *)th + i) ^
990 - *(u32 *)((u8 *)th2 + i);
991 + flush |= net_hdr_word((u8 *)th + i) ^
992 + net_hdr_word((u8 *)th2 + i);
993
994 /* When we receive our second frame we can made a decision on if we
995 * continue this flow as an atomic flow with a fixed ID or if we use
996 Index: linux-4.14.61/net/ipv6/netfilter/ip6table_mangle.c
997 ===================================================================
998 --- linux-4.14.61.orig/net/ipv6/netfilter/ip6table_mangle.c
999 +++ linux-4.14.61/net/ipv6/netfilter/ip6table_mangle.c
1000 @@ -50,7 +50,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
1001 hop_limit = ipv6_hdr(skb)->hop_limit;
1002
1003 /* flowlabel and prio (includes version, which shouldn't change either */
1004 - flowlabel = *((u_int32_t *)ipv6_hdr(skb));
1005 + flowlabel = net_hdr_word(ipv6_hdr(skb));
1006
1007 ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
1008
1009 @@ -59,7 +59,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
1010 !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
1011 skb->mark != mark ||
1012 ipv6_hdr(skb)->hop_limit != hop_limit ||
1013 - flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) {
1014 + flowlabel != net_hdr_word(ipv6_hdr(skb)))) {
1015 err = ip6_route_me_harder(state->net, skb);
1016 if (err < 0)
1017 ret = NF_DROP_ERR(err);