<div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Apr 26, 2023 at 1:19 PM Tim Gardner <<a href="mailto:tim.gardner@canonical.com">tim.gardner@canonical.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">From: David Howells <<a href="mailto:dhowells@redhat.com" target="_blank">dhowells@redhat.com</a>><br>
<br>
BugLink: <a href="https://bugs.launchpad.net/bugs/2017801" rel="noreferrer" target="_blank">https://bugs.launchpad.net/bugs/2017801</a><br>
<br>
[ Upstream commit 47f9e4c924025c5be87959d3335e66fcbb7f6b5c ]<br>
<br>
The key which gets cached in task structure from a kernel thread does not<br>
get invalidated even after expiry. Due to which, a new key request from<br>
kernel thread will be served with the cached key if it's present in task<br>
struct irrespective of the key validity. The change is to not cache key in<br>
task_struct when key requested from kernel thread so that kernel thread<br>
gets a valid key on every key request.<br>
<br>
The problem has been seen with the cifs module doing DNS lookups from a<br>
kernel thread and the results getting pinned by being attached to that<br>
kernel thread's cache - and thus not something that can be easily got rid<br>
of. The cache would ordinarily be cleared by notify-resume, but kernel<br>
threads don't do that.<br>
<br>
This isn't seen with AFS because AFS is doing request_key() within the<br>
kernel half of a user thread - which will do notify-resume.<br>
<br>
Fixes: 7743c48e54ee ("keys: Cache result of request_key*() temporarily in task_struct")<br>
Signed-off-by: Bharath SM <<a href="mailto:bharathsm@microsoft.com" target="_blank">bharathsm@microsoft.com</a>><br>
Signed-off-by: David Howells <<a href="mailto:dhowells@redhat.com" target="_blank">dhowells@redhat.com</a>><br>
Reviewed-by: Jarkko Sakkinen <<a href="mailto:jarkko@kernel.org" target="_blank">jarkko@kernel.org</a>><br>
cc: Shyam Prasad N <<a href="mailto:nspmangalore@gmail.com" target="_blank">nspmangalore@gmail.com</a>><br>
cc: Steve French <<a href="mailto:smfrench@gmail.com" target="_blank">smfrench@gmail.com</a>><br>
cc: <a href="mailto:keyrings@vger.kernel.org" target="_blank">keyrings@vger.kernel.org</a><br>
cc: <a href="mailto:linux-cifs@vger.kernel.org" target="_blank">linux-cifs@vger.kernel.org</a><br>
cc: <a href="mailto:linux-fsdevel@vger.kernel.org" target="_blank">linux-fsdevel@vger.kernel.org</a><br>
Link: <a href="https://lore.kernel.org/r/CAGypqWw951d=zYRbdgNR4snUDvJhWL=q3=WOyh7HhSJupjz2vA@mail.gmail.com/Signed-off-by" rel="noreferrer" target="_blank">https://lore.kernel.org/r/CAGypqWw951d=zYRbdgNR4snUDvJhWL=q3=WOyh7HhSJupjz2vA@mail.gmail.com/<br>
Signed-off-by</a>: Sasha Levin <<a href="mailto:sashal@kernel.org" target="_blank">sashal@kernel.org</a>><br>
(cherry picked from commit 97674f4cd05ef35963a5f73ba785582c82801982 linux-5.4.y)<br>
Signed-off-by: Tim Gardner <<a href="mailto:tim.gardner@canonical.com" target="_blank">tim.gardner@canonical.com</a>><br>
---<br>
security/keys/request_key.c | 9 ++++++---<br>
1 file changed, 6 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/security/keys/request_key.c b/security/keys/request_key.c<br>
index 957b9e3e1492..17c9c0cfb6f5 100644<br>
--- a/security/keys/request_key.c<br>
+++ b/security/keys/request_key.c<br>
@@ -38,9 +38,12 @@ static void cache_requested_key(struct key *key)<br>
#ifdef CONFIG_KEYS_REQUEST_CACHE<br>
struct task_struct *t = current;<br>
<br>
- key_put(t->cached_requested_key);<br>
- t->cached_requested_key = key_get(key);<br>
- set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);<br>
+ /* Do not cache key if it is a kernel thread */<br>
+ if (!(t->flags & PF_KTHREAD)) {<br>
+ key_put(t->cached_requested_key);<br>
+ t->cached_requested_key = key_get(key);<br>
+ set_tsk_thread_flag(t, TIF_NOTIFY_RESUME);<br>
+ }<br>
#endif<br>
}<br>
<br>
-- <br>
2.34.1<br>
<pre style="color:rgb(0,0,0)"><br class="gmail-Apple-interchange-newline">-- <br></pre><pre style="color:rgb(0,0,0)">Acked-by: Philip Cox <<a href="mailto:philip.cox@canonical.com">philip.cox@canonical.com</a>>
</pre><br class="gmail-Apple-interchange-newline"><br>
</blockquote></div></div></div>