Commit 2e21865f authored by David Howells's avatar David Howells

keys: sparse: Fix key_fs[ug]id_changed()

Sparse warnings are incurred by key_fs[ug]id_changed() due to unprotected
accesses of tsk->cred, which is marked __rcu.

Fix this by passing the new cred struct to these functions from
commit_creds() rather than the task pointer.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarJames Morris <jamorris@linux.microsoft.com>
parent a188339c
...@@ -402,8 +402,8 @@ extern struct ctl_table key_sysctls[]; ...@@ -402,8 +402,8 @@ extern struct ctl_table key_sysctls[];
* the userspace interface * the userspace interface
*/ */
extern int install_thread_keyring_to_cred(struct cred *cred); extern int install_thread_keyring_to_cred(struct cred *cred);
extern void key_fsuid_changed(struct task_struct *tsk); extern void key_fsuid_changed(struct cred *new_cred);
extern void key_fsgid_changed(struct task_struct *tsk); extern void key_fsgid_changed(struct cred *new_cred);
extern void key_init(void); extern void key_init(void);
#else /* CONFIG_KEYS */ #else /* CONFIG_KEYS */
...@@ -418,8 +418,8 @@ extern void key_init(void); ...@@ -418,8 +418,8 @@ extern void key_init(void);
#define make_key_ref(k, p) NULL #define make_key_ref(k, p) NULL
#define key_ref_to_ptr(k) NULL #define key_ref_to_ptr(k) NULL
#define is_key_possessed(k) 0 #define is_key_possessed(k) 0
#define key_fsuid_changed(t) do { } while(0) #define key_fsuid_changed(c) do { } while(0)
#define key_fsgid_changed(t) do { } while(0) #define key_fsgid_changed(c) do { } while(0)
#define key_init() do { } while(0) #define key_init() do { } while(0)
#endif /* CONFIG_KEYS */ #endif /* CONFIG_KEYS */
......
...@@ -455,9 +455,9 @@ int commit_creds(struct cred *new) ...@@ -455,9 +455,9 @@ int commit_creds(struct cred *new)
/* alter the thread keyring */ /* alter the thread keyring */
if (!uid_eq(new->fsuid, old->fsuid)) if (!uid_eq(new->fsuid, old->fsuid))
key_fsuid_changed(task); key_fsuid_changed(new);
if (!gid_eq(new->fsgid, old->fsgid)) if (!gid_eq(new->fsgid, old->fsgid))
key_fsgid_changed(task); key_fsgid_changed(new);
/* do it /* do it
* RLIMIT_NPROC limits on user->processes have already been checked * RLIMIT_NPROC limits on user->processes have already been checked
......
...@@ -293,28 +293,26 @@ static int install_session_keyring(struct key *keyring) ...@@ -293,28 +293,26 @@ static int install_session_keyring(struct key *keyring)
/* /*
* Handle the fsuid changing. * Handle the fsuid changing.
*/ */
void key_fsuid_changed(struct task_struct *tsk) void key_fsuid_changed(struct cred *new_cred)
{ {
/* update the ownership of the thread keyring */ /* update the ownership of the thread keyring */
BUG_ON(!tsk->cred); if (new_cred->thread_keyring) {
if (tsk->cred->thread_keyring) { down_write(&new_cred->thread_keyring->sem);
down_write(&tsk->cred->thread_keyring->sem); new_cred->thread_keyring->uid = new_cred->fsuid;
tsk->cred->thread_keyring->uid = tsk->cred->fsuid; up_write(&new_cred->thread_keyring->sem);
up_write(&tsk->cred->thread_keyring->sem);
} }
} }
/* /*
* Handle the fsgid changing. * Handle the fsgid changing.
*/ */
void key_fsgid_changed(struct task_struct *tsk) void key_fsgid_changed(struct cred *new_cred)
{ {
/* update the ownership of the thread keyring */ /* update the ownership of the thread keyring */
BUG_ON(!tsk->cred); if (new_cred->thread_keyring) {
if (tsk->cred->thread_keyring) { down_write(&new_cred->thread_keyring->sem);
down_write(&tsk->cred->thread_keyring->sem); new_cred->thread_keyring->gid = new_cred->fsgid;
tsk->cred->thread_keyring->gid = tsk->cred->fsgid; up_write(&new_cred->thread_keyring->sem);
up_write(&tsk->cred->thread_keyring->sem);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment