mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>, kvm@vger.kernel.org
Cc: Sean Christopherson <seanjc@google.com>,
	x86@kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: KVM: x86: Cancel pvclock_gtod_work on module removal
Date: Thu, 6 May 2021 13:35:01 +0200	[thread overview]
Message-ID: <2a18634f-b100-334e-f7b5-01c84302e27e@redhat.com> (raw)
In-Reply-To: <87czu4onry.ffs@nanos.tec.linutronix.de>

On 05/05/21 23:48, Thomas Gleixner wrote:
> Nothing prevents the following:
> 
>    pvclock_gtod_notify()
>      queue_work(system_long_wq, &pvclock_gtod_work);
>    ...
>    remove_module(kvm);
>    ...
>    work_queue_run()
>      pvclock_gtod_work()	<- UAF
> 
> Ditto for any other operation on that workqueue list head which touches
> pvclock_gtod_work after module removal.
> 
> Cancel the work in kvm_arch_exit() to prevent that.
> 
> Fixes: 16e8d74d2da9 ("KVM: x86: notifier for clocksource changes")
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
> Found by inspection because of:
>    https://lkml.kernel.org/r/0000000000001d43ac05c0f5c6a0@google.com
> See also:
>    https://lkml.kernel.org/r/20210505105940.190490250@infradead.org
> 
> TL;DR: Scheduling work with tk_core.seq write held is a bad idea.
> ---
>   arch/x86/kvm/x86.c |    1 +
>   1 file changed, 1 insertion(+)
> 
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -8168,6 +8168,7 @@ void kvm_arch_exit(void)
>   	cpuhp_remove_state_nocalls(CPUHP_AP_X86_KVM_CLK_ONLINE);
>   #ifdef CONFIG_X86_64
>   	pvclock_gtod_unregister_notifier(&pvclock_gtod_notifier);
> +	cancel_work_sync(&pvclock_gtod_work);
>   #endif
>   	kvm_x86_ops.hardware_enable = NULL;
>   	kvm_mmu_module_exit();
> 

Queued, thanks (with added Cc to stable).

Paolo


      reply	other threads:[~2021-05-06 11:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-05 21:48 Thomas Gleixner
2021-05-06 11:35 ` Paolo Bonzini [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=2a18634f-b100-334e-f7b5-01c84302e27e@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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®