05fe0c7b205960201d977747ee5a654f4448ca36
[openwrt/staging/dedeckeh.git] / target / linux / ath79 / patches-5.10 / 910-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 @@ -180,73 +184,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 @@ -271,8 +271,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 @@ -83,7 +83,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 @@ -927,10 +928,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 #ifdef CONFIG_TCP_MD5SIG
276 --- a/net/ipv6/datagram.c
277 +++ b/net/ipv6/datagram.c
278 @@ -492,7 +492,7 @@ int ipv6_recv_error(struct sock *sk, str
279 ipv6_iface_scope_id(&sin->sin6_addr,
280 IP6CB(skb)->iif);
281 } else {
282 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
283 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
284 &sin->sin6_addr);
285 sin->sin6_scope_id = 0;
286 }
287 @@ -846,12 +846,12 @@ int ip6_datagram_send_ctl(struct net *ne
288 }
289
290 if (fl6->flowlabel&IPV6_FLOWINFO_MASK) {
291 - if ((fl6->flowlabel^*(__be32 *)CMSG_DATA(cmsg))&~IPV6_FLOWINFO_MASK) {
292 + if ((fl6->flowlabel^net_hdr_word(CMSG_DATA(cmsg)))&~IPV6_FLOWINFO_MASK) {
293 err = -EINVAL;
294 goto exit_f;
295 }
296 }
297 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
298 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
299 break;
300
301 case IPV6_2292HOPOPTS:
302 --- a/net/ipv6/exthdrs.c
303 +++ b/net/ipv6/exthdrs.c
304 @@ -948,7 +948,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
305 goto drop;
306 }
307
308 - pkt_len = ntohl(*(__be32 *)(nh + optoff + 2));
309 + pkt_len = ntohl(net_hdr_word(nh + optoff + 2));
310 if (pkt_len <= IPV6_MAXPLEN) {
311 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
312 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2);
313 --- a/include/linux/types.h
314 +++ b/include/linux/types.h
315 @@ -227,5 +227,11 @@ typedef void (*swap_func_t)(void *a, voi
316 typedef int (*cmp_r_func_t)(const void *a, const void *b, const void *priv);
317 typedef int (*cmp_func_t)(const void *a, const void *b);
318
319 +struct net_hdr_word {
320 + u32 words[1];
321 +} __attribute__((packed, aligned(2)));
322 +
323 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
324 +
325 #endif /* __ASSEMBLY__ */
326 #endif /* _LINUX_TYPES_H */
327 --- a/net/ipv4/af_inet.c
328 +++ b/net/ipv4/af_inet.c
329 @@ -1469,8 +1469,8 @@ struct sk_buff *inet_gro_receive(struct
330 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
331 goto out_unlock;
332
333 - id = ntohl(*(__be32 *)&iph->id);
334 - flush = (u16)((ntohl(*(__be32 *)iph) ^ skb_gro_len(skb)) | (id & ~IP_DF));
335 + id = ntohl(net_hdr_word(&iph->id));
336 + flush = (u16)((ntohl(net_hdr_word(iph)) ^ skb_gro_len(skb)) | (id & ~IP_DF));
337 id >>= 16;
338
339 list_for_each_entry(p, head, list) {
340 --- a/net/ipv4/tcp_output.c
341 +++ b/net/ipv4/tcp_output.c
342 @@ -609,48 +609,53 @@ static void tcp_options_write(__be32 *pt
343 u16 options = opts->options; /* mungable copy */
344
345 if (unlikely(OPTION_MD5 & options)) {
346 - *ptr++ = htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
347 - (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
348 + net_hdr_word(ptr++) =
349 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
350 + (TCPOPT_MD5SIG << 8) | TCPOLEN_MD5SIG);
351 /* overload cookie hash location */
352 opts->hash_location = (__u8 *)ptr;
353 ptr += 4;
354 }
355
356 if (unlikely(opts->mss)) {
357 - *ptr++ = htonl((TCPOPT_MSS << 24) |
358 - (TCPOLEN_MSS << 16) |
359 - opts->mss);
360 + net_hdr_word(ptr++) =
361 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
362 + opts->mss);
363 }
364
365 if (likely(OPTION_TS & options)) {
366 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
367 - *ptr++ = htonl((TCPOPT_SACK_PERM << 24) |
368 - (TCPOLEN_SACK_PERM << 16) |
369 - (TCPOPT_TIMESTAMP << 8) |
370 - TCPOLEN_TIMESTAMP);
371 + net_hdr_word(ptr++) =
372 + htonl((TCPOPT_SACK_PERM << 24) |
373 + (TCPOLEN_SACK_PERM << 16) |
374 + (TCPOPT_TIMESTAMP << 8) |
375 + TCPOLEN_TIMESTAMP);
376 options &= ~OPTION_SACK_ADVERTISE;
377 } else {
378 - *ptr++ = htonl((TCPOPT_NOP << 24) |
379 - (TCPOPT_NOP << 16) |
380 - (TCPOPT_TIMESTAMP << 8) |
381 - TCPOLEN_TIMESTAMP);
382 + net_hdr_word(ptr++) =
383 + htonl((TCPOPT_NOP << 24) |
384 + (TCPOPT_NOP << 16) |
385 + (TCPOPT_TIMESTAMP << 8) |
386 + TCPOLEN_TIMESTAMP);
387 }
388 - *ptr++ = htonl(opts->tsval);
389 - *ptr++ = htonl(opts->tsecr);
390 + net_hdr_word(ptr++) = htonl(opts->tsval);
391 + net_hdr_word(ptr++) = htonl(opts->tsecr);
392 }
393
394 if (unlikely(OPTION_SACK_ADVERTISE & options)) {
395 - *ptr++ = htonl((TCPOPT_NOP << 24) |
396 - (TCPOPT_NOP << 16) |
397 - (TCPOPT_SACK_PERM << 8) |
398 - TCPOLEN_SACK_PERM);
399 + net_hdr_word(ptr++) =
400 + htonl((TCPOPT_NOP << 24) |
401 + (TCPOPT_NOP << 16) |
402 + (TCPOPT_SACK_PERM << 8) |
403 + TCPOLEN_SACK_PERM);
404 }
405
406 if (unlikely(OPTION_WSCALE & options)) {
407 - *ptr++ = htonl((TCPOPT_NOP << 24) |
408 - (TCPOPT_WINDOW << 16) |
409 - (TCPOLEN_WINDOW << 8) |
410 - opts->ws);
411 + net_hdr_word(ptr++) =
412 + htonl((TCPOPT_NOP << 24) |
413 + (TCPOPT_WINDOW << 16) |
414 + (TCPOLEN_WINDOW << 8) |
415 + opts->ws);
416 }
417
418 if (unlikely(opts->num_sack_blocks)) {
419 @@ -658,16 +663,17 @@ static void tcp_options_write(__be32 *pt
420 tp->duplicate_sack : tp->selective_acks;
421 int this_sack;
422
423 - *ptr++ = htonl((TCPOPT_NOP << 24) |
424 - (TCPOPT_NOP << 16) |
425 - (TCPOPT_SACK << 8) |
426 - (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
427 + net_hdr_word(ptr++) =
428 + htonl((TCPOPT_NOP << 24) |
429 + (TCPOPT_NOP << 16) |
430 + (TCPOPT_SACK << 8) |
431 + (TCPOLEN_SACK_BASE + (opts->num_sack_blocks *
432 TCPOLEN_SACK_PERBLOCK)));
433
434 for (this_sack = 0; this_sack < opts->num_sack_blocks;
435 ++this_sack) {
436 - *ptr++ = htonl(sp[this_sack].start_seq);
437 - *ptr++ = htonl(sp[this_sack].end_seq);
438 + net_hdr_word(ptr++) = htonl(sp[this_sack].start_seq);
439 + net_hdr_word(ptr++) = htonl(sp[this_sack].end_seq);
440 }
441
442 tp->rx_opt.dsack = 0;
443 @@ -680,13 +686,14 @@ static void tcp_options_write(__be32 *pt
444
445 if (foc->exp) {
446 len = TCPOLEN_EXP_FASTOPEN_BASE + foc->len;
447 - *ptr = htonl((TCPOPT_EXP << 24) | (len << 16) |
448 + net_hdr_word(ptr) =
449 + htonl((TCPOPT_EXP << 24) | (len << 16) |
450 TCPOPT_FASTOPEN_MAGIC);
451 p += TCPOLEN_EXP_FASTOPEN_BASE;
452 } else {
453 len = TCPOLEN_FASTOPEN_BASE + foc->len;
454 - *p++ = TCPOPT_FASTOPEN;
455 - *p++ = len;
456 + net_hdr_word(p++) = TCPOPT_FASTOPEN;
457 + net_hdr_word(p++) = len;
458 }
459
460 memcpy(p, foc->val, foc->len);
461 --- a/include/uapi/linux/igmp.h
462 +++ b/include/uapi/linux/igmp.h
463 @@ -33,7 +33,7 @@ struct igmphdr {
464 __u8 code; /* For newer IGMP */
465 __sum16 csum;
466 __be32 group;
467 -};
468 +} __attribute__((packed, aligned(2)));
469
470 /* V3 group record types [grec_type] */
471 #define IGMPV3_MODE_IS_INCLUDE 1
472 @@ -49,7 +49,7 @@ struct igmpv3_grec {
473 __be16 grec_nsrcs;
474 __be32 grec_mca;
475 __be32 grec_src[0];
476 -};
477 +} __attribute__((packed, aligned(2)));
478
479 struct igmpv3_report {
480 __u8 type;
481 @@ -58,7 +58,7 @@ struct igmpv3_report {
482 __be16 resv2;
483 __be16 ngrec;
484 struct igmpv3_grec grec[0];
485 -};
486 +} __attribute__((packed, aligned(2)));
487
488 struct igmpv3_query {
489 __u8 type;
490 @@ -79,7 +79,7 @@ struct igmpv3_query {
491 __u8 qqic;
492 __be16 nsrcs;
493 __be32 srcs[0];
494 -};
495 +} __attribute__((packed, aligned(2)));
496
497 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
498 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
499 --- a/net/core/flow_dissector.c
500 +++ b/net/core/flow_dissector.c
501 @@ -128,7 +128,7 @@ __be32 __skb_flow_get_ports(const struct
502 ports = __skb_header_pointer(skb, thoff + poff,
503 sizeof(_ports), data, hlen, &_ports);
504 if (ports)
505 - return *ports;
506 + return (__be32)net_hdr_word(ports);
507 }
508
509 return 0;
510 --- a/include/uapi/linux/icmpv6.h
511 +++ b/include/uapi/linux/icmpv6.h
512 @@ -78,7 +78,7 @@ struct icmp6hdr {
513 #define icmp6_addrconf_other icmp6_dataun.u_nd_ra.other
514 #define icmp6_rt_lifetime icmp6_dataun.u_nd_ra.rt_lifetime
515 #define icmp6_router_pref icmp6_dataun.u_nd_ra.router_pref
516 -};
517 +} __attribute__((packed, aligned(2)));
518
519
520 #define ICMPV6_ROUTER_PREF_LOW 0x3
521 --- a/include/net/ndisc.h
522 +++ b/include/net/ndisc.h
523 @@ -93,7 +93,7 @@ struct ra_msg {
524 struct icmp6hdr icmph;
525 __be32 reachable_time;
526 __be32 retrans_timer;
527 -};
528 +} __attribute__((packed, aligned(2)));
529
530 struct rd_msg {
531 struct icmp6hdr icmph;
532 @@ -372,10 +372,10 @@ static inline u32 ndisc_hashfn(const voi
533 {
534 const u32 *p32 = pkey;
535
536 - return (((p32[0] ^ hash32_ptr(dev)) * hash_rnd[0]) +
537 - (p32[1] * hash_rnd[1]) +
538 - (p32[2] * hash_rnd[2]) +
539 - (p32[3] * hash_rnd[3]));
540 + return (((net_hdr_word(&p32[0]) ^ hash32_ptr(dev)) * hash_rnd[0]) +
541 + (net_hdr_word(&p32[1]) * hash_rnd[1]) +
542 + (net_hdr_word(&p32[2]) * hash_rnd[2]) +
543 + (net_hdr_word(&p32[3]) * hash_rnd[3]));
544 }
545
546 static inline struct neighbour *__ipv6_neigh_lookup_noref(struct net_device *dev, const void *pkey)
547 --- a/net/sched/cls_u32.c
548 +++ b/net/sched/cls_u32.c
549 @@ -155,7 +155,7 @@ next_knode:
550 data = skb_header_pointer(skb, toff, 4, &hdata);
551 if (!data)
552 goto out;
553 - if ((*data ^ key->val) & key->mask) {
554 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
555 n = rcu_dereference_bh(n->next);
556 goto next_knode;
557 }
558 @@ -206,8 +206,8 @@ check_terminal:
559 &hdata);
560 if (!data)
561 goto out;
562 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
563 - n->fshift);
564 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
565 + &n->sel, n->fshift);
566 }
567 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
568 goto next_ht;
569 --- a/net/ipv6/ip6_offload.c
570 +++ b/net/ipv6/ip6_offload.c
571 @@ -240,7 +240,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *
572 continue;
573
574 iph2 = (struct ipv6hdr *)(p->data + off);
575 - first_word = *(__be32 *)iph ^ *(__be32 *)iph2;
576 + first_word = net_hdr_word(iph) ^ net_hdr_word(iph2);
577
578 /* All fields must match except length and Traffic Class.
579 * XXX skbs on the gro_list have all been parsed and pulled
580 --- a/include/net/addrconf.h
581 +++ b/include/net/addrconf.h
582 @@ -47,7 +47,7 @@ struct prefix_info {
583 __be32 reserved2;
584
585 struct in6_addr prefix;
586 -};
587 +} __attribute__((packed, aligned(2)));
588
589 #include <linux/ipv6.h>
590 #include <linux/netdevice.h>
591 --- a/include/net/inet_ecn.h
592 +++ b/include/net/inet_ecn.h
593 @@ -140,9 +140,9 @@ static inline int IP6_ECN_set_ce(struct
594 if (INET_ECN_is_not_ect(ipv6_get_dsfield(iph)))
595 return 0;
596
597 - from = *(__be32 *)iph;
598 + from = net_hdr_word(iph);
599 to = from | htonl(INET_ECN_CE << 20);
600 - *(__be32 *)iph = to;
601 + net_hdr_word(iph) = to;
602 if (skb->ip_summed == CHECKSUM_COMPLETE)
603 skb->csum = csum_add(csum_sub(skb->csum, (__force __wsum)from),
604 (__force __wsum)to);
605 --- a/include/net/ipv6.h
606 +++ b/include/net/ipv6.h
607 @@ -146,7 +146,7 @@ struct frag_hdr {
608 __u8 reserved;
609 __be16 frag_off;
610 __be32 identification;
611 -};
612 +} __attribute__((packed, aligned(2)));
613
614 #define IP6_MF 0x0001
615 #define IP6_OFFSET 0xFFF8
616 @@ -560,8 +560,8 @@ static inline void __ipv6_addr_set_half(
617 }
618 #endif
619 #endif
620 - addr[0] = wh;
621 - addr[1] = wl;
622 + net_hdr_word(&addr[0]) = wh;
623 + net_hdr_word(&addr[1]) = wl;
624 }
625
626 static inline void ipv6_addr_set(struct in6_addr *addr,
627 @@ -620,6 +620,8 @@ static inline bool ipv6_prefix_equal(con
628 const __be32 *a1 = addr1->s6_addr32;
629 const __be32 *a2 = addr2->s6_addr32;
630 unsigned int pdw, pbi;
631 + /* Used for last <32-bit fraction of prefix */
632 + u32 pbia1, pbia2;
633
634 /* check complete u32 in prefix */
635 pdw = prefixlen >> 5;
636 @@ -628,7 +630,9 @@ static inline bool ipv6_prefix_equal(con
637
638 /* check incomplete u32 in prefix */
639 pbi = prefixlen & 0x1f;
640 - if (pbi && ((a1[pdw] ^ a2[pdw]) & htonl((0xffffffff) << (32 - pbi))))
641 + pbia1 = net_hdr_word(&a1[pdw]);
642 + pbia2 = net_hdr_word(&a2[pdw]);
643 + if (pbi && ((pbia1 ^ pbia2) & htonl((0xffffffff) << (32 - pbi))))
644 return false;
645
646 return true;
647 @@ -749,13 +753,13 @@ static inline void ipv6_addr_set_v4mappe
648 */
649 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
650 {
651 - const __be32 *a1 = token1, *a2 = token2;
652 + const struct in6_addr *a1 = token1, *a2 = token2;
653 int i;
654
655 addrlen >>= 2;
656
657 for (i = 0; i < addrlen; i++) {
658 - __be32 xb = a1[i] ^ a2[i];
659 + __be32 xb = a1->s6_addr32[i] ^ a2->s6_addr32[i];
660 if (xb)
661 return i * 32 + 31 - __fls(ntohl(xb));
662 }
663 @@ -941,17 +945,18 @@ static inline int ip6_multipath_hash_pol
664 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
665 __be32 flowlabel)
666 {
667 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
668 + net_hdr_word((__be32 *)hdr) =
669 + htonl(0x60000000 | (tclass << 20)) | flowlabel;
670 }
671
672 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
673 {
674 - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
675 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
676 }
677
678 static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
679 {
680 - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
681 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
682 }
683
684 static inline u8 ip6_tclass(__be32 flowinfo)
685 --- a/include/net/secure_seq.h
686 +++ b/include/net/secure_seq.h
687 @@ -3,6 +3,7 @@
688 #define _NET_SECURE_SEQ
689
690 #include <linux/types.h>
691 +#include <linux/in6.h>
692
693 u64 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
694 u64 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
695 --- a/include/uapi/linux/in.h
696 +++ b/include/uapi/linux/in.h
697 @@ -88,7 +88,7 @@ enum {
698 /* Internet address. */
699 struct in_addr {
700 __be32 s_addr;
701 -};
702 +} __attribute__((packed, aligned(2)));
703 #endif
704
705 #define IP_TOS 1
706 --- a/net/ipv6/ip6_fib.c
707 +++ b/net/ipv6/ip6_fib.c
708 @@ -140,7 +140,7 @@ static __be32 addr_bit_set(const void *t
709 * See include/asm-generic/bitops/le.h.
710 */
711 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
712 - addr[fn_bit >> 5];
713 + net_hdr_word(&addr[fn_bit >> 5]);
714 }
715
716 struct fib6_info *fib6_info_alloc(gfp_t gfp_flags, bool with_fib6_nh)
717 --- a/net/netfilter/nf_conntrack_proto_tcp.c
718 +++ b/net/netfilter/nf_conntrack_proto_tcp.c
719 @@ -415,7 +415,7 @@ static void tcp_sack(const struct sk_buf
720
721 /* Fast path for timestamp-only option */
722 if (length == TCPOLEN_TSTAMP_ALIGNED
723 - && *(__be32 *)ptr == htonl((TCPOPT_NOP << 24)
724 + && net_hdr_word(ptr) == htonl((TCPOPT_NOP << 24)
725 | (TCPOPT_NOP << 16)
726 | (TCPOPT_TIMESTAMP << 8)
727 | TCPOLEN_TIMESTAMP))
728 --- a/net/xfrm/xfrm_input.c
729 +++ b/net/xfrm/xfrm_input.c
730 @@ -165,8 +165,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
731 if (!pskb_may_pull(skb, hlen))
732 return -EINVAL;
733
734 - *spi = *(__be32 *)(skb_transport_header(skb) + offset);
735 - *seq = *(__be32 *)(skb_transport_header(skb) + offset_seq);
736 + *spi = net_hdr_word(skb_transport_header(skb) + offset);
737 + *seq = net_hdr_word(skb_transport_header(skb) + offset_seq);
738 return 0;
739 }
740 EXPORT_SYMBOL(xfrm_parse_spi);
741 --- a/net/ipv4/tcp_input.c
742 +++ b/net/ipv4/tcp_input.c
743 @@ -4128,14 +4128,16 @@ static bool tcp_parse_aligned_timestamp(
744 {
745 const __be32 *ptr = (const __be32 *)(th + 1);
746
747 - if (*ptr == htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16)
748 - | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
749 + if (net_hdr_word(ptr) ==
750 + htonl((TCPOPT_NOP << 24) | (TCPOPT_NOP << 16) |
751 + (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
752 tp->rx_opt.saw_tstamp = 1;
753 ++ptr;
754 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
755 + tp->rx_opt.rcv_tsval = get_unaligned_be32(ptr);
756 ++ptr;
757 - if (*ptr)
758 - tp->rx_opt.rcv_tsecr = ntohl(*ptr) - tp->tsoffset;
759 + if (net_hdr_word(ptr))
760 + tp->rx_opt.rcv_tsecr = get_unaligned_be32(ptr) -
761 + tp->tsoffset;
762 else
763 tp->rx_opt.rcv_tsecr = 0;
764 return true;
765 --- a/include/uapi/linux/if_pppox.h
766 +++ b/include/uapi/linux/if_pppox.h
767 @@ -51,6 +51,7 @@ struct pppoe_addr {
768 */
769 struct pptp_addr {
770 __u16 call_id;
771 + __u16 pad;
772 struct in_addr sin_addr;
773 };
774
775 --- a/net/ipv6/netfilter/nf_log_ipv6.c
776 +++ b/net/ipv6/netfilter/nf_log_ipv6.c
777 @@ -63,9 +63,9 @@ static void dump_ipv6_packet(struct net
778 /* Max length: 44 "LEN=65535 TC=255 HOPLIMIT=255 FLOWLBL=FFFFF " */
779 nf_log_buf_add(m, "LEN=%zu TC=%u HOPLIMIT=%u FLOWLBL=%u ",
780 ntohs(ih->payload_len) + sizeof(struct ipv6hdr),
781 - (ntohl(*(__be32 *)ih) & 0x0ff00000) >> 20,
782 + (ntohl(net_hdr_word(ih)) & 0x0ff00000) >> 20,
783 ih->hop_limit,
784 - (ntohl(*(__be32 *)ih) & 0x000fffff));
785 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
786
787 fragment = 0;
788 ptr = ip6hoff + sizeof(struct ipv6hdr);
789 --- a/include/net/neighbour.h
790 +++ b/include/net/neighbour.h
791 @@ -275,8 +275,10 @@ static inline bool neigh_key_eq128(const
792 const u32 *n32 = (const u32 *)n->primary_key;
793 const u32 *p32 = pkey;
794
795 - return ((n32[0] ^ p32[0]) | (n32[1] ^ p32[1]) |
796 - (n32[2] ^ p32[2]) | (n32[3] ^ p32[3])) == 0;
797 + return ((n32[0] ^ net_hdr_word(&p32[0])) |
798 + (n32[1] ^ net_hdr_word(&p32[1])) |
799 + (n32[2] ^ net_hdr_word(&p32[2])) |
800 + (n32[3] ^ net_hdr_word(&p32[3]))) == 0;
801 }
802
803 static inline struct neighbour *___neigh_lookup_noref(
804 --- a/include/uapi/linux/netfilter_arp/arp_tables.h
805 +++ b/include/uapi/linux/netfilter_arp/arp_tables.h
806 @@ -70,7 +70,7 @@ struct arpt_arp {
807 __u8 flags;
808 /* Inverse flags */
809 __u16 invflags;
810 -};
811 +} __attribute__((aligned(4)));
812
813 /* Values for "flag" field in struct arpt_ip (general arp structure).
814 * No flags defined yet.
815 --- a/net/core/utils.c
816 +++ b/net/core/utils.c
817 @@ -460,8 +460,14 @@ void inet_proto_csum_replace16(__sum16 *
818 bool pseudohdr)
819 {
820 __be32 diff[] = {
821 - ~from[0], ~from[1], ~from[2], ~from[3],
822 - to[0], to[1], to[2], to[3],
823 + ~net_hdr_word(&from[0]),
824 + ~net_hdr_word(&from[1]),
825 + ~net_hdr_word(&from[2]),
826 + ~net_hdr_word(&from[3]),
827 + net_hdr_word(&to[0]),
828 + net_hdr_word(&to[1]),
829 + net_hdr_word(&to[2]),
830 + net_hdr_word(&to[3]),
831 };
832 if (skb->ip_summed != CHECKSUM_PARTIAL) {
833 *sum = csum_fold(csum_partial(diff, sizeof(diff),
834 --- a/include/linux/etherdevice.h
835 +++ b/include/linux/etherdevice.h
836 @@ -513,7 +513,7 @@ static inline bool is_etherdev_addr(cons
837 * @b: Pointer to Ethernet header
838 *
839 * Compare two Ethernet headers, returns 0 if equal.
840 - * This assumes that the network header (i.e., IP header) is 4-byte
841 + * This assumes that the network header (i.e., IP header) is 2-byte
842 * aligned OR the platform can handle unaligned access. This is the
843 * case for all packets coming into netif_receive_skb or similar
844 * entry points.
845 @@ -536,11 +536,12 @@ static inline unsigned long compare_ethe
846 fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
847 return fold;
848 #else
849 - u32 *a32 = (u32 *)((u8 *)a + 2);
850 - u32 *b32 = (u32 *)((u8 *)b + 2);
851 + const u16 *a16 = a;
852 + const u16 *b16 = b;
853
854 - return (*(u16 *)a ^ *(u16 *)b) | (a32[0] ^ b32[0]) |
855 - (a32[1] ^ b32[1]) | (a32[2] ^ b32[2]);
856 + return (a16[0] ^ b16[0]) | (a16[1] ^ b16[1]) | (a16[2] ^ b16[2]) |
857 + (a16[3] ^ b16[3]) | (a16[4] ^ b16[4]) | (a16[5] ^ b16[5]) |
858 + (a16[6] ^ b16[6]);
859 #endif
860 }
861
862 --- a/net/ipv4/tcp_offload.c
863 +++ b/net/ipv4/tcp_offload.c
864 @@ -223,7 +223,7 @@ struct sk_buff *tcp_gro_receive(struct l
865
866 th2 = tcp_hdr(p);
867
868 - if (*(u32 *)&th->source ^ *(u32 *)&th2->source) {
869 + if (net_hdr_word(&th->source) ^ net_hdr_word(&th2->source)) {
870 NAPI_GRO_CB(p)->same_flow = 0;
871 continue;
872 }
873 @@ -241,8 +241,8 @@ found:
874 ~(TCP_FLAG_CWR | TCP_FLAG_FIN | TCP_FLAG_PSH));
875 flush |= (__force int)(th->ack_seq ^ th2->ack_seq);
876 for (i = sizeof(*th); i < thlen; i += 4)
877 - flush |= *(u32 *)((u8 *)th + i) ^
878 - *(u32 *)((u8 *)th2 + i);
879 + flush |= net_hdr_word((u8 *)th + i) ^
880 + net_hdr_word((u8 *)th2 + i);
881
882 /* When we receive our second frame we can made a decision on if we
883 * continue this flow as an atomic flow with a fixed ID or if we use
884 --- a/net/ipv6/netfilter/ip6table_mangle.c
885 +++ b/net/ipv6/netfilter/ip6table_mangle.c
886 @@ -47,7 +47,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
887 hop_limit = ipv6_hdr(skb)->hop_limit;
888
889 /* flowlabel and prio (includes version, which shouldn't change either */
890 - flowlabel = *((u_int32_t *)ipv6_hdr(skb));
891 + flowlabel = net_hdr_word(ipv6_hdr(skb));
892
893 ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
894
895 @@ -56,7 +56,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
896 !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
897 skb->mark != mark ||
898 ipv6_hdr(skb)->hop_limit != hop_limit ||
899 - flowlabel != *((u_int32_t *)ipv6_hdr(skb)))) {
900 + flowlabel != net_hdr_word(ipv6_hdr(skb)))) {
901 err = ip6_route_me_harder(state->net, state->sk, skb);
902 if (err < 0)
903 ret = NF_DROP_ERR(err);