Skip to content

Commit 8379bb8

Browse files
dhowellstorvalds
authored andcommitted
keys: Fix request_key() cache
When the key cached by request_key() and co. is cleaned up on exit(), the code looks in the wrong task_struct, and so clears the wrong cache. This leads to anomalies in key refcounting when doing, say, a kernel build on an afs volume, that then trigger kasan to report a use-after-free when the key is viewed in /proc/keys. Fix this by making exit_creds() look in the passed-in task_struct rather than in current (the task_struct cleanup code is deferred by RCU and potentially run in another task). Fixes: 7743c48 ("keys: Cache result of request_key*() temporarily in task_struct") Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 219d543 commit 8379bb8

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎kernel/cred.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ void exit_creds(struct task_struct *tsk)
175175
put_cred(cred);
176176

177177
#ifdef CONFIG_KEYS_REQUEST_CACHE
178-
key_put(current->cached_requested_key);
179-
current->cached_requested_key = NULL;
178+
key_put(tsk->cached_requested_key);
179+
tsk->cached_requested_key = NULL;
180180
#endif
181181
}
182182

0 commit comments

Comments
 (0)