Skip to content

Commit ab8462e

Browse files
dhowellssmb49
authored andcommitted
keys: Do not cache key in task struct if key is requested from kernel thread
BugLink: https://bugs.launchpad.net/bugs/2023230 [ Upstream commit 47f9e4c ] The key which gets cached in task structure from a kernel thread does not get invalidated even after expiry. Due to which, a new key request from kernel thread will be served with the cached key if it's present in task struct irrespective of the key validity. The change is to not cache key in task_struct when key requested from kernel thread so that kernel thread gets a valid key on every key request. The problem has been seen with the cifs module doing DNS lookups from a kernel thread and the results getting pinned by being attached to that kernel thread's cache - and thus not something that can be easily got rid of. The cache would ordinarily be cleared by notify-resume, but kernel threads don't do that. This isn't seen with AFS because AFS is doing request_key() within the kernel half of a user thread - which will do notify-resume. Fixes: 7743c48 ("keys: Cache result of request_key*() temporarily in task_struct") Signed-off-by: Bharath SM <[email protected]> Signed-off-by: David Howells <[email protected]> Reviewed-by: Jarkko Sakkinen <[email protected]> cc: Shyam Prasad N <[email protected]> cc: Steve French <[email protected]> cc: [email protected] cc: [email protected] cc: [email protected] Link: https://lore.kernel.org/r/CAGypqWw951d=zYRbdgNR4snUDvJhWL=q3=WOyh7HhSJupjz2vA@mail.gmail.com/ Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Kamal Mostafa <[email protected]> Signed-off-by: Luke Nowakowski-Krijger <[email protected]>
1 parent bac7734 commit ab8462e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

security/keys/request_key.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ static void cache_requested_key(struct key *key)
3838
#ifdef CONFIG_KEYS_REQUEST_CACHE
3939
struct task_struct *t = current;
4040

41-
key_put(t->cached_requested_key);
42-
t->cached_requested_key = key_get(key);
43-
set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
41+
/* Do not cache key if it is a kernel thread */
42+
if (!(t->flags & PF_KTHREAD)) {
43+
key_put(t->cached_requested_key);
44+
t->cached_requested_key = key_get(key);
45+
set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
46+
}
4447
#endif
4548
}
4649

0 commit comments

Comments
 (0)