Thread (8 messages) 8 messages, 4 authors, 2020-01-18

Re: inconsistent lock state in ima_process_queued_keys

flat view

From: Lakshmi Ramasubramanian <hidden>
Date: 2020-01-14 17:18:51
Also in: linux-integrity, lkml

Hi Dmitry,
quoted hunk ↗ jump to hunk
--- a/security/integrity/ima/ima_asymmetric_keys.c
+++ b/security/integrity/ima/ima_asymmetric_keys.c
@@ -103,17 +103,18 @@ static bool ima_queue_key(struct key *keyring,
const void *payload,
  {
         bool queued = false;
         struct ima_key_entry *entry;
+       unsigned long flags;

         entry = ima_alloc_key_entry(keyring, payload, payload_len);
         if (!entry)
                 return false;

-       spin_lock(&ima_keys_lock);
+       spin_lock_irqsave(&ima_keys_lock, flags);
         if (!ima_process_keys) {
                 list_add_tail(&entry->list, &ima_keys);
                 queued = true;
         }
-       spin_unlock(&ima_keys_lock);
+       spin_unlock_irqrestore(&ima_keys_lock, flags);

         if (!queued)
                 ima_free_key_entry(entry);
Using sping_lock_irqsave() and spin_lock_irqrestore() in ima_queue_key() is the right approach. Found a relevant blog below:

https://stackoverflow.com/questions/50637489/spin-lock-irqsave-in-interrupt-context

I think it would be safe to use the same spinlock functions in ima_process_queued_keys() as well, but not a must.

Could you please confirm if your change fixed the crash?
I'll post a patch shortly.

thanks,
 -lakshmi
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help