提交 9e57b302 编写于 作者: J J. Bruce Fields 提交者: Trond Myklebust

SUNRPC,RPCSEC_GSS: remove unnecessary kmalloc of a checksum

Remove unnecessary kmalloc of temporary space to hold the md5 result; it's
small enough to just put on the stack.

This code may be called to process rpc's necessary to perform writes, so
there's a potential deadlock whenever we kmalloc() here.  After this a
couple kmalloc()'s still remain, to be removed soon.

This also fixes a rare double-free on error noticed by coverity.
Signed-off-by: NJ. Bruce Fields <bfields@citi.umich.edu>
Signed-off-by: NTrond Myklebust <Trond.Myklebust@netapp.com>
上级 7a1218a2
...@@ -76,7 +76,8 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text, ...@@ -76,7 +76,8 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
{ {
struct krb5_ctx *ctx = gss_ctx->internal_ctx_id; struct krb5_ctx *ctx = gss_ctx->internal_ctx_id;
s32 checksum_type; s32 checksum_type;
struct xdr_netobj md5cksum = {.len = 0, .data = NULL}; char cksumdata[16];
struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
unsigned char *ptr, *krb5_hdr, *msg_start; unsigned char *ptr, *krb5_hdr, *msg_start;
s32 now; s32 now;
...@@ -133,8 +134,6 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text, ...@@ -133,8 +134,6 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
BUG(); BUG();
} }
kfree(md5cksum.data);
if ((krb5_make_seq_num(ctx->seq, ctx->initiate ? 0 : 0xff, if ((krb5_make_seq_num(ctx->seq, ctx->initiate ? 0 : 0xff,
ctx->seq_send, krb5_hdr + 16, krb5_hdr + 8))) ctx->seq_send, krb5_hdr + 16, krb5_hdr + 8)))
goto out_err; goto out_err;
...@@ -143,6 +142,5 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text, ...@@ -143,6 +142,5 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
return ((ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE); return ((ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE);
out_err: out_err:
kfree(md5cksum.data);
return GSS_S_FAILURE; return GSS_S_FAILURE;
} }
...@@ -79,7 +79,8 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx, ...@@ -79,7 +79,8 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
int signalg; int signalg;
int sealalg; int sealalg;
s32 checksum_type; s32 checksum_type;
struct xdr_netobj md5cksum = {.len = 0, .data = NULL}; char cksumdata[16];
struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
s32 now; s32 now;
int direction; int direction;
s32 seqnum; s32 seqnum;
...@@ -176,6 +177,5 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx, ...@@ -176,6 +177,5 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
ret = GSS_S_COMPLETE; ret = GSS_S_COMPLETE;
out: out:
kfree(md5cksum.data);
return ret; return ret;
} }
...@@ -121,7 +121,8 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, ...@@ -121,7 +121,8 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
{ {
struct krb5_ctx *kctx = ctx->internal_ctx_id; struct krb5_ctx *kctx = ctx->internal_ctx_id;
s32 checksum_type; s32 checksum_type;
struct xdr_netobj md5cksum = {.len = 0, .data = NULL}; char cksumdata[16];
struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
int blocksize = 0, plainlen; int blocksize = 0, plainlen;
unsigned char *ptr, *krb5_hdr, *msg_start; unsigned char *ptr, *krb5_hdr, *msg_start;
s32 now; s32 now;
...@@ -205,8 +206,6 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, ...@@ -205,8 +206,6 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
BUG(); BUG();
} }
kfree(md5cksum.data);
/* XXX would probably be more efficient to compute checksum /* XXX would probably be more efficient to compute checksum
* and encrypt at the same time: */ * and encrypt at the same time: */
if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff, if ((krb5_make_seq_num(kctx->seq, kctx->initiate ? 0 : 0xff,
...@@ -221,7 +220,6 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset, ...@@ -221,7 +220,6 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
return ((kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE); return ((kctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE);
out_err: out_err:
if (md5cksum.data) kfree(md5cksum.data);
return GSS_S_FAILURE; return GSS_S_FAILURE;
} }
...@@ -232,7 +230,8 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf) ...@@ -232,7 +230,8 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
int signalg; int signalg;
int sealalg; int sealalg;
s32 checksum_type; s32 checksum_type;
struct xdr_netobj md5cksum = {.len = 0, .data = NULL}; char cksumdata[16];
struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
s32 now; s32 now;
int direction; int direction;
s32 seqnum; s32 seqnum;
...@@ -358,6 +357,5 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf) ...@@ -358,6 +357,5 @@ gss_unwrap_kerberos(struct gss_ctx *ctx, int offset, struct xdr_buf *buf)
ret = GSS_S_COMPLETE; ret = GSS_S_COMPLETE;
out: out:
if (md5cksum.data) kfree(md5cksum.data);
return ret; return ret;
} }
...@@ -57,7 +57,8 @@ spkm3_make_token(struct spkm3_ctx *ctx, ...@@ -57,7 +57,8 @@ spkm3_make_token(struct spkm3_ctx *ctx,
{ {
s32 checksum_type; s32 checksum_type;
char tokhdrbuf[25]; char tokhdrbuf[25];
struct xdr_netobj md5cksum = {.len = 0, .data = NULL}; char cksumdata[16];
struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
struct xdr_netobj mic_hdr = {.len = 0, .data = tokhdrbuf}; struct xdr_netobj mic_hdr = {.len = 0, .data = tokhdrbuf};
int tokenlen = 0; int tokenlen = 0;
unsigned char *ptr; unsigned char *ptr;
...@@ -115,13 +116,11 @@ spkm3_make_token(struct spkm3_ctx *ctx, ...@@ -115,13 +116,11 @@ spkm3_make_token(struct spkm3_ctx *ctx,
dprintk("RPC: gss_spkm3_seal: SPKM_WRAP_TOK not supported\n"); dprintk("RPC: gss_spkm3_seal: SPKM_WRAP_TOK not supported\n");
goto out_err; goto out_err;
} }
kfree(md5cksum.data);
/* XXX need to implement sequence numbers, and ctx->expired */ /* XXX need to implement sequence numbers, and ctx->expired */
return GSS_S_COMPLETE; return GSS_S_COMPLETE;
out_err: out_err:
kfree(md5cksum.data);
token->data = NULL; token->data = NULL;
token->len = 0; token->len = 0;
return GSS_S_FAILURE; return GSS_S_FAILURE;
......
...@@ -56,7 +56,8 @@ spkm3_read_token(struct spkm3_ctx *ctx, ...@@ -56,7 +56,8 @@ spkm3_read_token(struct spkm3_ctx *ctx,
{ {
s32 code; s32 code;
struct xdr_netobj wire_cksum = {.len =0, .data = NULL}; struct xdr_netobj wire_cksum = {.len =0, .data = NULL};
struct xdr_netobj md5cksum = {.len = 0, .data = NULL}; char cksumdata[16];
struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
unsigned char *ptr = (unsigned char *)read_token->data; unsigned char *ptr = (unsigned char *)read_token->data;
unsigned char *cksum; unsigned char *cksum;
int bodysize, md5elen; int bodysize, md5elen;
...@@ -120,7 +121,6 @@ spkm3_read_token(struct spkm3_ctx *ctx, ...@@ -120,7 +121,6 @@ spkm3_read_token(struct spkm3_ctx *ctx,
/* XXX: need to add expiration and sequencing */ /* XXX: need to add expiration and sequencing */
ret = GSS_S_COMPLETE; ret = GSS_S_COMPLETE;
out: out:
kfree(md5cksum.data);
kfree(wire_cksum.data); kfree(wire_cksum.data);
return ret; return ret;
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册