Commit 50e5d35c authored by Paul Moore's avatar Paul Moore Committed by David S. Miller

[CIPSO]: Fix several unaligned kernel accesses in the CIPSO engine.

IPv4 options are not very well aligned within the packet and the
format of a CIPSO option is even worse.  The result is that the CIPSO
engine in the kernel does a few unaligned accesses when parsing and
validating incoming packets with CIPSO options attached which generate
error messages on certain alignment sensitive platforms.  This patch
fixes this by marking these unaligned accesses with the
get_unaliagned() macro.
Signed-off-by: default avatarPaul Moore <paul.moore@hp.com>
Acked-by: default avatarJames Morris <jmorris@namei.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ba6ff9f2
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <net/cipso_ipv4.h> #include <net/cipso_ipv4.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <asm/bug.h> #include <asm/bug.h>
#include <asm/unaligned.h>
struct cipso_v4_domhsh_entry { struct cipso_v4_domhsh_entry {
char *domain; char *domain;
...@@ -1000,7 +1001,7 @@ static int cipso_v4_map_cat_enum_valid(const struct cipso_v4_doi *doi_def, ...@@ -1000,7 +1001,7 @@ static int cipso_v4_map_cat_enum_valid(const struct cipso_v4_doi *doi_def,
return -EFAULT; return -EFAULT;
for (iter = 0; iter < enumcat_len; iter += 2) { for (iter = 0; iter < enumcat_len; iter += 2) {
cat = ntohs(*((__be16 *)&enumcat[iter])); cat = ntohs(get_unaligned((__be16 *)&enumcat[iter]));
if (cat <= cat_prev) if (cat <= cat_prev)
return -EFAULT; return -EFAULT;
cat_prev = cat; cat_prev = cat;
...@@ -1068,7 +1069,7 @@ static int cipso_v4_map_cat_enum_ntoh(const struct cipso_v4_doi *doi_def, ...@@ -1068,7 +1069,7 @@ static int cipso_v4_map_cat_enum_ntoh(const struct cipso_v4_doi *doi_def,
for (iter = 0; iter < net_cat_len; iter += 2) { for (iter = 0; iter < net_cat_len; iter += 2) {
ret_val = netlbl_secattr_catmap_setbit(secattr->mls_cat, ret_val = netlbl_secattr_catmap_setbit(secattr->mls_cat,
ntohs(*((__be16 *)&net_cat[iter])), ntohs(get_unaligned((__be16 *)&net_cat[iter])),
GFP_ATOMIC); GFP_ATOMIC);
if (ret_val != 0) if (ret_val != 0)
return ret_val; return ret_val;
...@@ -1102,9 +1103,10 @@ static int cipso_v4_map_cat_rng_valid(const struct cipso_v4_doi *doi_def, ...@@ -1102,9 +1103,10 @@ static int cipso_v4_map_cat_rng_valid(const struct cipso_v4_doi *doi_def,
return -EFAULT; return -EFAULT;
for (iter = 0; iter < rngcat_len; iter += 4) { for (iter = 0; iter < rngcat_len; iter += 4) {
cat_high = ntohs(*((__be16 *)&rngcat[iter])); cat_high = ntohs(get_unaligned((__be16 *)&rngcat[iter]));
if ((iter + 4) <= rngcat_len) if ((iter + 4) <= rngcat_len)
cat_low = ntohs(*((__be16 *)&rngcat[iter + 2])); cat_low = ntohs(
get_unaligned((__be16 *)&rngcat[iter + 2]));
else else
cat_low = 0; cat_low = 0;
...@@ -1201,9 +1203,10 @@ static int cipso_v4_map_cat_rng_ntoh(const struct cipso_v4_doi *doi_def, ...@@ -1201,9 +1203,10 @@ static int cipso_v4_map_cat_rng_ntoh(const struct cipso_v4_doi *doi_def,
u16 cat_high; u16 cat_high;
for (net_iter = 0; net_iter < net_cat_len; net_iter += 4) { for (net_iter = 0; net_iter < net_cat_len; net_iter += 4) {
cat_high = ntohs(*((__be16 *)&net_cat[net_iter])); cat_high = ntohs(get_unaligned((__be16 *)&net_cat[net_iter]));
if ((net_iter + 4) <= net_cat_len) if ((net_iter + 4) <= net_cat_len)
cat_low = ntohs(*((__be16 *)&net_cat[net_iter + 2])); cat_low = ntohs(
get_unaligned((__be16 *)&net_cat[net_iter + 2]));
else else
cat_low = 0; cat_low = 0;
...@@ -1565,7 +1568,7 @@ int cipso_v4_validate(unsigned char **option) ...@@ -1565,7 +1568,7 @@ int cipso_v4_validate(unsigned char **option)
} }
rcu_read_lock(); rcu_read_lock();
doi_def = cipso_v4_doi_search(ntohl(*((__be32 *)&opt[2]))); doi_def = cipso_v4_doi_search(ntohl(get_unaligned((__be32 *)&opt[2])));
if (doi_def == NULL) { if (doi_def == NULL) {
err_offset = 2; err_offset = 2;
goto validate_return_locked; goto validate_return_locked;
...@@ -1856,7 +1859,7 @@ int cipso_v4_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr) ...@@ -1856,7 +1859,7 @@ int cipso_v4_sock_getattr(struct sock *sk, struct netlbl_lsm_secattr *secattr)
if (ret_val == 0) if (ret_val == 0)
return ret_val; return ret_val;
doi = ntohl(*(__be32 *)&cipso_ptr[2]); doi = ntohl(get_unaligned((__be32 *)&cipso_ptr[2]));
rcu_read_lock(); rcu_read_lock();
doi_def = cipso_v4_doi_search(doi); doi_def = cipso_v4_doi_search(doi);
if (doi_def == NULL) { if (doi_def == NULL) {
...@@ -1911,7 +1914,7 @@ int cipso_v4_skbuff_getattr(const struct sk_buff *skb, ...@@ -1911,7 +1914,7 @@ int cipso_v4_skbuff_getattr(const struct sk_buff *skb,
if (cipso_v4_cache_check(cipso_ptr, cipso_ptr[1], secattr) == 0) if (cipso_v4_cache_check(cipso_ptr, cipso_ptr[1], secattr) == 0)
return 0; return 0;
doi = ntohl(*(__be32 *)&cipso_ptr[2]); doi = ntohl(get_unaligned((__be32 *)&cipso_ptr[2]));
rcu_read_lock(); rcu_read_lock();
doi_def = cipso_v4_doi_search(doi); doi_def = cipso_v4_doi_search(doi);
if (doi_def == NULL) if (doi_def == NULL)
......
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