]> git.ipfire.org Git - thirdparty/krb5.git/commit
Fix memory bugs in gss_add_cred() extension case 845/head
authorGreg Hudson <ghudson@mit.edu>
Thu, 13 Sep 2018 20:31:36 +0000 (16:31 -0400)
committerGreg Hudson <ghudson@mit.edu>
Wed, 19 Sep 2018 16:00:29 +0000 (12:00 -0400)
commit288cbada833dc6af7d43dd308563b48b73347dfb
tree02bb4d68b5dfde3f794b6902dcf20827a44e9194
parent9e32161dc307a323fd36fd59e252583fe7b90526
Fix memory bugs in gss_add_cred() extension case

If gss_add_cred() is called with both an input_cred_handle and an
output_cred_handle, it creates a new credential with the elements of
the input credential plus the requested element.  Making a shallow
copy of mechs_array and cred_array from the old credential creates
aliased pointers which become invalid when one of the two credentials
is released, leading to use-after-free and double-free errors.

Instead, make a full copy of the input cred for this case.  Make this
copy at the beginning so that union_cred can always be modified in
place (and freed on error using gss_release_cred() if we created it),
removing the need for new_union_cred, new_mechs_array, and
new_cred_array.  Use a stack object for target_mechs to simplify
cleanup and reduce the number of failure cases.

GSSAPI provides no facility for copying a credential; since we mostly
use the GSSAPI as our SPI for mechanisms, we have no simple way to
copy mechanism creds when copying the union cred.  Use
gss_export_cred() and gss_import_cred() if the mechanism provides
them; otherwise fall back to gss_inquire_cred() and
gss_acquire_cred().

ticket: 8734
tags: pullup
target_version: 1.16-next
target_version: 1.15-next
src/lib/gssapi/mechglue/g_acquire_cred.c
src/tests/gssapi/t_add_cred.c