Skip to content

Commit

Permalink
Merge tag 'nfsd-5.0-2' of git://linux-nfs.org/~bfields/linux
Browse files Browse the repository at this point in the history
Pull more nfsd fixes from Bruce Fields:
 "Two small fixes, one for crashes using nfs/krb5 with older enctypes,
  one that could prevent clients from reclaiming state after a kernel
  upgrade"

* tag 'nfsd-5.0-2' of git://linux-nfs.org/~bfields/linux:
  sunrpc: fix 4 more call sites that were using stack memory with a scatterlist
  Revert "nfsd4: return default lease period"
  • Loading branch information
torvalds committed Feb 17, 2019
2 parents 55638c5 + e7afe6c commit 88fe73c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
4 changes: 2 additions & 2 deletions fs/nfsd/nfsctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1239,8 +1239,8 @@ static __net_init int nfsd_init_net(struct net *net)
retval = nfsd_idmap_init(net);
if (retval)
goto out_idmap_error;
nn->nfsd4_lease = 45; /* default lease time */
nn->nfsd4_grace = 45;
nn->nfsd4_lease = 90; /* default lease time */
nn->nfsd4_grace = 90;
nn->somebody_reclaimed = false;
nn->clverifier_counter = prandom_u32();
nn->clientid_counter = prandom_u32();
Expand Down
49 changes: 38 additions & 11 deletions net/sunrpc/auth_gss/gss_krb5_seqnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ krb5_make_rc4_seq_num(struct krb5_ctx *kctx, int direction, s32 seqnum,
unsigned char *cksum, unsigned char *buf)
{
struct crypto_sync_skcipher *cipher;
unsigned char plain[8];
unsigned char *plain;
s32 code;

dprintk("RPC: %s:\n", __func__);
cipher = crypto_alloc_sync_skcipher(kctx->gk5e->encrypt_name, 0, 0);
if (IS_ERR(cipher))
return PTR_ERR(cipher);

plain = kmalloc(8, GFP_NOFS);
if (!plain)
return -ENOMEM;

plain[0] = (unsigned char) ((seqnum >> 24) & 0xff);
plain[1] = (unsigned char) ((seqnum >> 16) & 0xff);
plain[2] = (unsigned char) ((seqnum >> 8) & 0xff);
Expand All @@ -67,6 +71,7 @@ krb5_make_rc4_seq_num(struct krb5_ctx *kctx, int direction, s32 seqnum,

code = krb5_encrypt(cipher, cksum, plain, buf, 8);
out:
kfree(plain);
crypto_free_sync_skcipher(cipher);
return code;
}
Expand All @@ -77,12 +82,17 @@ krb5_make_seq_num(struct krb5_ctx *kctx,
u32 seqnum,
unsigned char *cksum, unsigned char *buf)
{
unsigned char plain[8];
unsigned char *plain;
s32 code;

if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC)
return krb5_make_rc4_seq_num(kctx, direction, seqnum,
cksum, buf);

plain = kmalloc(8, GFP_NOFS);
if (!plain)
return -ENOMEM;

plain[0] = (unsigned char) (seqnum & 0xff);
plain[1] = (unsigned char) ((seqnum >> 8) & 0xff);
plain[2] = (unsigned char) ((seqnum >> 16) & 0xff);
Expand All @@ -93,15 +103,17 @@ krb5_make_seq_num(struct krb5_ctx *kctx,
plain[6] = direction;
plain[7] = direction;

return krb5_encrypt(key, cksum, plain, buf, 8);
code = krb5_encrypt(key, cksum, plain, buf, 8);
kfree(plain);
return code;
}

static s32
krb5_get_rc4_seq_num(struct krb5_ctx *kctx, unsigned char *cksum,
unsigned char *buf, int *direction, s32 *seqnum)
{
struct crypto_sync_skcipher *cipher;
unsigned char plain[8];
unsigned char *plain;
s32 code;

dprintk("RPC: %s:\n", __func__);
Expand All @@ -113,20 +125,28 @@ krb5_get_rc4_seq_num(struct krb5_ctx *kctx, unsigned char *cksum,
if (code)
goto out;

plain = kmalloc(8, GFP_NOFS);
if (!plain) {
code = -ENOMEM;
goto out;
}

code = krb5_decrypt(cipher, cksum, buf, plain, 8);
if (code)
goto out;
goto out_plain;

if ((plain[4] != plain[5]) || (plain[4] != plain[6])
|| (plain[4] != plain[7])) {
code = (s32)KG_BAD_SEQ;
goto out;
goto out_plain;
}

*direction = plain[4];

*seqnum = ((plain[0] << 24) | (plain[1] << 16) |
(plain[2] << 8) | (plain[3]));
out_plain:
kfree(plain);
out:
crypto_free_sync_skcipher(cipher);
return code;
Expand All @@ -139,26 +159,33 @@ krb5_get_seq_num(struct krb5_ctx *kctx,
int *direction, u32 *seqnum)
{
s32 code;
unsigned char plain[8];
unsigned char *plain;
struct crypto_sync_skcipher *key = kctx->seq;

dprintk("RPC: krb5_get_seq_num:\n");

if (kctx->enctype == ENCTYPE_ARCFOUR_HMAC)
return krb5_get_rc4_seq_num(kctx, cksum, buf,
direction, seqnum);
plain = kmalloc(8, GFP_NOFS);
if (!plain)
return -ENOMEM;

if ((code = krb5_decrypt(key, cksum, buf, plain, 8)))
return code;
goto out;

if ((plain[4] != plain[5]) || (plain[4] != plain[6]) ||
(plain[4] != plain[7]))
return (s32)KG_BAD_SEQ;
(plain[4] != plain[7])) {
code = (s32)KG_BAD_SEQ;
goto out;
}

*direction = plain[4];

*seqnum = ((plain[0]) |
(plain[1] << 8) | (plain[2] << 16) | (plain[3] << 24));

return 0;
out:
kfree(plain);
return code;
}

0 comments on commit 88fe73c

Please sign in to comment.