History

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.

David Howells committed 7 years ago

Commit 2e218651 parent a1883393 files · +16 −18Browse files

Unified · Split

3 files
  1. include/linux/key.h +4 −4
  2. kernel/cred.c +2 −2
  3. security/keys/process_keys.c +10 −12
include/linux/key.h+4−4
@@ -402,8 +402,8 @@ extern struct ctl_table key_sysctls[]; · 401 unmodified lines
402402 * the userspace interface
403403 */
404404 extern int install_thread_keyring_to_cred(struct cred *cred);
405−extern void key_fsuid_changed(struct task_struct *tsk);
406−extern void key_fsgid_changed(struct task_struct *tsk);
405+extern void key_fsuid_changed(struct cred *new_cred);
406+extern void key_fsgid_changed(struct cred *new_cred);
407407 extern void key_init(void);
408408
409409 #else /* CONFIG_KEYS */
@@ -418,8 +418,8 @@ extern void key_init(void); · 8 unmodified lines
418418 #define make_key_ref(k, p) NULL
419419 #define key_ref_to_ptr(k) NULL
420420 #define is_key_possessed(k) 0
421−#define key_fsuid_changed(t) do { } while(0)
422−#define key_fsgid_changed(t) do { } while(0)
421+#define key_fsuid_changed(c) do { } while(0)
422+#define key_fsgid_changed(c) do { } while(0)
423423 #define key_init() do { } while(0)
424424
425425 #endif /* CONFIG_KEYS */
kernel/cred.c+2−2
@@ -455,9 +455,9 @@ int commit_creds(struct cred *new) · 454 unmodified lines
455455
456456 /* alter the thread keyring */
457457 if (!uid_eq(new->fsuid, old->fsuid))
458− key_fsuid_changed(task);
458+ key_fsuid_changed(new);
459459 if (!gid_eq(new->fsgid, old->fsgid))
460− key_fsgid_changed(task);
460+ key_fsgid_changed(new);
461461
462462 /* do it
463463 * RLIMIT_NPROC limits on user->processes have already been checked
security/keys/process_keys.c+10−12
@@ -293,28 +293,26 @@ static int install_session_keyring(struct key *keyring) · 292 unmodified lines
293293 /*
294294 * Handle the fsuid changing.
295295 */
296−void key_fsuid_changed(struct task_struct *tsk)
296+void key_fsuid_changed(struct cred *new_cred)
297297 {
298298 /* update the ownership of the thread keyring */
299− BUG_ON(!tsk->cred);
300− if (tsk->cred->thread_keyring) {
301− down_write(&tsk->cred->thread_keyring->sem);
302− tsk->cred->thread_keyring->uid = tsk->cred->fsuid;
303− up_write(&tsk->cred->thread_keyring->sem);
299+ if (new_cred->thread_keyring) {
300+ down_write(&new_cred->thread_keyring->sem);
301+ new_cred->thread_keyring->uid = new_cred->fsuid;
302+ up_write(&new_cred->thread_keyring->sem);
304303 }
305304 }
306305
307306 /*
308307 * Handle the fsgid changing.
309308 */
310−void key_fsgid_changed(struct task_struct *tsk)
309+void key_fsgid_changed(struct cred *new_cred)
311310 {
312311 /* update the ownership of the thread keyring */
313− BUG_ON(!tsk->cred);
314− if (tsk->cred->thread_keyring) {
315− down_write(&tsk->cred->thread_keyring->sem);
316− tsk->cred->thread_keyring->gid = tsk->cred->fsgid;
317− up_write(&tsk->cred->thread_keyring->sem);
312+ if (new_cred->thread_keyring) {
313+ down_write(&new_cred->thread_keyring->sem);
314+ new_cred->thread_keyring->gid = new_cred->fsgid;
315+ up_write(&new_cred->thread_keyring->sem);
318316 }
319317 }
320318

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t