cfg80211: fix race condition with wiphy_apply_custom_regulatory()
[safe/jmp/linux-2.6] / net / rxrpc / rxkad.c
index eebefb6..ef8f910 100644 (file)
@@ -31,7 +31,7 @@
 
 unsigned rxrpc_debug;
 module_param_named(debug, rxrpc_debug, uint, S_IWUSR | S_IRUGO);
-MODULE_PARM_DESC(rxrpc_debug, "rxkad debugging mask");
+MODULE_PARM_DESC(debug, "rxkad debugging mask");
 
 struct rxkad_level1_hdr {
        __be32  data_size;      /* true data size (excluding padding) */
@@ -237,7 +237,8 @@ static int rxkad_secure_packet_encrypt(const struct rxrpc_call *call,
        len = data_size + call->conn->size_align - 1;
        len &= ~(call->conn->size_align - 1);
 
-       sg_init_table(sg, skb_to_sgvec(skb, sg, 0, len));
+       sg_init_table(sg, nsg);
+       skb_to_sgvec(skb, sg, 0, len);
        crypto_blkcipher_encrypt_iv(&desc, sg, sg, len);
 
        _leave(" = 0");
@@ -260,6 +261,7 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
                __be32 x[2];
        } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
        __be32 x;
+       u32 y;
        int ret;
 
        sp = rxrpc_skb(skb);
@@ -283,7 +285,7 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
 
        /* calculate the security checksum */
        x = htonl(call->channel << (32 - RXRPC_CIDSHIFT));
-       x |= sp->hdr.seq & __constant_cpu_to_be32(0x3fffffff);
+       x |= sp->hdr.seq & cpu_to_be32(0x3fffffff);
        tmpbuf.x[0] = sp->hdr.callNumber;
        tmpbuf.x[1] = x;
 
@@ -291,11 +293,11 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
        sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
        crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf));
 
-       x = ntohl(tmpbuf.x[1]);
-       x = (x >> 16) & 0xffff;
-       if (x == 0)
-               x = 1; /* zero checksums are not permitted */
-       sp->hdr.cksum = htons(x);
+       y = ntohl(tmpbuf.x[1]);
+       y = (y >> 16) & 0xffff;
+       if (y == 0)
+               y = 1; /* zero checksums are not permitted */
+       sp->hdr.cksum = htons(y);
 
        switch (call->conn->security_level) {
        case RXRPC_SECURITY_PLAIN:
@@ -313,7 +315,7 @@ static int rxkad_secure_packet(const struct rxrpc_call *call,
                break;
        }
 
-       _leave(" = %d [set %hx]", ret, x);
+       _leave(" = %d [set %hx]", ret, y);
        return ret;
 }
 
@@ -344,7 +346,7 @@ static int rxkad_verify_packet_auth(const struct rxrpc_call *call,
                goto nomem;
 
        sg_init_table(sg, nsg);
-       sg_mark_end(sg, skb_to_sgvec(skb, sg, 0, 8));
+       skb_to_sgvec(skb, sg, 0, 8);
 
        /* start the decryption afresh */
        memset(&iv, 0, sizeof(iv));
@@ -426,7 +428,7 @@ static int rxkad_verify_packet_encrypt(const struct rxrpc_call *call,
        }
 
        sg_init_table(sg, nsg);
-       sg_mark_end(sg, skb_to_sgvec(skb, sg, 0, skb->len));
+       skb_to_sgvec(skb, sg, 0, skb->len);
 
        /* decrypt from the session key */
        payload = call->conn->key->payload.data;
@@ -492,6 +494,7 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
        } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
        __be32 x;
        __be16 cksum;
+       u32 y;
        int ret;
 
        sp = rxrpc_skb(skb);
@@ -517,7 +520,7 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
 
        /* validate the security checksum */
        x = htonl(call->channel << (32 - RXRPC_CIDSHIFT));
-       x |= sp->hdr.seq & __constant_cpu_to_be32(0x3fffffff);
+       x |= sp->hdr.seq & cpu_to_be32(0x3fffffff);
        tmpbuf.x[0] = call->call_id;
        tmpbuf.x[1] = x;
 
@@ -525,12 +528,12 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
        sg_init_one(&sg[1], &tmpbuf, sizeof(tmpbuf));
        crypto_blkcipher_encrypt_iv(&desc, &sg[0], &sg[1], sizeof(tmpbuf));
 
-       x = ntohl(tmpbuf.x[1]);
-       x = (x >> 16) & 0xffff;
-       if (x == 0)
-               x = 1; /* zero checksums are not permitted */
+       y = ntohl(tmpbuf.x[1]);
+       y = (y >> 16) & 0xffff;
+       if (y == 0)
+               y = 1; /* zero checksums are not permitted */
 
-       cksum = htons(x);
+       cksum = htons(y);
        if (sp->hdr.cksum != cksum) {
                *_abort_code = RXKADSEALEDINCON;
                _leave(" = -EPROTO [csum failed]");
@@ -701,7 +704,7 @@ static void rxkad_sg_set_buf2(struct scatterlist sg[2],
                nsg++;
        }
 
-       sg_mark_end(sg, nsg);
+       sg_mark_end(&sg[nsg - 1]);
 
        ASSERTCMP(sg[0].length + sg[1].length, ==, buflen);
 }
@@ -894,7 +897,7 @@ static int rxkad_decrypt_ticket(struct rxrpc_connection *conn,
        /* get the IPv4 address of the entity that requested the ticket */
        memcpy(&addr, p, sizeof(addr));
        p += 4;
-       _debug("KIV ADDR : "NIPQUAD_FMT, NIPQUAD(addr));
+       _debug("KIV ADDR : %pI4", &addr);
 
        /* get the session key from the ticket */
        memcpy(&key, p, sizeof(key));
@@ -1000,7 +1003,8 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
        struct rxrpc_crypt session_key;
        time_t expiry;
        void *ticket;
-       u32 abort_code, version, kvno, ticket_len, csum, level;
+       u32 abort_code, version, kvno, ticket_len, level;
+       __be32 csum;
        int ret;
 
        _enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key));
@@ -1020,6 +1024,7 @@ static int rxkad_verify_response(struct rxrpc_connection *conn,
 
        abort_code = RXKADINCONSISTENCY;
        if (version != RXKAD_VERSION)
+               goto protocol_error;
 
        abort_code = RXKADTICKETLEN;
        if (ticket_len < 4 || ticket_len > MAXKRB5TICKETLEN)