Commit 0d3d077c authored by Herbert Xu's avatar Herbert Xu Committed by David S. Miller

[SELINUX]: Fix ipv6_skip_exthdr() invocation causing OOPS.

The SELinux hooks invoke ipv6_skip_exthdr() with an incorrect
length final argument.  However, the length argument turns out
to be superfluous.

I was just reading ipv6_skip_exthdr and it occured to me that we can
get rid of len altogether.  The only place where len is used is to
check whether the skb has two bytes for ipv6_opt_hdr.  This check
is done by skb_header_pointer/skb_copy_bits anyway.

Now it might appear that we've made the code slower by deferring
the check to skb_copy_bits.  However, this check should not trigger
in the common case so this is OK.
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent aa77d269
...@@ -416,7 +416,7 @@ extern void ipv6_push_frag_opts(struct sk_buff *skb, ...@@ -416,7 +416,7 @@ extern void ipv6_push_frag_opts(struct sk_buff *skb,
u8 *proto); u8 *proto);
extern int ipv6_skip_exthdr(const struct sk_buff *, int start, extern int ipv6_skip_exthdr(const struct sk_buff *, int start,
u8 *nexthdrp, int len); u8 *nexthdrp);
extern int ipv6_ext_hdr(u8 nexthdr); extern int ipv6_ext_hdr(u8 nexthdr);
......
...@@ -41,8 +41,8 @@ int ipv6_ext_hdr(u8 nexthdr) ...@@ -41,8 +41,8 @@ int ipv6_ext_hdr(u8 nexthdr)
* when Linux implements ESP (and maybe AUTH) headers. * when Linux implements ESP (and maybe AUTH) headers.
* --AK * --AK
* *
* This function parses (probably truncated) exthdr set "hdr" * This function parses (probably truncated) exthdr set "hdr".
* of length "len". "nexthdrp" initially points to some place, * "nexthdrp" initially points to some place,
* where type of the first header can be found. * where type of the first header can be found.
* *
* It skips all well-known exthdrs, and returns pointer to the start * It skips all well-known exthdrs, and returns pointer to the start
...@@ -63,7 +63,7 @@ int ipv6_ext_hdr(u8 nexthdr) ...@@ -63,7 +63,7 @@ int ipv6_ext_hdr(u8 nexthdr)
* --ANK (980726) * --ANK (980726)
*/ */
int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, int len) int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp)
{ {
u8 nexthdr = *nexthdrp; u8 nexthdr = *nexthdrp;
...@@ -71,13 +71,11 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, int len ...@@ -71,13 +71,11 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, int len
struct ipv6_opt_hdr _hdr, *hp; struct ipv6_opt_hdr _hdr, *hp;
int hdrlen; int hdrlen;
if (len < (int)sizeof(struct ipv6_opt_hdr))
return -1;
if (nexthdr == NEXTHDR_NONE) if (nexthdr == NEXTHDR_NONE)
return -1; return -1;
hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr); hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
if (hp == NULL) if (hp == NULL)
BUG(); return -1;
if (nexthdr == NEXTHDR_FRAGMENT) { if (nexthdr == NEXTHDR_FRAGMENT) {
unsigned short _frag_off, *fp; unsigned short _frag_off, *fp;
fp = skb_header_pointer(skb, fp = skb_header_pointer(skb,
...@@ -97,7 +95,6 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, int len ...@@ -97,7 +95,6 @@ int ipv6_skip_exthdr(const struct sk_buff *skb, int start, u8 *nexthdrp, int len
hdrlen = ipv6_optlen(hp); hdrlen = ipv6_optlen(hp);
nexthdr = hp->nexthdr; nexthdr = hp->nexthdr;
len -= hdrlen;
start += hdrlen; start += hdrlen;
} }
......
...@@ -135,7 +135,7 @@ static int is_ineligible(struct sk_buff *skb) ...@@ -135,7 +135,7 @@ static int is_ineligible(struct sk_buff *skb)
if (len < 0) if (len < 0)
return 1; return 1;
ptr = ipv6_skip_exthdr(skb, ptr, &nexthdr, len); ptr = ipv6_skip_exthdr(skb, ptr, &nexthdr);
if (ptr < 0) if (ptr < 0)
return 0; return 0;
if (nexthdr == IPPROTO_ICMPV6) { if (nexthdr == IPPROTO_ICMPV6) {
...@@ -514,7 +514,7 @@ static void icmpv6_notify(struct sk_buff *skb, int type, int code, u32 info) ...@@ -514,7 +514,7 @@ static void icmpv6_notify(struct sk_buff *skb, int type, int code, u32 info)
nexthdr = ((struct ipv6hdr *)skb->data)->nexthdr; nexthdr = ((struct ipv6hdr *)skb->data)->nexthdr;
if (ipv6_ext_hdr(nexthdr)) { if (ipv6_ext_hdr(nexthdr)) {
/* now skip over extension headers */ /* now skip over extension headers */
inner_offset = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &nexthdr, skb->len - sizeof(struct ipv6hdr)); inner_offset = ipv6_skip_exthdr(skb, sizeof(struct ipv6hdr), &nexthdr);
if (inner_offset<0) if (inner_offset<0)
return; return;
} else { } else {
......
...@@ -2855,8 +2855,7 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb, struct avc_audit_data *ad ...@@ -2855,8 +2855,7 @@ static int selinux_parse_skb_ipv6(struct sk_buff *skb, struct avc_audit_data *ad
nexthdr = ip6->nexthdr; nexthdr = ip6->nexthdr;
offset += sizeof(_ipv6h); offset += sizeof(_ipv6h);
offset = ipv6_skip_exthdr(skb, offset, &nexthdr, offset = ipv6_skip_exthdr(skb, offset, &nexthdr);
skb->tail - skb->head - offset);
if (offset < 0) if (offset < 0)
goto out; goto out;
......
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