Skip to content

Commit e67b652

Browse files
AlexiousLuchucklever
authored andcommitted
SUNRPC: fix a memleak in gss_import_v2_context
The ctx->mech_used.data allocated by kmemdup is not freed in neither gss_import_v2_context nor it only caller gss_krb5_import_sec_context, which frees ctx on error. Thus, this patch reform the last call of gss_import_v2_context to the gss_krb5_import_ctx_v2, preventing the memleak while keepping the return formation. Fixes: 47d8480 ("gss_krb5: handle new context format from gssd") Signed-off-by: Zhipeng Lu <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent d206a76 commit e67b652

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

net/sunrpc/auth_gss/gss_krb5_mech.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
398398
u64 seq_send64;
399399
int keylen;
400400
u32 time32;
401+
int ret;
401402

402403
p = simple_get_bytes(p, end, &ctx->flags, sizeof(ctx->flags));
403404
if (IS_ERR(p))
@@ -450,8 +451,16 @@ gss_import_v2_context(const void *p, const void *end, struct krb5_ctx *ctx,
450451
}
451452
ctx->mech_used.len = gss_kerberos_mech.gm_oid.len;
452453

453-
return gss_krb5_import_ctx_v2(ctx, gfp_mask);
454+
ret = gss_krb5_import_ctx_v2(ctx, gfp_mask);
455+
if (ret) {
456+
p = ERR_PTR(ret);
457+
goto out_free;
458+
}
454459

460+
return 0;
461+
462+
out_free:
463+
kfree(ctx->mech_used.data);
455464
out_err:
456465
return PTR_ERR(p);
457466
}

0 commit comments

Comments
 (0)