• Eric W. Biederman's avatar
    ucounts: Move get_ucounts from cred_alloc_blank to key_change_session_keyring · 5ebcbe34
    Eric W. Biederman authored
    Setting cred->ucounts in cred_alloc_blank does not make sense.  The
    uid and user_ns are deliberately not set in cred_alloc_blank but
    instead the setting is delayed until key_change_session_keyring.
    
    So move dealing with ucounts into key_change_session_keyring as well.
    
    Unfortunately that movement of get_ucounts adds a new failure mode to
    key_change_session_keyring.  I do not see anything stopping the parent
    process from calling setuid and changing the relevant part of it's
    cred while keyctl_session_to_parent is running making it fundamentally
    necessary to call get_ucounts in key_change_session_keyring.  Which
    means that the new failure mode cannot be avoided.
    
    A failure of key_change_session_keyring results in a single threaded
    parent keeping it's existing credentials.  Which results in the parent
    process not being able to access the session keyring and whichever
    keys are in the new keyring.
    
    Further get_ucounts is only expected...
    5ebcbe34
process_keys.c 23.7 KB