Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

gss_krb5: create a define for token header size and clean up ptr location

cleanup:
Document token header size with a #define instead of open-coding it.

Don't needlessly increment "ptr" past the beginning of the header
which makes the values passed to functions more understandable and
eliminates the need for extra "krb5_hdr" pointer.

Clean up some intersecting white-space issues flagged by checkpatch.pl.

This leaves the checksum length hard-coded at 8 for DES. A later patch
cleans that up.

Signed-off-by: Kevin Coffman <kwc@citi.umich.edu>
Signed-off-by: J. Bruce Fields <bfields@citi.umich.edu>

authored by

Kevin Coffman and committed by
J. Bruce Fields
d00953a5 8837abca

+49 -46
+3
include/linux/sunrpc/gss_krb5.h
··· 51 51 52 52 extern spinlock_t krb5_seq_lock; 53 53 54 + /* The length of the Kerberos GSS token header */ 55 + #define GSS_KRB5_TOK_HDR_LEN (16) 56 + 54 57 #define KG_TOK_MIC_MSG 0x0101 55 58 #define KG_TOK_WRAP_MSG 0x0201 56 59
+13 -13
net/sunrpc/auth_gss/gss_krb5_seal.c
··· 78 78 struct krb5_ctx *ctx = gss_ctx->internal_ctx_id; 79 79 char cksumdata[16]; 80 80 struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; 81 - unsigned char *ptr, *krb5_hdr, *msg_start; 81 + unsigned char *ptr, *msg_start; 82 82 s32 now; 83 83 u32 seq_send; 84 84 ··· 87 87 88 88 now = get_seconds(); 89 89 90 - token->len = g_token_size(&ctx->mech_used, 24); 90 + token->len = g_token_size(&ctx->mech_used, GSS_KRB5_TOK_HDR_LEN + 8); 91 91 92 92 ptr = token->data; 93 - g_make_token_header(&ctx->mech_used, 24, &ptr); 93 + g_make_token_header(&ctx->mech_used, GSS_KRB5_TOK_HDR_LEN + 8, &ptr); 94 94 95 - *ptr++ = (unsigned char) ((KG_TOK_MIC_MSG>>8)&0xff); 96 - *ptr++ = (unsigned char) (KG_TOK_MIC_MSG&0xff); 95 + /* ptr now at header described in rfc 1964, section 1.2.1: */ 96 + ptr[0] = (unsigned char) ((KG_TOK_MIC_MSG >> 8) & 0xff); 97 + ptr[1] = (unsigned char) (KG_TOK_MIC_MSG & 0xff); 97 98 98 - /* ptr now at byte 2 of header described in rfc 1964, section 1.2.1: */ 99 - krb5_hdr = ptr - 2; 100 - msg_start = krb5_hdr + 24; 99 + msg_start = ptr + GSS_KRB5_TOK_HDR_LEN + 8; 101 100 102 - *(__be16 *)(krb5_hdr + 2) = htons(SGN_ALG_DES_MAC_MD5); 103 - memset(krb5_hdr + 4, 0xff, 4); 101 + *(__be16 *)(ptr + 2) = htons(SGN_ALG_DES_MAC_MD5); 102 + memset(ptr + 4, 0xff, 4); 104 103 105 - if (make_checksum("md5", krb5_hdr, 8, text, 0, &md5cksum)) 104 + if (make_checksum("md5", ptr, 8, text, 0, &md5cksum)) 106 105 return GSS_S_FAILURE; 107 106 108 107 if (krb5_encrypt(ctx->seq, NULL, md5cksum.data, 109 108 md5cksum.data, md5cksum.len)) 110 109 return GSS_S_FAILURE; 111 110 112 - memcpy(krb5_hdr + 16, md5cksum.data + md5cksum.len - 8, 8); 111 + memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data + md5cksum.len - 8, 8); 113 112 114 113 spin_lock(&krb5_seq_lock); 115 114 seq_send = ctx->seq_send++; 116 115 spin_unlock(&krb5_seq_lock); 117 116 118 117 if (krb5_make_seq_num(ctx->seq, ctx->initiate ? 0 : 0xff, 119 - seq_send, krb5_hdr + 16, krb5_hdr + 8)) 118 + seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, 119 + ptr + 8)) 120 120 return GSS_S_FAILURE; 121 121 122 122 return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
+8 -8
net/sunrpc/auth_gss/gss_krb5_unseal.c
··· 92 92 read_token->len)) 93 93 return GSS_S_DEFECTIVE_TOKEN; 94 94 95 - if ((*ptr++ != ((KG_TOK_MIC_MSG>>8)&0xff)) || 96 - (*ptr++ != ( KG_TOK_MIC_MSG &0xff)) ) 95 + if ((ptr[0] != ((KG_TOK_MIC_MSG >> 8) & 0xff)) || 96 + (ptr[1] != (KG_TOK_MIC_MSG & 0xff))) 97 97 return GSS_S_DEFECTIVE_TOKEN; 98 98 99 99 /* XXX sanity-check bodysize?? */ 100 100 101 - signalg = ptr[0] + (ptr[1] << 8); 101 + signalg = ptr[2] + (ptr[3] << 8); 102 102 if (signalg != SGN_ALG_DES_MAC_MD5) 103 103 return GSS_S_DEFECTIVE_TOKEN; 104 104 105 - sealalg = ptr[2] + (ptr[3] << 8); 105 + sealalg = ptr[4] + (ptr[5] << 8); 106 106 if (sealalg != SEAL_ALG_NONE) 107 107 return GSS_S_DEFECTIVE_TOKEN; 108 108 109 - if ((ptr[4] != 0xff) || (ptr[5] != 0xff)) 109 + if ((ptr[6] != 0xff) || (ptr[7] != 0xff)) 110 110 return GSS_S_DEFECTIVE_TOKEN; 111 111 112 - if (make_checksum("md5", ptr - 2, 8, message_buffer, 0, &md5cksum)) 112 + if (make_checksum("md5", ptr, 8, message_buffer, 0, &md5cksum)) 113 113 return GSS_S_FAILURE; 114 114 115 115 if (krb5_encrypt(ctx->seq, NULL, md5cksum.data, md5cksum.data, 16)) 116 116 return GSS_S_FAILURE; 117 117 118 - if (memcmp(md5cksum.data + 8, ptr + 14, 8)) 118 + if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8)) 119 119 return GSS_S_BAD_SIG; 120 120 121 121 /* it got through unscathed. Make sure the context is unexpired */ ··· 127 127 128 128 /* do sequencing checks */ 129 129 130 - if (krb5_get_seq_num(ctx->seq, ptr + 14, ptr + 6, &direction, &seqnum)) 130 + if (krb5_get_seq_num(ctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8, &direction, &seqnum)) 131 131 return GSS_S_FAILURE; 132 132 133 133 if ((ctx->initiate && direction != 0xff) ||
+25 -25
net/sunrpc/auth_gss/gss_krb5_wrap.c
··· 122 122 char cksumdata[16]; 123 123 struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; 124 124 int blocksize = 0, plainlen; 125 - unsigned char *ptr, *krb5_hdr, *msg_start; 125 + unsigned char *ptr, *msg_start; 126 126 s32 now; 127 127 int headlen; 128 128 struct page **tmp_pages; ··· 149 149 buf->len += headlen; 150 150 BUG_ON((buf->len - offset - headlen) % blocksize); 151 151 152 - g_make_token_header(&kctx->mech_used, 24 + plainlen, &ptr); 152 + g_make_token_header(&kctx->mech_used, 153 + GSS_KRB5_TOK_HDR_LEN + 8 + plainlen, &ptr); 153 154 154 155 155 - *ptr++ = (unsigned char) ((KG_TOK_WRAP_MSG>>8)&0xff); 156 - *ptr++ = (unsigned char) (KG_TOK_WRAP_MSG&0xff); 156 + /* ptr now at header described in rfc 1964, section 1.2.1: */ 157 + ptr[0] = (unsigned char) ((KG_TOK_WRAP_MSG >> 8) & 0xff); 158 + ptr[1] = (unsigned char) (KG_TOK_WRAP_MSG & 0xff); 157 159 158 - /* ptr now at byte 2 of header described in rfc 1964, section 1.2.1: */ 159 - krb5_hdr = ptr - 2; 160 - msg_start = krb5_hdr + 24; 160 + msg_start = ptr + 24; 161 161 162 - *(__be16 *)(krb5_hdr + 2) = htons(SGN_ALG_DES_MAC_MD5); 163 - memset(krb5_hdr + 4, 0xff, 4); 164 - *(__be16 *)(krb5_hdr + 4) = htons(SEAL_ALG_DES); 162 + *(__be16 *)(ptr + 2) = htons(SGN_ALG_DES_MAC_MD5); 163 + memset(ptr + 4, 0xff, 4); 164 + *(__be16 *)(ptr + 4) = htons(SEAL_ALG_DES); 165 165 166 166 make_confounder(msg_start, blocksize); 167 167 168 168 /* XXXJBF: UGH!: */ 169 169 tmp_pages = buf->pages; 170 170 buf->pages = pages; 171 - if (make_checksum("md5", krb5_hdr, 8, buf, 171 + if (make_checksum("md5", ptr, 8, buf, 172 172 offset + headlen - blocksize, &md5cksum)) 173 173 return GSS_S_FAILURE; 174 174 buf->pages = tmp_pages; ··· 176 176 if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, 177 177 md5cksum.data, md5cksum.len)) 178 178 return GSS_S_FAILURE; 179 - memcpy(krb5_hdr + 16, md5cksum.data + md5cksum.len - 8, 8); 179 + memcpy(ptr + GSS_KRB5_TOK_HDR_LEN, md5cksum.data + md5cksum.len - 8, 8); 180 180 181 181 spin_lock(&krb5_seq_lock); 182 182 seq_send = kctx->seq_send++; ··· 185 185 /* XXX would probably be more efficient to compute checksum 186 186 * and encrypt at the same time: */ 187 187 if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff, 188 - seq_send, krb5_hdr + 16, krb5_hdr + 8))) 188 + seq_send, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8))) 189 189 return GSS_S_FAILURE; 190 190 191 191 if (gss_encrypt_xdr_buf(kctx->enc, buf, offset + headlen - blocksize, ··· 219 219 buf->len - offset)) 220 220 return GSS_S_DEFECTIVE_TOKEN; 221 221 222 - if ((*ptr++ != ((KG_TOK_WRAP_MSG>>8)&0xff)) || 223 - (*ptr++ != (KG_TOK_WRAP_MSG &0xff)) ) 222 + if ((ptr[0] != ((KG_TOK_WRAP_MSG >> 8) & 0xff)) || 223 + (ptr[1] != (KG_TOK_WRAP_MSG & 0xff))) 224 224 return GSS_S_DEFECTIVE_TOKEN; 225 225 226 226 /* XXX sanity-check bodysize?? */ 227 227 228 228 /* get the sign and seal algorithms */ 229 229 230 - signalg = ptr[0] + (ptr[1] << 8); 230 + signalg = ptr[2] + (ptr[3] << 8); 231 231 if (signalg != SGN_ALG_DES_MAC_MD5) 232 232 return GSS_S_DEFECTIVE_TOKEN; 233 233 234 - sealalg = ptr[2] + (ptr[3] << 8); 234 + sealalg = ptr[4] + (ptr[5] << 8); 235 235 if (sealalg != SEAL_ALG_DES) 236 236 return GSS_S_DEFECTIVE_TOKEN; 237 237 238 - if ((ptr[4] != 0xff) || (ptr[5] != 0xff)) 238 + if ((ptr[6] != 0xff) || (ptr[7] != 0xff)) 239 239 return GSS_S_DEFECTIVE_TOKEN; 240 240 241 241 if (gss_decrypt_xdr_buf(kctx->enc, buf, 242 - ptr + 22 - (unsigned char *)buf->head[0].iov_base)) 242 + ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base)) 243 243 return GSS_S_DEFECTIVE_TOKEN; 244 244 245 - if (make_checksum("md5", ptr - 2, 8, buf, 246 - ptr + 22 - (unsigned char *)buf->head[0].iov_base, &md5cksum)) 245 + if (make_checksum("md5", ptr, 8, buf, 246 + ptr + GSS_KRB5_TOK_HDR_LEN + 8 - (unsigned char *)buf->head[0].iov_base, &md5cksum)) 247 247 return GSS_S_FAILURE; 248 248 249 249 if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, 250 250 md5cksum.data, md5cksum.len)) 251 251 return GSS_S_FAILURE; 252 252 253 - if (memcmp(md5cksum.data + 8, ptr + 14, 8)) 253 + if (memcmp(md5cksum.data + 8, ptr + GSS_KRB5_TOK_HDR_LEN, 8)) 254 254 return GSS_S_BAD_SIG; 255 255 256 256 /* it got through unscathed. Make sure the context is unexpired */ ··· 262 262 263 263 /* do sequencing checks */ 264 264 265 - if (krb5_get_seq_num(kctx->seq, ptr + 14, ptr + 6, &direction, 266 - &seqnum)) 265 + if (krb5_get_seq_num(kctx->seq, ptr + GSS_KRB5_TOK_HDR_LEN, ptr + 8, 266 + &direction, &seqnum)) 267 267 return GSS_S_BAD_SIG; 268 268 269 269 if ((kctx->initiate && direction != 0xff) || ··· 274 274 * better to copy and encrypt at the same time. */ 275 275 276 276 blocksize = crypto_blkcipher_blocksize(kctx->enc); 277 - data_start = ptr + 22 + blocksize; 277 + data_start = ptr + GSS_KRB5_TOK_HDR_LEN + 8 + blocksize; 278 278 orig_start = buf->head[0].iov_base + offset; 279 279 data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start; 280 280 memmove(orig_start, data_start, data_len);