All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KEYS: Do not cache key in task struct if key is requested from kernel thread
@ 2023-03-12 18:53 Bharath SM
  2023-03-12 21:37 ` Jarkko Sakkinen
  2023-03-14 15:18 ` David Howells
  0 siblings, 2 replies; 10+ messages in thread
From: Bharath SM @ 2023-03-12 18:53 UTC (permalink / raw)
  To: David Howells, jarkko, keyrings; +Cc: Bharath S M, Shyam Prasad N, Steve French

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.

Signed-off-by: Bharath SM <bharathsm@microsoft.com>
---
 security/keys/request_key.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/security/keys/request_key.c b/security/keys/request_key.c
index 2da4404276f0..07a0ef2baacd 100644
--- a/security/keys/request_key.c
+++ b/security/keys/request_key.c
@@ -38,9 +38,12 @@ static void cache_requested_key(struct key *key)
 #ifdef CONFIG_KEYS_REQUEST_CACHE
        struct task_struct *t = current;

-       key_put(t->cached_requested_key);
-       t->cached_requested_key = key_get(key);
-       set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
+       /* Do not cache key if it is a kernel thread */
+       if (!(t->flags & PF_KTHREAD)) {
+               key_put(t->cached_requested_key);
+               t->cached_requested_key = key_get(key);
+               set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);
+       }
 #endif
 }

--
2.25.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-03-19 13:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-12 18:53 [PATCH] KEYS: Do not cache key in task struct if key is requested from kernel thread Bharath SM
2023-03-12 21:37 ` Jarkko Sakkinen
2023-03-13  5:18   ` Bharath SM
2023-03-14 11:07     ` Jarkko Sakkinen
2023-03-14 15:27       ` David Howells
2023-03-15 15:13         ` Bharath SM
2023-03-15 15:34           ` Bharath SM
2023-03-19 13:39         ` Jarkko Sakkinen
2023-03-19 13:40           ` Jarkko Sakkinen
2023-03-14 15:18 ` David Howells

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.