1 From: Felix Fietkau <nbd@openwrt.org>
2 Subject: [PATCH] ar71xx: fix unaligned access in a few more places
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(-)
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;
55 - carry = (csum < word[1]);
56 + csum = net_hdr_word(word++);
58 + w = net_hdr_word(word++);
64 - carry = (csum < word[2]);
65 + w = net_hdr_word(word++);
71 - carry = (csum < word[3]);
72 + w = net_hdr_word(word++);
80 - carry = (csum < *word);
81 + w = net_hdr_word(word++);
86 } while (word != stop);
88 return csum_fold(csum);
89 @@ -182,74 +186,6 @@ static inline __sum16 ip_compute_csum(co
90 return csum_fold(csum_partial(buff, len, 0));
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,
102 - " .set push # csum_ipv6_magic\n"
103 - " .set noreorder \n"
105 - " addu %0, %5 # proto (long in network byte order)\n"
106 - " sltu $1, %0, %5 \n"
109 - " addu %0, %6 # csum\n"
110 - " sltu $1, %0, %6 \n"
111 - " lw %1, 0(%2) # four words source address\n"
114 - " sltu $1, %0, %1 \n"
119 - " sltu $1, %0, %1 \n"
124 - " sltu $1, %0, %1 \n"
126 - " lw %1, 12(%2) \n"
129 - " sltu $1, %0, %1 \n"
134 - " sltu $1, %0, %1 \n"
139 - " sltu $1, %0, %1 \n"
144 - " sltu $1, %0, %1 \n"
146 - " lw %1, 12(%3) \n"
149 - " sltu $1, %0, %1 \n"
151 - " addu %0, $1 # Add final carry\n"
153 - : "=&r" (sum), "=&r" (tmp)
154 - : "r" (saddr), "r" (daddr),
155 - "0" (htonl(len)), "r" (htonl(proto)), "r" (sum)
158 - return csum_fold(sum);
161 #include <asm-generic/checksum.h>
162 #endif /* CONFIG_GENERIC_CSUM */
164 --- a/include/uapi/linux/ip.h
165 +++ b/include/uapi/linux/ip.h
166 @@ -106,7 +106,7 @@ struct iphdr {
169 /*The options start here. */
171 +} __attribute__((packed, aligned(2)));
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;
182 +} __attribute__((packed, aligned(2)));
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 {
193 +} __attribute__((packed, aligned(2)));
196 * The union cast uses a gcc extension to avoid aliasing problems
197 @@ -65,7 +65,7 @@ struct tcphdr {
202 +} __attribute__((packed, aligned(2)));
204 #define tcp_flag_word(tp) (((union tcp_word_hdr *)(tp))->words[3])
206 --- a/include/uapi/linux/udp.h
207 +++ b/include/uapi/linux/udp.h
208 @@ -25,7 +25,7 @@ struct udphdr {
213 +} __attribute__((packed, aligned(2)));
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
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);
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 {
237 +} __attribute__((packed, aligned(2)));
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
248 +} __attribute__((packed, aligned(2)));
249 #endif /* __UAPI_DEF_IN6_ADDR */
251 #if __UAPI_DEF_SOCKADDR_IN6
252 --- a/net/ipv6/tcp_ipv6.c
253 +++ b/net/ipv6/tcp_ipv6.c
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 @@ -944,10 +945,10 @@ static void tcp_v6_send_response(const s
263 topt = (__be32 *)(t1 + 1);
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++);
277 --- a/include/linux/ipv6.h
278 +++ b/include/linux/ipv6.h
281 #define ipv6_optlen(p) (((p)->hdrlen+1) << 3)
282 #define ipv6_authlen(p) (((p)->hdrlen+2) << 2)
285 * This structure contains configuration options per IPv6 link.
287 --- a/net/ipv6/datagram.c
288 +++ b/net/ipv6/datagram.c
289 @@ -492,7 +492,7 @@ int ipv6_recv_error(struct sock *sk, str
290 ipv6_iface_scope_id(&sin->sin6_addr,
293 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
294 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
296 sin->sin6_scope_id = 0;
298 @@ -846,12 +846,12 @@ int ip6_datagram_send_ctl(struct net *ne
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) {
308 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
309 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
312 case IPV6_2292HOPOPTS:
313 --- a/net/ipv6/exthdrs.c
314 +++ b/net/ipv6/exthdrs.c
315 @@ -1002,7 +1002,7 @@ static bool ipv6_hop_jumbo(struct sk_buf
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 __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
323 icmpv6_param_prob(skb, ICMPV6_HDR_FIELD, optoff+2);
324 --- a/include/linux/types.h
325 +++ b/include/linux/types.h
326 @@ -231,5 +231,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);
330 +struct net_hdr_word {
332 +} __attribute__((packed, aligned(2)));
334 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
336 #endif /* __ASSEMBLY__ */
337 #endif /* _LINUX_TYPES_H */
338 --- a/net/ipv4/af_inet.c
339 +++ b/net/ipv4/af_inet.c
340 @@ -1480,8 +1480,8 @@ struct sk_buff *inet_gro_receive(struct
341 if (unlikely(ip_fast_csum((u8 *)iph, 5)))
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));
350 list_for_each_entry(p, head, list) {
351 --- a/net/ipv4/tcp_output.c
352 +++ b/net/ipv4/tcp_output.c
353 @@ -609,48 +609,53 @@ static void tcp_options_write(__be32 *pt
354 u16 options = opts->options; /* mungable copy */
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;
367 if (unlikely(opts->mss)) {
368 - *ptr++ = htonl((TCPOPT_MSS << 24) |
369 - (TCPOLEN_MSS << 16) |
371 + net_hdr_word(ptr++) =
372 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
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;
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);
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);
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);
417 if (unlikely(OPTION_WSCALE & options)) {
418 - *ptr++ = htonl((TCPOPT_NOP << 24) |
419 - (TCPOPT_WINDOW << 16) |
420 - (TCPOLEN_WINDOW << 8) |
422 + net_hdr_word(ptr++) =
423 + htonl((TCPOPT_NOP << 24) |
424 + (TCPOPT_WINDOW << 16) |
425 + (TCPOLEN_WINDOW << 8) |
429 if (unlikely(opts->num_sack_blocks)) {
430 @@ -658,16 +663,17 @@ static void tcp_options_write(__be32 *pt
431 tp->duplicate_sack : tp->selective_acks;
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)));
445 for (this_sack = 0; this_sack < opts->num_sack_blocks;
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);
453 tp->rx_opt.dsack = 0;
454 @@ -680,13 +686,14 @@ static void tcp_options_write(__be32 *pt
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;
464 len = TCPOLEN_FASTOPEN_BASE + foc->len;
465 - *p++ = TCPOPT_FASTOPEN;
467 + net_hdr_word(p++) = TCPOPT_FASTOPEN;
468 + net_hdr_word(p++) = len;
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 */
479 +} __attribute__((packed, aligned(2)));
481 /* V3 group record types [grec_type] */
482 #define IGMPV3_MODE_IS_INCLUDE 1
483 @@ -49,7 +49,7 @@ struct igmpv3_grec {
488 +} __attribute__((packed, aligned(2)));
490 struct igmpv3_report {
492 @@ -58,7 +58,7 @@ struct igmpv3_report {
495 struct igmpv3_grec grec[0];
497 +} __attribute__((packed, aligned(2)));
499 struct igmpv3_query {
501 @@ -79,7 +79,7 @@ struct igmpv3_query {
506 +} __attribute__((packed, aligned(2)));
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 @@ -129,7 +129,7 @@ __be32 __skb_flow_get_ports(const struct
513 ports = __skb_header_pointer(skb, thoff + poff,
514 sizeof(_ports), data, hlen, &_ports);
517 + return (__be32)net_hdr_word(ports);
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
528 +} __attribute__((packed, aligned(2)));
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;
539 +} __attribute__((packed, aligned(2)));
542 struct icmp6hdr icmph;
543 @@ -372,10 +372,10 @@ static inline u32 ndisc_hashfn(const voi
545 const u32 *p32 = pkey;
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]));
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);
564 - if ((*data ^ key->val) & key->mask) {
565 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
566 n = rcu_dereference_bh(n->next);
569 @@ -206,8 +206,8 @@ check_terminal:
573 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
575 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
576 + &n->sel, n->fshift);
578 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
580 --- a/net/ipv6/ip6_offload.c
581 +++ b/net/ipv6/ip6_offload.c
582 @@ -241,7 +241,7 @@ INDIRECT_CALLABLE_SCOPE struct sk_buff *
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);
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 {
596 struct in6_addr prefix;
598 +} __attribute__((packed, aligned(2)));
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)))
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),
616 --- a/include/net/ipv6.h
617 +++ b/include/net/ipv6.h
618 @@ -147,7 +147,7 @@ struct frag_hdr {
621 __be32 identification;
623 +} __attribute__((packed, aligned(2)));
625 #define IP6_MF 0x0001
626 #define IP6_OFFSET 0xFFF8
627 @@ -561,8 +561,8 @@ static inline void __ipv6_addr_set_half(
633 + net_hdr_word(&addr[0]) = wh;
634 + net_hdr_word(&addr[1]) = wl;
637 static inline void ipv6_addr_set(struct in6_addr *addr,
638 @@ -621,6 +621,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 */
645 /* check complete u32 in prefix */
646 pdw = prefixlen >> 5;
647 @@ -629,7 +631,9 @@ static inline bool ipv6_prefix_equal(con
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))))
658 @@ -746,13 +750,13 @@ static inline void ipv6_addr_set_v4mappe
660 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
662 - const __be32 *a1 = token1, *a2 = token2;
663 + const struct in6_addr *a1 = token1, *a2 = token2;
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];
672 return i * 32 + 31 - __fls(ntohl(xb));
674 @@ -946,17 +950,18 @@ static inline u32 ip6_multipath_hash_fie
675 static inline void ip6_flow_hdr(struct ipv6hdr *hdr, unsigned int tclass,
678 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
679 + net_hdr_word((__be32 *)hdr) =
680 + htonl(0x60000000 | (tclass << 20)) | flowlabel;
683 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
685 - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
686 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
689 static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
691 - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
692 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
695 static inline u8 ip6_tclass(__be32 flowinfo)
696 --- a/include/net/secure_seq.h
697 +++ b/include/net/secure_seq.h
699 #define _NET_SECURE_SEQ
701 #include <linux/types.h>
702 +#include <linux/in6.h>
704 u64 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
705 u64 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr,
706 --- a/include/uapi/linux/in.h
707 +++ b/include/uapi/linux/in.h
708 @@ -88,7 +88,7 @@ enum {
709 /* Internet address. */
713 +} __attribute__((packed, aligned(2)));
717 --- a/net/ipv6/ip6_fib.c
718 +++ b/net/ipv6/ip6_fib.c
719 @@ -141,7 +141,7 @@ static __be32 addr_bit_set(const void *t
720 * See include/asm-generic/bitops/le.h.
722 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
724 + net_hdr_word(&addr[fn_bit >> 5]);
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 @@ -400,7 +400,7 @@ static void tcp_sack(const struct sk_buf
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)
737 | (TCPOPT_TIMESTAMP << 8)
738 | TCPOLEN_TIMESTAMP))
739 --- a/net/xfrm/xfrm_input.c
740 +++ b/net/xfrm/xfrm_input.c
741 @@ -167,8 +167,8 @@ int xfrm_parse_spi(struct sk_buff *skb,
742 if (!pskb_may_pull(skb, hlen))
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);
751 EXPORT_SYMBOL(xfrm_parse_spi);
752 --- a/net/ipv4/tcp_input.c
753 +++ b/net/ipv4/tcp_input.c
754 @@ -4175,14 +4175,16 @@ static bool tcp_parse_aligned_timestamp(
756 const __be32 *ptr = (const __be32 *)(th + 1);
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;
765 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
766 + tp->rx_opt.rcv_tsval = get_unaligned_be32(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) -
774 tp->rx_opt.rcv_tsecr = 0;
776 --- a/include/uapi/linux/if_pppox.h
777 +++ b/include/uapi/linux/if_pppox.h
778 @@ -51,6 +51,7 @@ struct pppoe_addr {
783 struct in_addr sin_addr;
786 --- a/include/net/neighbour.h
787 +++ b/include/net/neighbour.h
788 @@ -270,8 +270,10 @@ static inline bool neigh_key_eq128(const
789 const u32 *n32 = (const u32 *)n->primary_key;
790 const u32 *p32 = pkey;
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;
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 {
808 +} __attribute__((aligned(4)));
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 *
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]),
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 @@ -525,7 +525,7 @@ static inline bool is_etherdev_addr(cons
834 * @b: Pointer to Ethernet header
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
842 @@ -548,11 +548,12 @@ static inline unsigned long compare_ethe
843 fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
846 - u32 *a32 = (u32 *)((u8 *)a + 2);
847 - u32 *b32 = (u32 *)((u8 *)b + 2);
848 + const u16 *a16 = a;
849 + const u16 *b16 = b;
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]) |
859 --- a/net/ipv4/tcp_offload.c
860 +++ b/net/ipv4/tcp_offload.c
861 @@ -223,7 +223,7 @@ struct sk_buff *tcp_gro_receive(struct l
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;
870 @@ -241,8 +241,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);
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(struct sk_buff *skb, con
884 hop_limit = ipv6_hdr(skb)->hop_limit;
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));
890 ret = ip6t_do_table(skb, state, priv);
892 @@ -53,7 +53,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
893 !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
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);
900 ret = NF_DROP_ERR(err);