910-unaligned_access_hacks.patch 27 KB

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