diff options
Diffstat (limited to 'net/sunrpc/auth_gss/gss_krb5_wrap.c')
-rw-r--r-- | net/sunrpc/auth_gss/gss_krb5_wrap.c | 72 |
1 files changed, 43 insertions, 29 deletions
diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c index b00b1b42630..ae8e69b59c4 100644 --- a/net/sunrpc/auth_gss/gss_krb5_wrap.c +++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c | |||
@@ -87,8 +87,8 @@ out: | |||
87 | return 0; | 87 | return 0; |
88 | } | 88 | } |
89 | 89 | ||
90 | static inline void | 90 | static void |
91 | make_confounder(char *p, int blocksize) | 91 | make_confounder(char *p, u32 conflen) |
92 | { | 92 | { |
93 | static u64 i = 0; | 93 | static u64 i = 0; |
94 | u64 *q = (u64 *)p; | 94 | u64 *q = (u64 *)p; |
@@ -102,8 +102,22 @@ make_confounder(char *p, int blocksize) | |||
102 | * uniqueness would mean worrying about atomicity and rollover, and I | 102 | * uniqueness would mean worrying about atomicity and rollover, and I |
103 | * don't care enough. */ | 103 | * don't care enough. */ |
104 | 104 | ||
105 | BUG_ON(blocksize != 8); | 105 | /* initialize to random value */ |
106 | *q = i++; | 106 | if (i == 0) { |
107 | i = random32(); | ||
108 | i = (i << 32) | random32(); | ||
109 | } | ||
110 | |||
111 | switch (conflen) { | ||
112 | case 16: | ||
113 | *q++ = i++; | ||
114 | /* fall through */ | ||
115 | case 8: | ||
116 | *q++ = i++; | ||
117 | break; | ||
118 | default: | ||
119 | BUG(); | ||
120 | } | ||
107 | } | 121 | } |
108 | 122 | ||
109 | /* Assumptions: the head and tail of inbuf are ours to play with. | 123 | /* Assumptions: the head and tail of inbuf are ours to play with. |
@@ -122,7 +136,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, | |||
122 | char cksumdata[16]; | 136 | char cksumdata[16]; |
123 | struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; | 137 | struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; |
124 | int blocksize = 0, plainlen; | 138 | int blocksize = 0, plainlen; |
125 | unsigned char *ptr, *krb5_hdr, *msg_start; | 139 | unsigned char *ptr, *msg_start; |
126 | s32 now; | 140 | s32 now; |
127 | int headlen; | 141 | int headlen; |
128 | struct page **tmp_pages; | 142 | struct page **tmp_pages; |
@@ -149,26 +163,26 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, | |||
149 | buf->len += headlen; | 163 | buf->len += headlen; |
150 | BUG_ON((buf->len - offset - headlen) % blocksize); | 164 | BUG_ON((buf->len - offset - headlen) % blocksize); |
151 | 165 | ||
152 | g_make_token_header(&kctx->mech_used, 24 + plainlen, &ptr); | 166 | g_make_token_header(&kctx->mech_used, |
167 | GSS_KRB5_TOK_HDR_LEN + 8 + plainlen, &ptr); | ||
153 | 168 | ||
154 | 169 | ||
155 | *ptr++ = (unsigned char) ((KG_TOK_WRAP_MSG>>8)&0xff); | 170 | /* ptr now at header described in rfc 1964, section 1.2.1: */ |
156 | *ptr++ = (unsigned char) (KG_TOK_WRAP_MSG&0xff); | 171 | ptr[0] = (unsigned char) ((KG_TOK_WRAP_MSG >> 8) & 0xff); |
172 | ptr[1] = (unsigned char) (KG_TOK_WRAP_MSG & 0xff); | ||
157 | 173 | ||
158 | /* ptr now at byte 2 of header described in rfc 1964, section 1.2.1: */ | 174 | msg_start = ptr + 24; |
159 | krb5_hdr = ptr - 2; | ||
160 | msg_start = krb5_hdr + 24; | ||
161 | 175 | ||
162 | *(__be16 *)(krb5_hdr + 2) = htons(SGN_ALG_DES_MAC_MD5); | 176 | *(__be16 *)(ptr + 2) = htons(SGN_ALG_DES_MAC_MD5); |
163 | memset(krb5_hdr + 4, 0xff, 4); | 177 | memset(ptr + 4, 0xff, 4); |
164 | *(__be16 *)(krb5_hdr + 4) = htons(SEAL_ALG_DES); | 178 | *(__be16 *)(ptr + 4) = htons(SEAL_ALG_DES); |
165 | 179 | ||
166 | make_confounder(msg_start, blocksize); | 180 | make_confounder(msg_start, blocksize); |
167 | 181 | ||
168 | /* XXXJBF: UGH!: */ | 182 | /* XXXJBF: UGH!: */ |
169 | tmp_pages = buf->pages; | 183 | tmp_pages = buf->pages; |
170 | buf->pages = pages; | 184 | buf->pages = pages; |
171 | if (make_checksum("md5", krb5_hdr, 8, buf, | 185 | if (make_checksum("md5", ptr, 8, buf, |
172 | offset + headlen - blocksize, &md5cksum)) | 186 | offset + headlen - blocksize, &md5cksum)) |
173 | return GSS_S_FAILURE; | 187 | return GSS_S_FAILURE; |
174 | buf->pages = tmp_pages; | 188 | buf->pages = tmp_pages; |
@@ -176,7 +190,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, | |||
176 | if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, | 190 | if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, |
177 | md5cksum.data, md5cksum.len)) | 191 | md5cksum.data, md5cksum.len)) |
178 | return GSS_S_FAILURE; | 192 | return GSS_S_FAILURE; |
179 | memcpy(krb5_hdr + 16, md5cksum.data + md5cksum.len - 8, 8); | 193 | memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data + md5cksum.len - 8, 8); |
180 | 194 | ||
181 | spin_lock(&krb5_seq_lock); | 195 | spin_lock(&krb5_seq_lock); |
182 | seq_send = kctx->seq_send++; | 196 | seq_send = kctx->seq_send++; |
@@ -185,7 +199,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, | |||
185 | /* XXX would probably be more efficient to compute checksum | 199 | /* XXX would probably be more efficient to compute checksum |
186 | * and encrypt at the same time: */ | 200 | * and encrypt at the same time: */ |
187 | if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff, | 201 | if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff, |
188 | seq_send, krb5_hdr + 16, krb5_hdr + 8))) | 202 | seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8))) |
189 | return GSS_S_FAILURE; | 203 | return GSS_S_FAILURE; |
190 | 204 | ||
191 | if (gss_encrypt_xdr_buf(kctx->enc, buf, offset + headlen - blocksize, | 205 | if (gss_encrypt_xdr_buf(kctx->enc, buf, offset + headlen - blocksize, |
@@ -219,38 +233,38 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf) | |||
219 | buf->len - offset)) | 233 | buf->len - offset)) |
220 | return GSS_S_DEFECTIVE_TOKEN; | 234 | return GSS_S_DEFECTIVE_TOKEN; |
221 | 235 | ||
222 | if ((*ptr++ != ((KG_TOK_WRAP_MSG>>8)&0xff)) || | 236 | if ((ptr[0] != ((KG_TOK_WRAP_MSG >> 8) & 0xff)) || |
223 | (*ptr++ != (KG_TOK_WRAP_MSG &0xff)) ) | 237 | (ptr[1] != (KG_TOK_WRAP_MSG & 0xff))) |
224 | return GSS_S_DEFECTIVE_TOKEN; | 238 | return GSS_S_DEFECTIVE_TOKEN; |
225 | 239 | ||
226 | /* XXX sanity-check bodysize?? */ | 240 | /* XXX sanity-check bodysize?? */ |
227 | 241 | ||
228 | /* get the sign and seal algorithms */ | 242 | /* get the sign and seal algorithms */ |
229 | 243 | ||
230 | signalg = ptr[0] + (ptr[1] << 8); | 244 | signalg = ptr[2] + (ptr[3] << 8); |
231 | if (signalg != SGN_ALG_DES_MAC_MD5) | 245 | if (signalg != SGN_ALG_DES_MAC_MD5) |
232 | return GSS_S_DEFECTIVE_TOKEN; | 246 | return GSS_S_DEFECTIVE_TOKEN; |
233 | 247 | ||
234 | sealalg = ptr[2] + (ptr[3] << 8); | 248 | sealalg = ptr[4] + (ptr[5] << 8); |
235 | if (sealalg != SEAL_ALG_DES) | 249 | if (sealalg != SEAL_ALG_DES) |
236 | return GSS_S_DEFECTIVE_TOKEN; | 250 | return GSS_S_DEFECTIVE_TOKEN; |
237 | 251 | ||
238 | if ((ptr[4] != 0xff) || (ptr[5] != 0xff)) | 252 | if ((ptr[6] != 0xff) || (ptr[7] != 0xff)) |
239 | return GSS_S_DEFECTIVE_TOKEN; | 253 | return GSS_S_DEFECTIVE_TOKEN; |
240 | 254 | ||
241 | if (gss_decrypt_xdr_buf(kctx->enc, buf, | 255 | if (gss_decrypt_xdr_buf(kctx->enc, buf, |
242 | ptr + 22 - (unsigned char *)buf->head[0].iov_base)) | 256 | ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base)) |
243 | return GSS_S_DEFECTIVE_TOKEN; | 257 | return GSS_S_DEFECTIVE_TOKEN; |
244 | 258 | ||
245 | if (make_checksum("md5", ptr - 2, 8, buf, | 259 | if (make_checksum("md5", ptr, 8, buf, |
246 | ptr + 22 - (unsigned char *)buf->head[0].iov_base, &md5cksum)) | 260 | ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base, &md5cksum)) |
247 | return GSS_S_FAILURE; | 261 | return GSS_S_FAILURE; |
248 | 262 | ||
249 | if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, | 263 | if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, |
250 | md5cksum.data, md5cksum.len)) | 264 | md5cksum.data, md5cksum.len)) |
251 | return GSS_S_FAILURE; | 265 | return GSS_S_FAILURE; |
252 | 266 | ||
253 | if (memcmp(md5cksum.data + 8, ptr + 14, 8)) | 267 | if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8)) |
254 | return GSS_S_BAD_SIG; | 268 | return GSS_S_BAD_SIG; |
255 | 269 | ||
256 | /* it got through unscathed. Make sure the context is unexpired */ | 270 | /* it got through unscathed. Make sure the context is unexpired */ |
@@ -262,8 +276,8 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf) | |||
262 | 276 | ||
263 | /* do sequencing checks */ | 277 | /* do sequencing checks */ |
264 | 278 | ||
265 | if (krb5_get_seq_num(kctx->seq, ptr + 14, ptr + 6, &direction, | 279 | if (krb5_get_seq_num(kctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8, |
266 | &seqnum)) | 280 | &direction, &seqnum)) |
267 | return GSS_S_BAD_SIG; | 281 | return GSS_S_BAD_SIG; |
268 | 282 | ||
269 | if ((kctx->initiate && direction != 0xff) || | 283 | if ((kctx->initiate && direction != 0xff) || |
@@ -274,7 +288,7 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf) | |||
274 | * better to copy and encrypt at the same time. */ | 288 | * better to copy and encrypt at the same time. */ |
275 | 289 | ||
276 | blocksize = crypto_blkcipher_blocksize(kctx->enc); | 290 | blocksize = crypto_blkcipher_blocksize(kctx->enc); |
277 | data_start = ptr + 22 + blocksize; | 291 | data_start = ptr + GSS_KRB5_TOK_HDR_LEN + 8 + blocksize; |
278 | orig_start = buf->head[0].iov_base + offset; | 292 | orig_start = buf->head[0].iov_base + offset; |
279 | data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start; | 293 | data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start; |
280 | memmove(orig_start, data_start, data_len); | 294 | memmove(orig_start, data_start, data_len); |