Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932213AbdLTJ2P (ORCPT ); Wed, 20 Dec 2017 04:28:15 -0500 Received: from mx2.suse.de ([195.135.220.15]:35216 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754581AbdLTJ2N (ORCPT ); Wed, 20 Dec 2017 04:28:13 -0500 From: Miroslav Benes To: jpoimboe@redhat.com, jeyu@kernel.org, jikos@kernel.org Cc: pmladek@suse.com, jbaron@akamai.com, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, Miroslav Benes Subject: [PATCH] livepatch: add locking to force and signal functions Date: Wed, 20 Dec 2017 10:28:07 +0100 Message-Id: <20171220092807.27785-1-mbenes@suse.cz> X-Mailer: git-send-email 2.15.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1778 Lines: 59 klp_send_signals() and klp_force_transition() do not acquire klp_mutex, because it seemed to be superfluous. A potential race in klp_send_signals() was harmless and there was nothing in klp_force_transition() which needed to be synchronized. That changed with the addition of klp_forced variable during the review process. There is a small window now, when klp_complete_transition() does not see klp_forced set to true while all tasks have been already transitioned to the target state. module_put() is called and the module can be removed. Acquire klp_mutex to prevent it. Do the same in klp_send_signals() just to be sure. There is no real downside to that. Reported-by: Jason Baron Signed-off-by: Miroslav Benes --- kernel/livepatch/transition.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kernel/livepatch/transition.c b/kernel/livepatch/transition.c index be5bfa533ee8..3f932ff607cd 100644 --- a/kernel/livepatch/transition.c +++ b/kernel/livepatch/transition.c @@ -625,6 +625,8 @@ void klp_send_signals(void) pr_notice("signaling remaining tasks\n"); + mutex_lock(&klp_mutex); + read_lock(&tasklist_lock); for_each_process_thread(g, task) { if (!klp_patch_pending(task)) @@ -653,6 +655,8 @@ void klp_send_signals(void) } } read_unlock(&tasklist_lock); + + mutex_unlock(&klp_mutex); } /* @@ -671,6 +675,8 @@ void klp_force_transition(void) pr_warn("forcing remaining tasks to the patched state\n"); + mutex_lock(&klp_mutex); + read_lock(&tasklist_lock); for_each_process_thread(g, task) klp_update_patch_state(task); @@ -680,4 +686,6 @@ void klp_force_transition(void) klp_update_patch_state(idle_task(cpu)); klp_forced = true; + + mutex_unlock(&klp_mutex); } -- 2.15.1