From: Petr Mladek <pmladek@suse.com>
To: Rik van Riel <riel@surriel.com>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
linux-kernel@vger.kernel.org, live-patching@vger.kernel.org,
kernel-team@fb.com, Jiri Kosina <jikos@kernel.org>,
Miroslav Benes <mbenes@suse.cz>,
Joe Lawrence <joe.lawrence@redhat.com>
Subject: Re: [PATCH v5] livepatch: fix race between fork and KLP transition
Date: Thu, 1 Sep 2022 15:45:50 +0200 [thread overview]
Message-ID: <YxC3jqHIHheHCaG0@alley> (raw)
In-Reply-To: <20220808150019.03d6a67b@imladris.surriel.com>
On Mon 2022-08-08 15:00:19, Rik van Riel wrote:
> The KLP transition code depends on the TIF_PATCH_PENDING and
> the task->patch_state to stay in sync. On a normal (forward)
> transition, TIF_PATCH_PENDING will be set on every task in
> the system, while on a reverse transition (after a failed
> forward one) first TIF_PATCH_PENDING will be cleared from
> every task, followed by it being set on tasks that need to
> be transitioned back to the original code.
>
> However, the fork code copies over the TIF_PATCH_PENDING flag
> from the parent to the child early on, in dup_task_struct and
> setup_thread_stack. Much later, klp_copy_process will set
> child->patch_state to match that of the parent.
>
> However, the parent's patch_state may have been changed by KLP loading
> or unloading since it was initially copied over into the child.
>
> This results in the KLP code occasionally hitting this warning in
> klp_complete_transition:
>
> for_each_process_thread(g, task) {
> WARN_ON_ONCE(test_tsk_thread_flag(task, TIF_PATCH_PENDING));
> task->patch_state = KLP_UNDEFINED;
> }
>
> Set, or clear, the TIF_PATCH_PENDING flag in the child task
> depending on whether or not it is needed at the time
> klp_copy_process is called, at a point in copy_process where the
> tasklist_lock is held exclusively, preventing races with the KLP
> code.
>
> The KLP code does have a few places where the state is changed
> without the tasklist_lock held, but those should not cause
> problems because klp_update_patch_state(current) cannot be
> called while the current task is in the middle of fork,
> klp_check_and_switch_task() which is called under the pi_lock,
> which prevents rescheduling, and manipulation of the patch
> state of idle tasks, which do not fork.
>
> This should prevent this warning from triggering again in the
> future, and close the race for both normal and reverse transitions.
>
> Signed-off-by: Rik van Riel <riel@surriel.com>
> Reported-by: Breno Leitao <leitao@debian.org>
> Reviewed-by: Petr Mladek <pmladek@suse.com>
> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
> Fixes: d83a7cb375ee ("livepatch: change to a per-task consistency model")
> Cc: stable@kernel.org
The patch has been pushed to livepatching/livepaching.git,
branch for-6.1/fixes.
Best Regards,
Petr
prev parent reply other threads:[~2022-09-01 13:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-08 19:00 [PATCH v5] livepatch: fix race between fork and KLP transition Rik van Riel
2022-09-01 13:45 ` Petr Mladek [this message]
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=YxC3jqHIHheHCaG0@alley \
--to=pmladek@suse.com \
--cc=jikos@kernel.org \
--cc=joe.lawrence@redhat.com \
--cc=jpoimboe@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-kernel@vger.kernel.org \
--cc=live-patching@vger.kernel.org \
--cc=mbenes@suse.cz \
--cc=riel@surriel.com \
/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