All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] livepatch: fix race between enabled_store() and klp_unregister_patch()
@ 2015-11-30  3:54 Li Bin
  2015-11-30 13:53 ` Petr Mladek
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Li Bin @ 2015-11-30  3:54 UTC (permalink / raw)
  To: jpoimboe, sjenning, jikos, vojtech
  Cc: live-patching, linux-kernel, guohanjun, dingtianhong, xiexiuqi,
	zhouchengming1

There is a potential race as following:

CPU0                         |  CPU1
-----------------------------|-----------------------------------
enabled_store()              |  klp_unregister_patch()
                             |  |-mutex_lock(&klp_mutex);
|-mutex_lock(&klp_mutex);    |  |-klp_free_patch();
                             |  |-mutex_unlock(&klp_mutex);
|-[process the patch's state]|
|-mutex_unlock(&klp_mutex)   |

Fix this race condition by adding klp_is_patch_registered() check in
enabled_store() after get the lock klp_mutex.

Signed-off-by: Li Bin <huawei.libin@huawei.com>
---
 kernel/livepatch/core.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/kernel/livepatch/core.c b/kernel/livepatch/core.c
index db545cb..50af971 100644
--- a/kernel/livepatch/core.c
+++ b/kernel/livepatch/core.c
@@ -614,6 +614,11 @@ static ssize_t enabled_store(struct kobject *kobj, struct kobj_attribute *attr,
 
 	mutex_lock(&klp_mutex);
 
+	if (!klp_is_patch_registered(patch)) {
+		ret = -EINVAL;
+		goto err;
+	}
+
 	if (val == patch->state) {
 		/* already in requested state */
 		ret = -EINVAL;
-- 
1.7.1


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

end of thread, other threads:[~2015-12-15  8:14 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-30  3:54 [PATCH] livepatch: fix race between enabled_store() and klp_unregister_patch() Li Bin
2015-11-30 13:53 ` Petr Mladek
2015-12-01  1:11 ` Josh Poimboeuf
2015-12-01  2:46   ` libin
2015-12-01  8:50   ` Jiri Slaby
2015-12-01 14:13     ` Petr Mladek
2015-12-01 14:28       ` Jiri Slaby
2015-12-01 16:57         ` Petr Mladek
2015-12-01 15:53     ` Josh Poimboeuf
2015-12-15  8:14 ` Miroslav Benes

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.