security: don't use RCU accessors for cred->session_keyring
sparse complains that a bunch of places in kernel/cred.c access cred->session_keyring without the RCU helpers required by the __rcu annotation. cred->session_keyring is written in the following places: - prepare_kernel_cred() [in a new cred struct] - keyctl_session_to_parent() [in a new cred struct] - prepare_creds [in a new cred struct, via memcpy] - install_session_keyring_to_cred() - from install_session_keyring() on new creds - from join_session_keyring() on new creds [twice] - from umh_keys_init() - from call_usermodehelper_exec_async() on new creds All of these writes are before the creds are committed; therefore, cred->session_keyring doesn't need RCU protection. Remove the __rcu annotation and fix up all existing users that use __rcu. Signed-off-by: Jann Horn <jannh@google.com> Signed-off-by: James Morris <james.morris@microsoft.com>
This commit is contained in:
@@ -142,12 +142,10 @@ static int call_sbin_request_key(struct key *authkey, void *aux)
|
||||
prkey = cred->process_keyring->serial;
|
||||
sprintf(keyring_str[1], "%d", prkey);
|
||||
|
||||
rcu_read_lock();
|
||||
session = rcu_dereference(cred->session_keyring);
|
||||
session = cred->session_keyring;
|
||||
if (!session)
|
||||
session = cred->user->session_keyring;
|
||||
sskey = session->serial;
|
||||
rcu_read_unlock();
|
||||
|
||||
sprintf(keyring_str[2], "%d", sskey);
|
||||
|
||||
@@ -287,10 +285,7 @@ static int construct_get_dest_keyring(struct key **_dest_keyring)
|
||||
|
||||
/* fall through */
|
||||
case KEY_REQKEY_DEFL_SESSION_KEYRING:
|
||||
rcu_read_lock();
|
||||
dest_keyring = key_get(
|
||||
rcu_dereference(cred->session_keyring));
|
||||
rcu_read_unlock();
|
||||
dest_keyring = key_get(cred->session_keyring);
|
||||
|
||||
if (dest_keyring)
|
||||
break;
|
||||
|
Reference in New Issue
Block a user