• David Howells's avatar
    keys: fix race with concurrent install_user_keyrings() · 554da46d
    David Howells authored
    commit 0da9dfdd upstream.
    
    This fixes CVE-2013-1792.
    
    There is a race in install_user_keyrings() that can cause a NULL pointer
    dereference when called concurrently for the same user if the uid and
    uid-session keyrings are not yet created.  It might be possible for an
    unprivileged user to trigger this by calling keyctl() from userspace in
    parallel immediately after logging in.
    
    Assume that we have two threads both executing lookup_user_key(), both
    looking for KEY_SPEC_USER_SESSION_KEYRING.
    
    	THREAD A			THREAD B
    	===============================	===============================
    					==>call install_user_keyrings();
    	if (!cred->user->session_keyring)
    	==>call install_user_keyrings()
    					...
    					user->uid_keyring = uid_keyring;
    	if (user->uid_keyring)
    		return 0;
    	<==
    	key = cred->user->session_keyring [== NULL]
    					user->session_keyring = session_keyring;
    	atomic_inc(&key->usage); [oops]
    
    At the point thread A dereference...
    554da46d
process_keys.c 18.5 KB