diff options
author | Chris Metcalf <cmetcalf@tilera.com> | 2011-05-29 06:55:44 -0400 |
---|---|---|
committer | David S. Miller <davem@zippy.davemloft.net> | 2011-05-31 18:11:02 -0400 |
commit | 48bdf072c3f1f8f739f76d19c74f4c79605cac46 (patch) | |
tree | 0cf0f1600892a781949451df0087b2407522a5ed /net/ipv4/ip_options.c | |
parent | 11ad2f52826ac6d58d6780d3d8a3e098c88d9142 (diff) |
ip_options_compile: properly handle unaligned pointer
The current code takes an unaligned pointer and does htonl() on it to
make it big-endian, then does a memcpy(). The problem is that the
compiler decides that since the pointer is to a __be32, it is legal
to optimize the copy into a processor word store. However, on an
architecture that does not handled unaligned writes in kernel space,
this produces an unaligned exception fault.
The solution is to track the pointer as a "char *" (which removes a bunch
of unpleasant casts in any case), and then just use put_unaligned_be32()
to write the value to memory.
Signed-off-by: Chris Metcalf <cmetcalf@tilera.com>
Signed-off-by: David S. Miller <davem@zippy.davemloft.net>
Diffstat (limited to 'net/ipv4/ip_options.c')
-rw-r--r-- | net/ipv4/ip_options.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/net/ipv4/ip_options.c b/net/ipv4/ip_options.c index c3118e1cd3bb..ec93335901dd 100644 --- a/net/ipv4/ip_options.c +++ b/net/ipv4/ip_options.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/slab.h> | 14 | #include <linux/slab.h> |
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <asm/uaccess.h> | 16 | #include <asm/uaccess.h> |
17 | #include <asm/unaligned.h> | ||
17 | #include <linux/skbuff.h> | 18 | #include <linux/skbuff.h> |
18 | #include <linux/ip.h> | 19 | #include <linux/ip.h> |
19 | #include <linux/icmp.h> | 20 | #include <linux/icmp.h> |
@@ -350,7 +351,7 @@ int ip_options_compile(struct net *net, | |||
350 | goto error; | 351 | goto error; |
351 | } | 352 | } |
352 | if (optptr[2] <= optlen) { | 353 | if (optptr[2] <= optlen) { |
353 | __be32 *timeptr = NULL; | 354 | unsigned char *timeptr = NULL; |
354 | if (optptr[2]+3 > optptr[1]) { | 355 | if (optptr[2]+3 > optptr[1]) { |
355 | pp_ptr = optptr + 2; | 356 | pp_ptr = optptr + 2; |
356 | goto error; | 357 | goto error; |
@@ -359,7 +360,7 @@ int ip_options_compile(struct net *net, | |||
359 | case IPOPT_TS_TSONLY: | 360 | case IPOPT_TS_TSONLY: |
360 | opt->ts = optptr - iph; | 361 | opt->ts = optptr - iph; |
361 | if (skb) | 362 | if (skb) |
362 | timeptr = (__be32*)&optptr[optptr[2]-1]; | 363 | timeptr = &optptr[optptr[2]-1]; |
363 | opt->ts_needtime = 1; | 364 | opt->ts_needtime = 1; |
364 | optptr[2] += 4; | 365 | optptr[2] += 4; |
365 | break; | 366 | break; |
@@ -371,7 +372,7 @@ int ip_options_compile(struct net *net, | |||
371 | opt->ts = optptr - iph; | 372 | opt->ts = optptr - iph; |
372 | if (rt) { | 373 | if (rt) { |
373 | memcpy(&optptr[optptr[2]-1], &rt->rt_spec_dst, 4); | 374 | memcpy(&optptr[optptr[2]-1], &rt->rt_spec_dst, 4); |
374 | timeptr = (__be32*)&optptr[optptr[2]+3]; | 375 | timeptr = &optptr[optptr[2]+3]; |
375 | } | 376 | } |
376 | opt->ts_needaddr = 1; | 377 | opt->ts_needaddr = 1; |
377 | opt->ts_needtime = 1; | 378 | opt->ts_needtime = 1; |
@@ -389,7 +390,7 @@ int ip_options_compile(struct net *net, | |||
389 | if (inet_addr_type(net, addr) == RTN_UNICAST) | 390 | if (inet_addr_type(net, addr) == RTN_UNICAST) |
390 | break; | 391 | break; |
391 | if (skb) | 392 | if (skb) |
392 | timeptr = (__be32*)&optptr[optptr[2]+3]; | 393 | timeptr = &optptr[optptr[2]+3]; |
393 | } | 394 | } |
394 | opt->ts_needtime = 1; | 395 | opt->ts_needtime = 1; |
395 | optptr[2] += 8; | 396 | optptr[2] += 8; |
@@ -403,10 +404,10 @@ int ip_options_compile(struct net *net, | |||
403 | } | 404 | } |
404 | if (timeptr) { | 405 | if (timeptr) { |
405 | struct timespec tv; | 406 | struct timespec tv; |
406 | __be32 midtime; | 407 | u32 midtime; |
407 | getnstimeofday(&tv); | 408 | getnstimeofday(&tv); |
408 | midtime = htonl((tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC); | 409 | midtime = (tv.tv_sec % 86400) * MSEC_PER_SEC + tv.tv_nsec / NSEC_PER_MSEC; |
409 | memcpy(timeptr, &midtime, sizeof(__be32)); | 410 | put_unaligned_be32(midtime, timeptr); |
410 | opt->is_changed = 1; | 411 | opt->is_changed = 1; |
411 | } | 412 | } |
412 | } else { | 413 | } else { |