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