Skip to contentSkip to conversation

lib/error-inject: Traverse list with mutex

PATCH Applied wuchi 1 participant 1 message Jun 20, 2022

Subsystems (4)
lore
Share & tools
lore

wuchi

author
#0 lore raw

PATCH 1/1 lib/error-inject: Traverse list with mutex

Traversing list without mutex in get_injectable_error_type will race with the following code:

    list_del_init(&ent->list)
    kfree(ent)

in module_unload_ei_list. So fix that.

---
 lib/error-inject.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
lib/error-inject.c +9 -3
index 4a4f1278c419..1afca1b1cdea 100644
@@ -40,12 +40,18 @@ bool within_error_injection_list(unsigned long addr)
 int get_injectable_error_type(unsigned long addr)
 {
 	struct ei_entry *ent;
+	int ei_type = EI_ETYPE_NONE;
 
+	mutex_lock(&ei_mutex);
 	list_for_each_entry(ent, &error_injection_list, list) {
-		if (addr >= ent->start_addr && addr < ent->end_addr)
-			return ent->etype;
+		if (addr >= ent->start_addr && addr < ent->end_addr) {
+			ei_type = ent->etype;
+			break;
+		}
 	}
-	return EI_ETYPE_NONE;
+	mutex_unlock(&ei_mutex);
+
+	return ei_type;
 }
 
 /*
Signature · 1 line
2.20.1