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