[IPSEC]: Disallow combinations of RO and AH/ESP/IPCOMP
authorHerbert Xu <herbert@gondor.apana.org.au>
Thu, 18 Oct 2007 04:35:15 +0000 (21:35 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 18 Oct 2007 04:35:15 +0000 (21:35 -0700)
Combining RO and AH/ESP/IPCOMP does not make sense.  So this patch adds a
check in the state initialisation function to prevent this.

This allows us to safely remove the mode input function of RO since it
can never be called anymore.  Indeed, if somehow it does get called we'll
know about it through an OOPS instead of it slipping past silently.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv6/ah6.c
net/ipv6/esp6.c
net/ipv6/ipcomp6.c
net/ipv6/xfrm6_mode_ro.c

index a8221d1..67cd066 100644 (file)
@@ -477,8 +477,15 @@ static int ah6_init_state(struct xfrm_state *x)
 
        x->props.header_len = XFRM_ALIGN8(sizeof(struct ip_auth_hdr) +
                                          ahp->icv_trunc_len);
-       if (x->props.mode == XFRM_MODE_TUNNEL)
+       switch (x->props.mode) {
+       case XFRM_MODE_BEET:
+       case XFRM_MODE_TRANSPORT:
+               break;
+       case XFRM_MODE_TUNNEL:
                x->props.header_len += sizeof(struct ipv6hdr);
+       default:
+               goto error;
+       }
        x->data = ahp;
 
        return 0;
index 9eb9285..b071543 100644 (file)
@@ -354,8 +354,15 @@ static int esp6_init_state(struct xfrm_state *x)
                                    (x->ealg->alg_key_len + 7) / 8))
                goto error;
        x->props.header_len = sizeof(struct ip_esp_hdr) + esp->conf.ivlen;
-       if (x->props.mode == XFRM_MODE_TUNNEL)
+       switch (x->props.mode) {
+       case XFRM_MODE_BEET:
+       case XFRM_MODE_TRANSPORT:
+               break;
+       case XFRM_MODE_TUNNEL:
                x->props.header_len += sizeof(struct ipv6hdr);
+       default:
+               goto error;
+       }
        x->data = esp;
        return 0;
 
index 28fc8ed..80ef2a1 100644 (file)
@@ -411,8 +411,15 @@ static int ipcomp6_init_state(struct xfrm_state *x)
                goto out;
 
        x->props.header_len = 0;
-       if (x->props.mode == XFRM_MODE_TUNNEL)
+       switch (x->props.mode) {
+       case XFRM_MODE_BEET:
+       case XFRM_MODE_TRANSPORT:
+               break;
+       case XFRM_MODE_TUNNEL:
                x->props.header_len += sizeof(struct ipv6hdr);
+       default:
+               goto error;
+       }
 
        mutex_lock(&ipcomp6_resource_mutex);
        if (!ipcomp6_alloc_scratches())
index 957ae36..a7bc8c6 100644 (file)
@@ -58,16 +58,7 @@ static int xfrm6_ro_output(struct xfrm_state *x, struct sk_buff *skb)
        return 0;
 }
 
-/*
- * Do nothing about routing optimization header unlike IPsec.
- */
-static int xfrm6_ro_input(struct xfrm_state *x, struct sk_buff *skb)
-{
-       return 0;
-}
-
 static struct xfrm_mode xfrm6_ro_mode = {
-       .input = xfrm6_ro_input,
        .output = xfrm6_ro_output,
        .owner = THIS_MODULE,
        .encap = XFRM_MODE_ROUTEOPTIMIZATION,