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 @@ -180,73 +184,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));
157 - return csum_fold(sum);
160 #include <asm-generic/checksum.h>
161 #endif /* CONFIG_GENERIC_CSUM */
163 --- a/include/uapi/linux/ip.h
164 +++ b/include/uapi/linux/ip.h
165 @@ -106,7 +106,7 @@ struct iphdr {
168 /*The options start here. */
170 +} __attribute__((packed, aligned(2)));
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;
181 +} __attribute__((packed, aligned(2)));
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 {
192 +} __attribute__((packed, aligned(2)));
195 * The union cast uses a gcc extension to avoid aliasing problems
196 @@ -65,7 +65,7 @@ struct tcphdr {
201 +} __attribute__((packed, aligned(2)));
203 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3])
205 --- a/include/uapi/linux/udp.h
206 +++ b/include/uapi/linux/udp.h
207 @@ -25,7 +25,7 @@ struct udphdr {
212 +} __attribute__((packed, aligned(2)));
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
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);
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 {
236 +} __attribute__((packed, aligned(2)));
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
247 +} __attribute__((packed, aligned(2)));
248 #endif /* __UAPI_DEF_IN6_ADDR */
250 #if __UAPI_DEF_SOCKADDR_IN6
251 --- a/net/ipv6/tcp_ipv6.c
252 +++ b/net/ipv6/tcp_ipv6.c
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 @@ -926,10 +927,10 @@ static void tcp_v6_send_response(const s
262 topt = (__be32 *)(t1 + 1);
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++);
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,
282 - ipv6_addr_set_v4mapped(*(__be32 *)(nh + serr->addr_offset),
283 + ipv6_addr_set_v4mapped(net_hdr_word(nh + serr->addr_offset),
285 sin->sin6_scope_id = 0;
287 @@ -846,12 +846,12 @@ int ip6_datagram_send_ctl(struct net *ne
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) {
297 - fl6->flowlabel = IPV6_FLOWINFO_MASK & *(__be32 *)CMSG_DATA(cmsg);
298 + fl6->flowlabel = IPV6_FLOWINFO_MASK & net_hdr_word(CMSG_DATA(cmsg));
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
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);
319 +struct net_hdr_word {
321 +} __attribute__((packed, aligned(2)));
323 +#define net_hdr_word(_p) (((struct net_hdr_word *) (_p))->words[0])
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)))
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));
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 */
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;
356 if (unlikely(opts->mss)) {
357 - *ptr++ = htonl((TCPOPT_MSS << 24) |
358 - (TCPOLEN_MSS << 16) |
360 + net_hdr_word(ptr++) =
361 + htonl((TCPOPT_MSS << 24) | (TCPOLEN_MSS << 16) |
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;
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);
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);
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);
406 if (unlikely(OPTION_WSCALE & options)) {
407 - *ptr++ = htonl((TCPOPT_NOP << 24) |
408 - (TCPOPT_WINDOW << 16) |
409 - (TCPOLEN_WINDOW << 8) |
411 + net_hdr_word(ptr++) =
412 + htonl((TCPOPT_NOP << 24) |
413 + (TCPOPT_WINDOW << 16) |
414 + (TCPOLEN_WINDOW << 8) |
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;
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)));
434 for (this_sack = 0; this_sack < opts->num_sack_blocks;
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);
442 tp->rx_opt.dsack = 0;
443 @@ -680,13 +686,14 @@ static void tcp_options_write(__be32 *pt
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;
453 len = TCPOLEN_FASTOPEN_BASE + foc->len;
454 - *p++ = TCPOPT_FASTOPEN;
456 + net_hdr_word(p++) = TCPOPT_FASTOPEN;
457 + net_hdr_word(p++) = len;
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 */
468 +} __attribute__((packed, aligned(2)));
470 /* V3 group record types [grec_type] */
471 #define IGMPV3_MODE_IS_INCLUDE 1
472 @@ -49,7 +49,7 @@ struct igmpv3_grec {
477 +} __attribute__((packed, aligned(2)));
479 struct igmpv3_report {
481 @@ -58,7 +58,7 @@ struct igmpv3_report {
484 struct igmpv3_grec grec[0];
486 +} __attribute__((packed, aligned(2)));
488 struct igmpv3_query {
490 @@ -79,7 +79,7 @@ struct igmpv3_query {
495 +} __attribute__((packed, aligned(2)));
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);
506 + return (__be32)net_hdr_word(ports);
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
517 +} __attribute__((packed, aligned(2)));
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;
528 +} __attribute__((packed, aligned(2)));
531 struct icmp6hdr icmph;
532 @@ -372,10 +372,10 @@ static inline u32 ndisc_hashfn(const voi
534 const u32 *p32 = pkey;
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]));
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);
553 - if ((*data ^ key->val) & key->mask) {
554 + if ((net_hdr_word(data) ^ key->val) & key->mask) {
555 n = rcu_dereference_bh(n->next);
558 @@ -206,8 +206,8 @@ check_terminal:
562 - sel = ht->divisor & u32_hash_fold(*data, &n->sel,
564 + sel = ht->divisor & u32_hash_fold(net_hdr_word(data),
565 + &n->sel, n->fshift);
567 if (!(n->sel.flags & (TC_U32_VAROFFSET | TC_U32_OFFSET | TC_U32_EAT)))
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 *
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);
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 {
585 struct in6_addr prefix;
587 +} __attribute__((packed, aligned(2)));
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)))
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),
605 --- a/include/net/ipv6.h
606 +++ b/include/net/ipv6.h
607 @@ -146,7 +146,7 @@ struct frag_hdr {
610 __be32 identification;
612 +} __attribute__((packed, aligned(2)));
614 #define IP6_MF 0x0001
615 #define IP6_OFFSET 0xFFF8
616 @@ -560,8 +560,8 @@ static inline void __ipv6_addr_set_half(
622 + net_hdr_word(&addr[0]) = wh;
623 + net_hdr_word(&addr[1]) = wl;
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 */
634 /* check complete u32 in prefix */
635 pdw = prefixlen >> 5;
636 @@ -628,7 +630,9 @@ static inline bool ipv6_prefix_equal(con
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))))
647 @@ -749,13 +753,13 @@ static inline void ipv6_addr_set_v4mappe
649 static inline int __ipv6_addr_diff32(const void *token1, const void *token2, int addrlen)
651 - const __be32 *a1 = token1, *a2 = token2;
652 + const struct in6_addr *a1 = token1, *a2 = token2;
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];
661 return i * 32 + 31 - __fls(ntohl(xb));
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,
667 - *(__be32 *)hdr = htonl(0x60000000 | (tclass << 20)) | flowlabel;
668 + net_hdr_word((__be32 *)hdr) =
669 + htonl(0x60000000 | (tclass << 20)) | flowlabel;
672 static inline __be32 ip6_flowinfo(const struct ipv6hdr *hdr)
674 - return *(__be32 *)hdr & IPV6_FLOWINFO_MASK;
675 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWINFO_MASK;
678 static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
680 - return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
681 + return net_hdr_word((__be32 *)hdr) & IPV6_FLOWLABEL_MASK;
684 static inline u8 ip6_tclass(__be32 flowinfo)
685 --- a/include/net/secure_seq.h
686 +++ b/include/net/secure_seq.h
688 #define _NET_SECURE_SEQ
690 #include <linux/types.h>
691 +#include <linux/in6.h>
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. */
702 +} __attribute__((packed, aligned(2)));
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.
711 return (__force __be32)(1 << ((~fn_bit ^ BITOP_BE32_SWIZZLE) & 0x1f)) &
713 + net_hdr_word(&addr[fn_bit >> 5]);
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
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)
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))
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);
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(
745 const __be32 *ptr = (const __be32 *)(th + 1);
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;
754 - tp->rx_opt.rcv_tsval = ntohl(*ptr);
755 + tp->rx_opt.rcv_tsval = get_unaligned_be32(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) -
763 tp->rx_opt.rcv_tsecr = 0;
765 --- a/include/uapi/linux/if_pppox.h
766 +++ b/include/uapi/linux/if_pppox.h
767 @@ -51,6 +51,7 @@ struct pppoe_addr {
772 struct in_addr sin_addr;
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,
784 - (ntohl(*(__be32 *)ih) & 0x000fffff));
785 + (ntohl(net_hdr_word(ih)) & 0x000fffff));
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;
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;
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 {
811 +} __attribute__((aligned(4)));
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 *
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]),
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 @@ -499,7 +499,7 @@ static inline bool is_etherdev_addr(cons
837 * @b: Pointer to Ethernet header
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
845 @@ -522,11 +522,12 @@ static inline unsigned long compare_ethe
846 fold |= *(unsigned long *)(a + 6) ^ *(unsigned long *)(b + 6);
849 - u32 *a32 = (u32 *)((u8 *)a + 2);
850 - u32 *b32 = (u32 *)((u8 *)b + 2);
851 + const u16 *a16 = a;
852 + const u16 *b16 = b;
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]) |
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
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;
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);
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;
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));
893 ret = ip6t_do_table(skb, state, state->net->ipv6.ip6table_mangle);
895 @@ -56,7 +56,7 @@ ip6t_mangle_out(struct sk_buff *skb, con
896 !ipv6_addr_equal(&ipv6_hdr(skb)->daddr, &daddr) ||
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);
903 ret = NF_DROP_ERR(err);