vhost_task: Fix a bug where KVM wakes an exited task
Subsystems (7)
Sean Christopherson
maintainerv2 cover vhost_task: Fix a bug where KVM wakes an exited task
Michael,
Do you want to take this through the vhost tree? It technically fixes a KVM bug, but this obviously touches far more vhost code than KVM code, and the patch that needs to go into 6.17 doesn't touch KVM at all.
Fix a bug where KVM attempts to wake a vhost task that has already exited in response to a fatal signal, and tack on a few cleanups to harden against introducing similar bugs in the future.
The issue is firmly a KVM problem, but I opted to fix the bug by making vhost_task_wake() safe against an exited task as doing so is far simpler and cleaner than implementing the same functionality in KVM, and I suspect that if there are other users of vhost_tasks in the future, then there's a good chance they will want/expect vhost_task to handle that detail.
Note, this only started causing problems when commit 56180dd20c19 ("futex:
Use RCU-based per-CPU reference counting instead of rcuref_t") landed, so the explosions are "new" in 6.17, but the bug has existed since KVM switched to vhost_task back in 6.13.
v2:
- Drop the "safe" postfix variant and make the "default" vhost_task_wake() safe. [Michael].
- Use vhost_task_wake() and __vhost_task_wake() for the public APIs, and vhost_task_wake_up_process() for the local helper. [Michael]
- Drag the signalas back from their Spanish holiday. [Sebastian]
v1: https://lore.kernel.org/all/[email protected]
Sean Christopherson (3):
vhost_task: Don't wake KVM x86's recovery thread if vhost task was
killed
vhost_task: Allow caller to omit handle_sigkill() callback
KVM: x86/mmu: Don't register a sigkill callback for NX hugepage
recovery tasks
arch/x86/kvm/mmu/mmu.c | 7 +--- drivers/vhost/vhost.c | 2 +- include/linux/sched/vhost_task.h | 1 + kernel/vhost_task.c | 62 +++++++++++++++++++++++++++----- 4 files changed, 56 insertions(+), 16 deletions(-)
base-commit: 1b237f190eb3d36f52dffe07a40b5eb210280e00
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 1/3 vhost_task: Don't wake KVM x86's recovery thread if vhost task was killed
Make the "default" API for waking a vhost task safe against the underlying task exiting due to a fatal signal. This fixes a bug in KVM x86 where KVM attempts to wake an NX hugepage recovery task that exiting before being explicitly stopped, resulting in a use-after-free and thus crashes, hangs, and other badness.
Oops: general protection fault, probably for non-canonical address 0xff0e899fa1566052: 0000 [#1] SMP CPU: 51 UID: 0 PID: 53807 Comm: tee Tainted: G S O 6.17.0-smp--38183c31756a-next #826 NONE Tainted: [S]=CPU_OUT_OF_SPEC, [O]=OOT_MODULE Hardware name: Google LLC Indus/Indus_QC_03, BIOS 30.110.0 09/13/2024 RIP: 0010:queued_spin_lock_slowpath+0x123/0x250 Code: ... <48> 89 8c 02 c0 da 47 a2 83 79 08 00 75 08 f3 90 83 79 08 00 74 f8 RSP: 0018:ffffbf55cffe7cf8 EFLAGS: 00010006 RAX: ff0e899fff0e8562 RBX: 0000000000d00000 RCX: ffffa39b40aefac0 RDX: 0000000000000030 RSI: fffffffffffffff8 RDI: ffffa39d0592e68c RBP: 0000000000d00000 R08: 00000000ffffff80 R09: 0000000400000000 R10: ffffa36cce4fe401 R11: 0000000000000800 R12: 0000000000000003 R13: 0000000000000000 R14: ffffa39d0592e68c R15: ffffa39b9e672000 FS: 00007f233b2e9740(0000) GS:ffffa39b9e672000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f233b39fda0 CR3: 00000004d031f002 CR4: 00000000007726f0 PKRU: 55555554 Call Trace: <TASK> _raw_spin_lock_irqsave+0x50/0x60 try_to_wake_up+0x4f/0x5d0 set_nx_huge_pages+0xe4/0x1c0 [kvm] param_attr_store+0x89/0xf0 module_attr_store+0x1e/0x30 kernfs_fop_write_iter+0xe4/0x160 vfs_write+0x2cb/0x420 ksys_write+0x7f/0xf0 do_syscall_64+0x6f/0x1f0 entry_SYSCALL_64_after_hwframe+0x4b/0x53 RIP: 0033:0x7f233b4178b3 R13: 0000000000000002 R14: 00000000226ff3d0 R15: 0000000000000002 </TASK>
Handle VHOST_TASK_FLAGS_KILLED in vhost_task_wake() instead of forcing KVM to solve the problem, as KVM would literally just add an equivalent flag, along with a new lock to protect said flag. In general, forcing simple usage of vhost task to care about signals _and_ take non-trivial action to do the right thing isn't developer friendly, and is likely to lead to similar bugs in the future.
Keep the existing behavior for vhost (by calling __vhost_task_wake() instead of vhost_task_wake()), as vhost_worker_killed() takes extra care to stop and flush all workers, i.e. doesn't need the extra protection, and because vhost_vq_work_queue() calls
vhost_worker_queue()
|
-> worker->ops->wakeup(worker)
|
-> vhost_task_wakeup()
|
-> vhost_task_wake()while holding RCU and so can't sleep, i.e. can't take exit_mutex.
rcu_read_lock();
worker = rcu_dereference(vq->worker);
if (worker) {
queued = true;
vhost_worker_queue(worker, work);
}
rcu_read_unlock();--- drivers/vhost/vhost.c | 2 +- include/linux/sched/vhost_task.h | 1 + kernel/vhost_task.c | 52 +++++++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 9 deletions(-)
drivers/vhost/vhost.c +1 -1
@@ -744,7 +744,7 @@ static void vhost_workers_free(struct vhost_dev *dev)static void vhost_task_wakeup (struct vhost_worker *worker) { -return vhost_task_wake (worker->vtsk); +return __vhost_task_wake (worker->vtsk); }static void vhost_kthread_wakeup (struct vhost_worker *worker)
include/linux/sched/vhost_task.h +1 -0
@@ -10,5 +10,6 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),void vhost_task_start (struct vhost_task *vtsk);void vhost_task_stop (struct vhost_task *vtsk);void vhost_task_wake (struct vhost_task *vtsk); +void __vhost_task_wake (struct vhost_task *vtsk);#endif /* _LINUX_SCHED_VHOST_TASK_H */
kernel/vhost_task.c +44 -8
67 lines not on this page · raw message
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 2/3 vhost_task: Allow caller to omit handle_sigkill() callback
In reply to Sean ChristophersonNow that vhost_task provides an API to safely wake a task without relying on the caller to react to signals, make handle_sigkill() optional and WARN if the "unsafe" __vhost_task_wake() is used without hooking sigkill. Requiring the user to react to sigkill adds no meaningful value, e.g. it didn't help KVM do the right thing with respect to signals, and adding a sanity check in __vhost_task_wake() gives developers a hint as to what needs to be done in response to sigkill.
--- kernel/vhost_task.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/vhost_task.c +9 -1
@@ -59,7 +59,8 @@ static int vhost_task_fn(void *data)*/ if (!test_bit (VHOST_TASK_FLAGS_STOP , &vtsk->flags)) {set_bit (VHOST_TASK_FLAGS_KILLED , &vtsk->flags); - vtsk->handle_sigkill (vtsk->data); +if (vtsk->handle_sigkill) + vtsk->handle_sigkill (vtsk->data); }mutex_unlock (&vtsk->exit_mutex);complete (&vtsk->exited);
@@ -81,6 +82,13 @@ static void vhost_task_wake_up_process(struct vhost_task *vtsk)*/ void __vhost_task_wake (struct vhost_task *vtsk) { +/* +* Waking the task without taking exit_mutex is safe if and only if the +* implementation hooks sigkill, as that's the only way the caller can +* know if the task has exited prematurely due to a signal. +*/ +WARN_ON_ONCE (!vtsk->handle_sigkill); +/* * Checking VHOST_TASK_FLAGS_KILLED can race with signal delivery, but * a race can only result in false negatives and this is just a sanity
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Sean Christopherson
maintainerPATCH v2 3/3 KVM: x86/mmu: Don't register a sigkill callback for NX hugepage recovery tasks
In reply to Sean ChristophersonDon't register a sigkill callback with vhost_task when creating NX hugepage recovery threads now that said callback is optional. In addition to removing what is effectively dead code, not registering a sigkill "handler" also guards against improper use of __vhost_task_wake().
--- arch/x86/kvm/mmu/mmu.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
arch/x86/kvm/mmu/mmu.c +1 -6
@@ -7677,10 +7677,6 @@ static void kvm_recover_nx_huge_pages(struct kvm *kvm)srcu_read_unlock (&kvm->srcu, rcu_idx); } -static void kvm_nx_huge_page_recovery_worker_kill (void *data) -{ -} -static bool kvm_nx_huge_page_recovery_worker (void *data) {struct kvm *kvm = data;
@@ -7713,8 +7709,7 @@ static int kvm_mmu_start_lpage_recovery(struct once *once)struct vhost_task *nx_thread; kvm->arch.nx_huge_page_last =get_jiffies_64 (); - nx_thread =vhost_task_create (kvm_nx_huge_page_recovery_worker, - kvm_nx_huge_page_recovery_worker_kill, + nx_thread =vhost_task_create (kvm_nx_huge_page_recovery_worker,NULL , kvm,"kvm-nx-lpage-recovery" );if (IS_ERR (nx_thread))
Signature · 1 line
2.51.0.268.g9569e192d0-goog
Quoted 1 line · Sean Christopherson
Michael,
Sean,
would the bellow work by chance? It is a quick shot but it looks symmetrical…
kernel/vhost_task.c +2 -1
@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);
@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);
Sebastian
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 1 line · Sean Christopherson
Michael,
Sean,
would the bellow work by chance? It is a quick shot but it looks symmetrical…
Gah, sorry, I flagged your earlier mail and then forgot to circle back to it (for whatever reason, I didn't entirely grok what you were suggesting).
Quoted 13 lines
kernel/vhost_task.c +1
-0@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);
kernel/vhost_task.c struct vhost_task *vhost_task_create(bool (*fn)(void *), · line 155
Quoted 8 lines
kernel/vhost_task.c +1
-1@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);
Nice! This fixes things too. Either solution works for me. Or maybe do both? Attempting to wake a task that vhost_task knows has exited (is exiting?) is a bit gross, but even with that hardening, guarding against UAF is very nice to have too.
Quoted 4 lines · Sean Christopherson
Nice! This fixes things too. Either solution works for me. Or maybe do both? Attempting to wake a task that
vhost_taskknows has exited (is exiting?) is a bit gross, but even with that hardening, guarding against UAF is very nice to have too.
I don't mind either way.
If this is requested I can submit a proper patch.
Quoted 1 line
Tested-by Sean Christopherson <[email protected]>
Sebastian
Michael S. Tsirkin
maintainerQuoted 39 lines · Sean Christopherson
Quoted 7 lines · Sebastian Andrzej Siewior
Quoted 1 line · Sean Christopherson
Michael,
Sean,
would the bellow work by chance? It is a quick shot but it looks symmetrical…
Gah, sorry, I flagged your earlier mail and then forgot to circle back to it (for whatever reason, I didn't entirely grok what you were suggesting).
Quoted 13 lines
kernel/vhost_task.c +1
-0@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);kernel/vhost_task.c struct vhost_task *vhost_task_create(bool (*fn)(void *), · line 155
Quoted 8 lines
kernel/vhost_task.c +1
-1@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);Nice! This fixes things too. Either solution works for me. Or maybe do both? Attempting to wake a task that
vhost_taskknows has exited (is exiting?) is a bit gross, but even with that hardening, guarding against UAF is very nice to have too.
Quoted 1 line
Tested-by Sean Christopherson <[email protected]>
Sure let's do both.
Signature · 1 line
MST
Lei Yang
Tested-byTested this series of patches's v2 again with vhost-net regression tests, everything works fine.
Quoted 33 lines · Sebastian Andrzej Siewior
Quoted 1 line · Sean Christopherson
Michael,
Sean,
would the bellow work by chance? It is a quick shot but it looks symmetrical…
kernel/vhost_task.c +2
-1@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);Sebastian
Michael S. Tsirkin
maintainerQuoted 30 lines · Sebastian Andrzej Siewior
Quoted 1 line · Sean Christopherson
Michael,
Sean,
would the bellow work by chance? It is a quick shot but it looks symmetrical…
kernel/vhost_task.c +2
-1@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);
Quoted 1 line
Sebastian
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ... Sean?
Signature · 1 line
MST
Quoted 3 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ... Sean?
Since I am in To: here. You want me to resent my diff as a proper patch?
Sebastian
Sean Christopherson
maintainerQuoted 3 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ...
I don't have a strong preference for 6.17, beyond landing a fix of some kind. I think there are three options for 6.17, in order of "least like to break something":
1. Sebastian's get_task_struct() fix
2. This series, without the KILLED sanity check in __vhost_task_wake()
3. This series, with my fixup (with which syzbot was happy)
Longer term, I'd still like to land everything though.
Quoted 3 lines
Quoted 1 line
Sean?
Since I am in To: here. You want me to resent my diff as a proper patch?
Ya, I think it makes sense to harden against UAF even if we fix the KVM bug more directly.
Michael S. Tsirkin
maintainerQuoted 10 lines · Sean Christopherson
Quoted 3 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ...
I don't have a strong preference for 6.17, beyond landing a fix of some kind. I think there are three options for 6.17, in order of "least like to break something":
1. Sebastian's
get_task_struct()fix
I am just a bit apprehensive that we don't create a situation where we leak the task struct somehow, given the limited testing time. Can you help me get convinced that risk is 0?
Quoted 4 lines
2. This series, without the KILLED sanity check in
__vhost_task_wake()
3. This series, with my fixup (with which syzbot was happy)Longer term, I'd still like to land everything though.
No problem with that.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Sean?
Since I am in To: here. You want me to resent my diff as a proper patch?
Ya, I think it makes sense to harden against UAF even if we fix the KVM bug more directly.
Sean Christopherson
maintainerQuoted 10 lines · Michael S. Tsirkin
Quoted 9 lines · Sean Christopherson
Quoted 3 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ...
I don't have a strong preference for 6.17, beyond landing a fix of some kind. I think there are three options for 6.17, in order of "least like to break something":
Quoted 6 lines
Quoted 1 line
1. Sebastian's
get_task_struct()fixI am just a bit apprehensive that we don't create a situation where we leak the task struct somehow, given the limited testing time. Can you help me get convinced that risk is 0?
I doubt it, I share same similar concerns about lack of testing. So I guess thinking about this again, #2 is probably safer since it'd only impact KVM?
Quoted 2 lines
Quoted 2 lines
2. This series, without the KILLED sanity check in
__vhost_task_wake()
3. This series, with my fixup (with which syzbot was happy)
Michael S. Tsirkin
maintainerQuoted 14 lines · Sean Christopherson
Quoted 13 lines · Michael S. Tsirkin
Quoted 10 lines · Sean Christopherson
Quoted 3 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ...
I don't have a strong preference for 6.17, beyond landing a fix of some kind. I think there are three options for 6.17, in order of "least like to break something":
1. Sebastian's
get_task_struct()fix
Quoted 6 lines
Quoted 3 lines
I am just a bit apprehensive that we don't create a situation where we leak the task struct somehow, given the limited testing time. Can you help me get convinced that risk is 0?
I doubt it, I share same similar concerns about lack of testing. So I guess thinking about this again, #2 is probably safer since it'd only impact KVM?
I can't say I understand completely how we get that state though? Why did the warning trigger if it's not a UAF?
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
2. This series, without the KILLED sanity check in
__vhost_task_wake()
3. This series, with my fixup (with which syzbot was happy)
Sean Christopherson
maintainerQuoted 19 lines · Michael S. Tsirkin
Quoted 18 lines · Sean Christopherson
Quoted 16 lines · Michael S. Tsirkin
Quoted 10 lines · Sean Christopherson
Quoted 3 lines · Sebastian Andrzej Siewior
Quoted 2 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ...
I don't have a strong preference for 6.17, beyond landing a fix of some kind. I think there are three options for 6.17, in order of "least like to break something":
1. Sebastian's
get_task_struct()fixI am just a bit apprehensive that we don't create a situation where we leak the task struct somehow, given the limited testing time. Can you help me get convinced that risk is 0?
Quoted 5 lines
Quoted 2 lines
I doubt it, I share same similar concerns about lack of testing. So I guess thinking about this again, #2 is probably safer since it'd only impact KVM?
I can't say I understand completely how we get that state though? Why did the warning trigger if it's not a UAF?
It's purely a flaw in the sanity check itself due to the ordering in vhost_task_fn().
As is, vhost_task_fn() marks the task KILLED before invoking ->handle_sigkill(), i.e. before vhost_worker_killed() is guaranteed to complete, and thus before worker->killed is set. As a result, vhost can keep waking workers that have KILLED set, but haven't actually exited. That's perfectly fine as UAF won't occur until do_exit() is called, and that won't happen until ->handle_sigkill() completes.
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
2. This series, without the KILLED sanity check in
__vhost_task_wake()
3. This series, with my fixup (with which syzbot was happy)
Michael S. Tsirkin
maintainerQuoted 8 lines · Sebastian Andrzej Siewior
Quoted 3 lines · Michael S. Tsirkin
So how about switching to this approach then? Instead of piling up fixes like we seem to do now ... Sean?
Since I am in To: here. You want me to resent my diff as a proper patch?
Sebastian
Yes please, if Sean can ack it.
Signature · 1 line
MST
PATCH 1/1 vhost: Take a reference on the task that is reference in struct vhost_task.
vhost_task_create() creates a task and keeps a reference to its task_struct. That task may exit early via a signal and its task_struct will be released.
A pending vhost_task_wake() will then attempt to wake the task and access a task_struct which is no longer there.
Acquire a reference on the task_struct while creating the thread and release the reference while the struct vhost_task itself is removed. If the task exits early due to a signal, then the vhost_task_wake() will still access a valid task_struct. The wake is safe and will be skipped in this case.
--- kernel/vhost_task.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
kernel/vhost_task.c +2 -1
@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);
@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);
Signature · 1 line
2.51.0
Re: [PATCH] vhost: Take a reference on the task that is reference in struct vhost_task.
Quoted 12 lines · Sebastian Andrzej Siewior
vhost_task_create()creates a task and keeps a reference to itstask_struct. That task may exit early via a signal and itstask_structwill be released.
A pendingvhost_task_wake()will then attempt to wake the task and access atask_structwhich is no longer there.Acquire a reference on the
task_structwhile creating the thread and release the reference while the structvhost_taskitself is removed. If the task exits early due to a signal, then thevhost_task_wake()will still access a validtask_struct. The wake is safe and will be skipped in this case.
Quoted 5 lines
Fixes f9010dbdce911 ("fork, vhost: Use CLONE_THREAD to fix freezer/ps regression")Reported-by Sean Christopherson <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>---
Michael S. Tsirkin
maintainerRe: [PATCH] vhost: Take a reference on the task that is reference in struct vhost_task.
In reply to Sebastian Andrzej SiewiorSubject: that is reference -> that is referenced
Quoted 43 lines · Sebastian Andrzej Siewior
vhost_task_create()creates a task and keeps a reference to itstask_struct. That task may exit early via a signal and itstask_structwill be released.
A pendingvhost_task_wake()will then attempt to wake the task and access atask_structwhich is no longer there.Acquire a reference on the
task_structwhile creating the thread and release the reference while the structvhost_taskitself is removed. If the task exits early due to a signal, then thevhost_task_wake()will still access a validtask_struct. The wake is safe and will be skipped in this case.Fixes f9010dbdce911 ("fork, vhost: Use CLONE_THREAD to fix freezer/ps regression")Reported-by Sean Christopherson <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- kernel/vhost_task.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/vhost_task.c +2
-1@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);Signature · 1 line
2.51.0
Michael S. Tsirkin
maintainerRe: [PATCH] vhost: Take a reference on the task that is reference in struct vhost_task.
Quoted 1 line · Michael S. Tsirkin
Subject: that is reference -> that is referenced
to note i fixed it for now. just dropped "that is referenced" completely. shorter.
Quoted 44 lines · Sebastian Andrzej Siewior
Quoted 43 lines
vhost_task_create()creates a task and keeps a reference to itstask_struct. That task may exit early via a signal and itstask_structwill be released.
A pendingvhost_task_wake()will then attempt to wake the task and access atask_structwhich is no longer there.Acquire a reference on the
task_structwhile creating the thread and release the reference while the structvhost_taskitself is removed. If the task exits early due to a signal, then thevhost_task_wake()will still access a validtask_struct. The wake is safe and will be skipped in this case.Fixes f9010dbdce911 ("fork, vhost: Use CLONE_THREAD to fix freezer/ps regression")Reported-by Sean Christopherson <[email protected]>Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- kernel/vhost_task.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)kernel/vhost_task.c +2
-1@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)* freeing it below. */ wait_for_completion (&vtsk->exited); +put_task_struct (vtsk->task);kfree (vtsk); }EXPORT_SYMBOL_GPL (vhost_task_stop);@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),return ERR_CAST (tsk); } - vtsk->task = tsk; + vtsk->task =get_task_struct (tsk);return vtsk; }EXPORT_SYMBOL_GPL (vhost_task_create);Signature · 1 line
2.51.0
Sean Christopherson
maintainerQuoted 5 lines · Sean Christopherson
Michael,
Do you want to take this through the vhost tree? It technically fixes a KVM bug, but this obviously touches far more vhost code than KVM code, and the patch that needs to go into 6.17 doesn't touch KVM at all.
Can this be squeezed into 6.17? I know it's very late in the cycle, and that the KVM bug is pre-existing, but the increased impact of the bug is new in 6.17 and I don't want 6.17 to release without a fix.
Michael S. Tsirkin
maintainerQuoted 10 lines · Sean Christopherson
Quoted 5 lines · Sean Christopherson
Michael,
Do you want to take this through the vhost tree? It technically fixes a KVM bug, but this obviously touches far more vhost code than KVM code, and the patch that needs to go into 6.17 doesn't touch KVM at all.
Can this be squeezed into 6.17? I know it's very late in the cycle, and that the KVM bug is pre-existing, but the increased impact of the bug is new in 6.17 and I don't want 6.17 to release without a fix.
To clarify you just mean 1/3, yes?
Sean Christopherson
maintainerQuoted 8 lines · Michael S. Tsirkin
Quoted 7 lines · Sean Christopherson
Quoted 5 lines · Sean Christopherson
Michael,
Do you want to take this through the vhost tree? It technically fixes a KVM bug, but this obviously touches far more vhost code than KVM code, and the patch that needs to go into 6.17 doesn't touch KVM at all.
Quoted 5 lines
Quoted 3 lines
Can this be squeezed into 6.17? I know it's very late in the cycle, and that the KVM bug is pre-existing, but the increased impact of the bug is new in 6.17 and I don't want 6.17 to release without a fix.
To clarify you just mean 1/3, yes?
Correct, 2 and 3 aren't urgent.