Skip to contentSkip to conversation

livepatch: Fix missing unlock on error in klp_enable_patch()

PATCH In review Yang Yingliang 3 participants 5 messages Dec 25, 2021 – Jan 4, 2022 Live patching

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 livepatch: Fix missing unlock on error in klp_enable_patch()

Add missing unlock when try_module_get() fails in klp_enable_patch().

Fixes bf01c2975925 ("livepatch: Fix kobject refcount bug on klp_init_patch_early failure path")
---
 kernel/livepatch/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/livepatch/core.c +3 -1
index 23cf444091a8..01bfab7fe7c0 100644
@@ -1047,8 +1047,10 @@ int klp_enable_patch(struct klp_patch *patch)
 		return -EINVAL;
 	}
 
-	if (!try_module_get(patch->mod))
+	if (!try_module_get(patch->mod)) {
+		mutex_unlock(&klp_mutex);
 		return -ENODEV;
+	}
 
 	klp_init_patch_early(patch);
 
Signature · 1 line
2.25.1
Acked-by on v1 1/1
#1 lore raw

Yang Yingliang <[email protected]> wrote on Sat [2021-Dec-25 10:51:15 +0800]:

Quoted 28 lines

Add missing unlock when try_module_get() fails in klp_enable_patch().

Fixes bf01c2975925 ("livepatch: Fix kobject refcount bug on klp_init_patch_early failure path")
---
 kernel/livepatch/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/livepatch/core.c +3 -1
index 23cf444091a8..01bfab7fe7c0 100644
@@ -1047,8 +1047,10 @@ int klp_enable_patch(struct klp_patch *patch)
 		return -EINVAL;
 	}
 
-	if (!try_module_get(patch->mod))
+	if (!try_module_get(patch->mod)) {
+		mutex_unlock(&klp_mutex);
 		return -ENODEV;
+	}
 
 	klp_init_patch_early(patch);
 
Signature · 1 line
2.25.1

Apologies for the silly oversight. Thank you for the fix.

maintainer Reviewed-by
#2 lore raw
Quoted 24 lines · David Vernet

Yang Yingliang <[email protected]> wrote on Sat [2021-Dec-25 10:51:15 +0800]:

Quoted 23 lines

Add missing unlock when try_module_get() fails in klp_enable_patch().

Fixes bf01c2975925 ("livepatch: Fix kobject refcount bug on klp_init_patch_early failure path")
---
 kernel/livepatch/core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/livepatch/core.c +3 -1
index 23cf444091a8..01bfab7fe7c0 100644
@@ -1047,8 +1047,10 @@ int klp_enable_patch(struct klp_patch *patch)
 		return -EINVAL;
 	}
 
-	if (!try_module_get(patch->mod))
+	if (!try_module_get(patch->mod)) {
+		mutex_unlock(&klp_mutex);
 		return -ENODEV;
+	}
 
Quoted 7 lines
Quoted 5 lines
kernel/livepatch/core.c +0 -0
 	klp_init_patch_early(patch);
 
Signature · 1 line
2.25.1

Apologies for the silly oversight. Thank you for the fix.

And nobody caught it. I think that it was partly caused by a pre-holiday loss of concentration :-/

Quoted 1 line

Best Regards,
Petr

maintainer
#4 lore raw
Quoted 9 lines · Petr Mladek
Quoted 5 lines · Yang Yingliang

Add missing unlock when try_module_get() fails in klp_enable_patch().

Fixes bf01c2975925 ("livepatch: Fix kobject refcount bug on klp_init_patch_early failure path")

JFYI, the patch has been committed into livepatch.git, branch for-5.17/fixes.

Just for record. I had to rebase the branch for-5.17/fixes because of missing Signed-off. I have updated Fixes: line to match the hash of the rebased commit. I hope that this fixed all my pre-holidays mistakes.

Best Regards,
Petr