Commit c149bdad authored by Sven Henkel's avatar Sven Henkel Committed by David S. Miller

[TCP]: Use get_unaligned() in tcp_parse_options()

TCP options are not guaranteed to be aligned at all, so we should use
get_unaligned when accessing u16- or u32-values in the TCP
options header to avoid alignment errors on some platforms. The patch
applies to vanilla 2.6.11.
Signed-off-by: default avatarSven Henkel <shenkel@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 818a9ce8
......@@ -71,6 +71,7 @@
#include <net/tcp.h>
#include <net/inet_common.h>
#include <linux/ipsec.h>
#include <asm/unaligned.h>
int sysctl_tcp_timestamps = 1;
int sysctl_tcp_window_scaling = 1;
......@@ -3007,7 +3008,7 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
switch(opcode) {
case TCPOPT_MSS:
if(opsize==TCPOLEN_MSS && th->syn && !estab) {
u16 in_mss = ntohs(*(__u16 *)ptr);
u16 in_mss = ntohs(get_unaligned((__u16 *)ptr));
if (in_mss) {
if (opt_rx->user_mss && opt_rx->user_mss < in_mss)
in_mss = opt_rx->user_mss;
......@@ -3034,8 +3035,8 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
if ((estab && opt_rx->tstamp_ok) ||
(!estab && sysctl_tcp_timestamps)) {
opt_rx->saw_tstamp = 1;
opt_rx->rcv_tsval = ntohl(*(__u32 *)ptr);
opt_rx->rcv_tsecr = ntohl(*(__u32 *)(ptr+4));
opt_rx->rcv_tsval = ntohl(get_unaligned((__u32 *)ptr));
opt_rx->rcv_tsecr = ntohl(get_unaligned((__u32 *)(ptr+4)));
}
}
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment