From: Petr Mladek <pmladek@suse.com>
To: Miroslav Benes <mbenes@suse.cz>
Cc: jpoimboe@redhat.com, jeyu@kernel.org, jikos@kernel.org,
jbaron@akamai.com, live-patching@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] livepatch: add locking to force and signal functions
Date: Wed, 20 Dec 2017 14:08:16 +0100 [thread overview]
Message-ID: <20171220130816.wpqscs3f3hmmnrt2@pathway.suse.cz> (raw)
In-Reply-To: <20171220092807.27785-1-mbenes@suse.cz>
On Wed 2017-12-20 10:28:07, Miroslav Benes wrote:
> 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 <jbaron@akamai.com>
> Signed-off-by: Miroslav Benes <mbenes@suse.cz>
> ---
> 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);
It would be cleaner if the lock guarded also the check:
if (patch != klp_transition_patch)
return -EINVAL;
in signal_store(). Then we could remove also the comment
above this check.
Same is true also for the force part stuff.
Best Regards,
Petr
PS: I am sorry that I hand waved the proposed solution when
we spoke about it yeasterday. I should have looked into
the code.
next prev parent reply other threads:[~2017-12-20 13:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-20 9:28 Miroslav Benes
2017-12-20 13:08 ` Petr Mladek [this message]
2017-12-20 13:18 ` Miroslav Benes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171220130816.wpqscs3f3hmmnrt2@pathway.suse.cz \
--to=pmladek@suse.com \
--cc=jbaron@akamai.com \
--cc=jeyu@kernel.org \
--cc=jikos@kernel.org \
--cc=jpoimboe@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®