Fix memory leak of remote context in gpp_remote_to_local_ctx - #131
Merged
Conversation
When converting a remote (gssproxy-side) context to a local one, gpp_remote_to_local_ctx() called xdr_free() on *remote_ctx to release the members of the gssx_ctx, but never free()'d the gssx_ctx struct itself before clearing the pointer. The struct is allocated by the XDR layer (gssrpc_xdr_reference) when decoding the init_sec_context reply, so this orphaned one gssx_ctx allocation on every conversion. This is hit on every successful sec=krb5 mount: gssd serializes the context for the kernel via gss_export_lucid_sec_context(), which the mechglue dispatches into gssi_inquire_sec_context_by_oid() -> gpp_remote_to_local_ctx(), leaking the remote context each time. Add the missing free(*remote_ctx), matching the xdr_free()+free() pattern already used in gpm_delete_sec_context(). This fixes the following leak: ==1043== 576 bytes in 2 blocks are definitely lost in loss record 815 of 926 ==1043== at 0x4877826: malloc (vg_replace_malloc.c:447) ==1043== by 0x5774BC1: gssrpc_xdr_reference (in /usr/lib64/libgssrpc.so.4.2) ==1043== by 0x5725E27: xdr_gssx_res_init_sec_context (gss_proxy_xdr.c:577) ==1043== by 0x5728512: gpm_make_call (gpm_common.c:768) ==1043== by 0x572BC83: gpm_init_sec_context (gpm_init_sec_context.c:94) ==1043== by 0x5731B83: gssi_init_sec_context (gpp_init_sec_context.c:158) ==1043== by 0x48F1C62: gss_init_sec_context (in /usr/lib64/libgssapi_krb5.so.2.2) ==1043== by 0x4A43DED: _rpc_gss_refresh (auth_gss.c:484) ==1043== by 0x4A44A79: rpc_gss_seccreate (auth_gss.c:861) ==1043== by 0x4010674: create_auth_rpc_client.constprop.0 (gssd_proc.c:439) ==1043== by 0x4012C03: krb5_use_machine_creds (gssd_proc.c:660) ==1043== by 0x4012C03: process_krb5_upcall (gssd_proc.c:789) ==1043== by 0x4012C03: gssd_work_thread_fn (gssd_proc.c:932) ==1043== by 0x4B649E1: start_thread (in /usr/lib64/libc.so.6) ==1043== Assisted-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Scott Mayhew <smayhew@redhat.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When converting a remote (gssproxy-side) context to a local one, gpp_remote_to_local_ctx() called xdr_free() on *remote_ctx to release the members of the gssx_ctx, but never free()'d the gssx_ctx struct itself before clearing the pointer. The struct is allocated by the XDR layer (gssrpc_xdr_reference) when decoding the init_sec_context reply, so this orphaned one gssx_ctx allocation on every conversion.
This is hit on every successful sec=krb5 mount: gssd serializes the context for the kernel via gss_export_lucid_sec_context(), which the mechglue dispatches into gssi_inquire_sec_context_by_oid() -> gpp_remote_to_local_ctx(), leaking the remote context each time.
Add the missing free(*remote_ctx), matching the xdr_free()+free() pattern already used in gpm_delete_sec_context().
This fixes the following leak:
==1043== 576 bytes in 2 blocks are definitely lost in loss record 815 of 926
==1043== at 0x4877826: malloc (vg_replace_malloc.c:447)
==1043== by 0x5774BC1: gssrpc_xdr_reference (in /usr/lib64/libgssrpc.so.4.2)
==1043== by 0x5725E27: xdr_gssx_res_init_sec_context (gss_proxy_xdr.c:577)
==1043== by 0x5728512: gpm_make_call (gpm_common.c:768)
==1043== by 0x572BC83: gpm_init_sec_context (gpm_init_sec_context.c:94)
==1043== by 0x5731B83: gssi_init_sec_context (gpp_init_sec_context.c:158)
==1043== by 0x48F1C62: gss_init_sec_context (in /usr/lib64/libgssapi_krb5.so.2.2)
==1043== by 0x4A43DED: _rpc_gss_refresh (auth_gss.c:484)
==1043== by 0x4A44A79: rpc_gss_seccreate (auth_gss.c:861)
==1043== by 0x4010674: create_auth_rpc_client.constprop.0 (gssd_proc.c:439)
==1043== by 0x4012C03: krb5_use_machine_creds (gssd_proc.c:660)
==1043== by 0x4012C03: process_krb5_upcall (gssd_proc.c:789)
==1043== by 0x4012C03: gssd_work_thread_fn (gssd_proc.c:932)
==1043== by 0x4B649E1: start_thread (in /usr/lib64/libc.so.6)
==1043==
Assisted-by: Claude Opus 4.8 noreply@anthropic.com