Skip to content

Commit

Permalink
Fix uncommon PKINIT memory leak
Browse files Browse the repository at this point in the history
PKINIT per-request module data objects are normally created by
pkinit_server_verify_padata() and freed by
pkinit_server_return_padata().  In some unusual circumstances, the KDC
may not call the return_padata method after verification succeeds.
Add a free_modreq method and free the object there instead.

[ghudson@mit.edu: rewrote commit message]

(cherry picked from commit 8834150)

ticket: 9065
version_fixed: 1.20.1
  • Loading branch information
Sashan authored and greghudson committed Nov 4, 2022
1 parent 782e3cf commit 440c974
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/plugins/preauth/pkinit/pkinit_srv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,6 @@ pkinit_server_return_padata(krb5_context context,
(*send_pa)->contents = (krb5_octet *) out_data->data;

cleanup:
pkinit_fini_kdc_req_context(context, reqctx);
free(scratch.data);
free(out_data);
if (encoded_dhkey_info != NULL)
Expand Down Expand Up @@ -1612,6 +1611,13 @@ pkinit_fini_kdc_req_context(krb5_context context, void *ctx)
free(reqctx);
}

static void
pkinit_free_modreq(krb5_context context, krb5_kdcpreauth_moddata moddata,
krb5_kdcpreauth_modreq modreq)
{
pkinit_fini_kdc_req_context(context, modreq);
}

krb5_error_code
kdcpreauth_pkinit_initvt(krb5_context context, int maj_ver, int min_ver,
krb5_plugin_vtable vtable);
Expand All @@ -1633,5 +1639,6 @@ kdcpreauth_pkinit_initvt(krb5_context context, int maj_ver, int min_ver,
vt->edata = pkinit_server_get_edata;
vt->verify = pkinit_server_verify_padata;
vt->return_padata = pkinit_server_return_padata;
vt->free_modreq = pkinit_free_modreq;
return 0;
}

0 comments on commit 440c974

Please sign in to comment.