Skip to content

Commit 31c9590

Browse files
committed
SUNRPC: Add "@len" parameter to gss_unwrap()
Refactor: This is a pre-requisite to fixing the client-side ralign computation in gss_unwrap_resp_priv(). The length value is passed in explicitly rather that as the value of buf->len. This will subsequently allow gss_unwrap_kerberos_v1() to compute a slack and align value, instead of computing it in gss_unwrap_resp_priv(). Fixes: 35e77d2 ("SUNRPC: Add rpc_auth::au_ralign field") Signed-off-by: Chuck Lever <[email protected]>
1 parent 6a8b55e commit 31c9590

File tree

7 files changed

+30
-27
lines changed

7 files changed

+30
-27
lines changed

include/linux/sunrpc/gss_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ u32 gss_wrap(
6666
u32 gss_unwrap(
6767
struct gss_ctx *ctx_id,
6868
int offset,
69+
int len,
6970
struct xdr_buf *inbuf);
7071
u32 gss_delete_sec_context(
7172
struct gss_ctx **ctx_id);
@@ -126,6 +127,7 @@ struct gss_api_ops {
126127
u32 (*gss_unwrap)(
127128
struct gss_ctx *ctx_id,
128129
int offset,
130+
int len,
129131
struct xdr_buf *buf);
130132
void (*gss_delete_sec_context)(
131133
void *internal_ctx_id);

include/linux/sunrpc/gss_krb5.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ struct gss_krb5_enctype {
8383
u32 (*encrypt_v2) (struct krb5_ctx *kctx, u32 offset,
8484
struct xdr_buf *buf,
8585
struct page **pages); /* v2 encryption function */
86-
u32 (*decrypt_v2) (struct krb5_ctx *kctx, u32 offset,
86+
u32 (*decrypt_v2) (struct krb5_ctx *kctx, u32 offset, u32 len,
8787
struct xdr_buf *buf, u32 *headskip,
8888
u32 *tailskip); /* v2 decryption function */
8989
};
@@ -255,7 +255,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx_id, int offset,
255255
struct xdr_buf *outbuf, struct page **pages);
256256

257257
u32
258-
gss_unwrap_kerberos(struct gss_ctx *ctx_id, int offset,
258+
gss_unwrap_kerberos(struct gss_ctx *ctx_id, int offset, int len,
259259
struct xdr_buf *buf);
260260

261261

@@ -312,7 +312,7 @@ gss_krb5_aes_encrypt(struct krb5_ctx *kctx, u32 offset,
312312
struct page **pages);
313313

314314
u32
315-
gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset,
315+
gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, u32 len,
316316
struct xdr_buf *buf, u32 *plainoffset,
317317
u32 *plainlen);
318318

net/sunrpc/auth_gss/auth_gss.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2043,9 +2043,9 @@ gss_unwrap_resp_priv(struct rpc_task *task, struct rpc_cred *cred,
20432043
offset = (u8 *)(p) - (u8 *)head->iov_base;
20442044
if (offset + opaque_len > rcv_buf->len)
20452045
goto unwrap_failed;
2046-
rcv_buf->len = offset + opaque_len;
20472046

2048-
maj_stat = gss_unwrap(ctx->gc_gss_ctx, offset, rcv_buf);
2047+
maj_stat = gss_unwrap(ctx->gc_gss_ctx, offset,
2048+
offset + opaque_len, rcv_buf);
20492049
if (maj_stat == GSS_S_CONTEXT_EXPIRED)
20502050
clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
20512051
if (maj_stat != GSS_S_COMPLETE)

net/sunrpc/auth_gss/gss_krb5_crypto.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,8 @@ gss_krb5_aes_encrypt(struct krb5_ctx *kctx, u32 offset,
851851
}
852852

853853
u32
854-
gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf,
855-
u32 *headskip, u32 *tailskip)
854+
gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, u32 len,
855+
struct xdr_buf *buf, u32 *headskip, u32 *tailskip)
856856
{
857857
struct xdr_buf subbuf;
858858
u32 ret = 0;
@@ -881,7 +881,7 @@ gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf,
881881

882882
/* create a segment skipping the header and leaving out the checksum */
883883
xdr_buf_subsegment(buf, &subbuf, offset + GSS_KRB5_TOK_HDR_LEN,
884-
(buf->len - offset - GSS_KRB5_TOK_HDR_LEN -
884+
(len - offset - GSS_KRB5_TOK_HDR_LEN -
885885
kctx->gk5e->cksumlength));
886886

887887
nblocks = (subbuf.len + blocksize - 1) / blocksize;
@@ -926,7 +926,7 @@ gss_krb5_aes_decrypt(struct krb5_ctx *kctx, u32 offset, struct xdr_buf *buf,
926926
goto out_err;
927927

928928
/* Get the packet's hmac value */
929-
ret = read_bytes_from_xdr_buf(buf, buf->len - kctx->gk5e->cksumlength,
929+
ret = read_bytes_from_xdr_buf(buf, len - kctx->gk5e->cksumlength,
930930
pkt_hmac, kctx->gk5e->cksumlength);
931931
if (ret)
932932
goto out_err;

net/sunrpc/auth_gss/gss_krb5_wrap.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,8 @@ gss_wrap_kerberos_v1(struct krb5_ctx *kctx, int offset,
261261
}
262262

263263
static u32
264-
gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
264+
gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, int len,
265+
struct xdr_buf *buf)
265266
{
266267
int signalg;
267268
int sealalg;
@@ -284,7 +285,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
284285

285286
ptr = (u8 *)buf->head[0].iov_base + offset;
286287
if (g_verify_token_header(&kctx->mech_used, &bodysize, &ptr,
287-
buf->len - offset))
288+
len - offset))
288289
return GSS_S_DEFECTIVE_TOKEN;
289290

290291
if ((ptr[0] != ((KG_TOK_WRAP_MSG >> 8) & 0xff)) ||
@@ -324,6 +325,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
324325
(!kctx->initiate && direction != 0))
325326
return GSS_S_BAD_SIG;
326327

328+
buf->len = len;
327329
if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC) {
328330
struct crypto_sync_skcipher *cipher;
329331
int err;
@@ -376,7 +378,7 @@ gss_unwrap_kerberos_v1(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
376378
data_len = (buf->head[0].iov_base + buf->head[0].iov_len) - data_start;
377379
memmove(orig_start, data_start, data_len);
378380
buf->head[0].iov_len -= (data_start - orig_start);
379-
buf->len -= (data_start - orig_start);
381+
buf->len = len - (data_start - orig_start);
380382

381383
if (gss_krb5_remove_padding(buf, blocksize))
382384
return GSS_S_DEFECTIVE_TOKEN;
@@ -486,7 +488,8 @@ gss_wrap_kerberos_v2(struct krb5_ctx *kctx, u32 offset,
486488
}
487489

488490
static u32
489-
gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
491+
gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, int len,
492+
struct xdr_buf *buf)
490493
{
491494
time64_t now;
492495
u8 *ptr;
@@ -532,7 +535,7 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
532535
if (rrc != 0)
533536
rotate_left(offset + 16, buf, rrc);
534537

535-
err = (*kctx->gk5e->decrypt_v2)(kctx, offset, buf,
538+
err = (*kctx->gk5e->decrypt_v2)(kctx, offset, len, buf,
536539
&headskip, &tailskip);
537540
if (err)
538541
return GSS_S_FAILURE;
@@ -542,7 +545,7 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
542545
* it against the original
543546
*/
544547
err = read_bytes_from_xdr_buf(buf,
545-
buf->len - GSS_KRB5_TOK_HDR_LEN - tailskip,
548+
len - GSS_KRB5_TOK_HDR_LEN - tailskip,
546549
decrypted_hdr, GSS_KRB5_TOK_HDR_LEN);
547550
if (err) {
548551
dprintk("%s: error %u getting decrypted_hdr\n", __func__, err);
@@ -568,14 +571,14 @@ gss_unwrap_kerberos_v2(struct krb5_ctx *kctx, int offset, struct xdr_buf *buf)
568571
* Note that buf->head[0].iov_len may indicate the available
569572
* head buffer space rather than that actually occupied.
570573
*/
571-
movelen = min_t(unsigned int, buf->head[0].iov_len, buf->len);
574+
movelen = min_t(unsigned int, buf->head[0].iov_len, len);
572575
movelen -= offset + GSS_KRB5_TOK_HDR_LEN + headskip;
573576
if (offset + GSS_KRB5_TOK_HDR_LEN + headskip + movelen >
574577
buf->head[0].iov_len)
575578
return GSS_S_FAILURE;
576579
memmove(ptr, ptr + GSS_KRB5_TOK_HDR_LEN + headskip, movelen);
577580
buf->head[0].iov_len -= GSS_KRB5_TOK_HDR_LEN + headskip;
578-
buf->len -= GSS_KRB5_TOK_HDR_LEN + headskip;
581+
buf->len = len - GSS_KRB5_TOK_HDR_LEN + headskip;
579582

580583
/* Trim off the trailing "extra count" and checksum blob */
581584
buf->len -= ec + GSS_KRB5_TOK_HDR_LEN + tailskip;
@@ -603,7 +606,8 @@ gss_wrap_kerberos(struct gss_ctx *gctx, int offset,
603606
}
604607

605608
u32
606-
gss_unwrap_kerberos(struct gss_ctx *gctx, int offset, struct xdr_buf *buf)
609+
gss_unwrap_kerberos(struct gss_ctx *gctx, int offset,
610+
int len, struct xdr_buf *buf)
607611
{
608612
struct krb5_ctx *kctx = gctx->internal_ctx_id;
609613

@@ -613,9 +617,9 @@ gss_unwrap_kerberos(struct gss_ctx *gctx, int offset, struct xdr_buf *buf)
613617
case ENCTYPE_DES_CBC_RAW:
614618
case ENCTYPE_DES3_CBC_RAW:
615619
case ENCTYPE_ARCFOUR_HMAC:
616-
return gss_unwrap_kerberos_v1(kctx, offset, buf);
620+
return gss_unwrap_kerberos_v1(kctx, offset, len, buf);
617621
case ENCTYPE_AES128_CTS_HMAC_SHA1_96:
618622
case ENCTYPE_AES256_CTS_HMAC_SHA1_96:
619-
return gss_unwrap_kerberos_v2(kctx, offset, buf);
623+
return gss_unwrap_kerberos_v2(kctx, offset, len, buf);
620624
}
621625
}

net/sunrpc/auth_gss/gss_mech_switch.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,11 @@ gss_wrap(struct gss_ctx *ctx_id,
411411
u32
412412
gss_unwrap(struct gss_ctx *ctx_id,
413413
int offset,
414+
int len,
414415
struct xdr_buf *buf)
415416
{
416417
return ctx_id->mech_type->gm_ops
417-
->gss_unwrap(ctx_id, offset, buf);
418+
->gss_unwrap(ctx_id, offset, len, buf);
418419
}
419420

420421

net/sunrpc/auth_gss/svcauth_gss.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,7 @@ static int
934934
unwrap_priv_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct gss_ctx *ctx)
935935
{
936936
u32 priv_len, maj_stat;
937-
int pad, saved_len, remaining_len, offset;
937+
int pad, remaining_len, offset;
938938

939939
clear_bit(RQ_SPLICE_OK, &rqstp->rq_flags);
940940

@@ -954,12 +954,8 @@ unwrap_priv_data(struct svc_rqst *rqstp, struct xdr_buf *buf, u32 seq, struct gs
954954
buf->len -= pad;
955955
fix_priv_head(buf, pad);
956956

957-
/* Maybe it would be better to give gss_unwrap a length parameter: */
958-
saved_len = buf->len;
959-
buf->len = priv_len;
960-
maj_stat = gss_unwrap(ctx, 0, buf);
957+
maj_stat = gss_unwrap(ctx, 0, priv_len, buf);
961958
pad = priv_len - buf->len;
962-
buf->len = saved_len;
963959
buf->len -= pad;
964960
/* The upper layers assume the buffer is aligned on 4-byte boundaries.
965961
* In the krb5p case, at least, the data ends up offset, so we need to

0 commit comments

Comments
 (0)