Skip to content

Commit 7ce635b

Browse files
Sebastian Andrzej Siewiorgregkh
authored andcommitted
vhost: Take a reference on the task in struct vhost_task.
[ Upstream commit afe1665 ] 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. Fixes: f9010db ("fork, vhost: Use CLONE_THREAD to fix freezer/ps regression") Reported-by: Sean Christopherson <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Tested-by: Sean Christopherson <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a78fd4f commit 7ce635b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/vhost_task.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void vhost_task_stop(struct vhost_task *vtsk)
100100
* freeing it below.
101101
*/
102102
wait_for_completion(&vtsk->exited);
103+
put_task_struct(vtsk->task);
103104
kfree(vtsk);
104105
}
105106
EXPORT_SYMBOL_GPL(vhost_task_stop);
@@ -148,7 +149,7 @@ struct vhost_task *vhost_task_create(bool (*fn)(void *),
148149
return ERR_PTR(PTR_ERR(tsk));
149150
}
150151

151-
vtsk->task = tsk;
152+
vtsk->task = get_task_struct(tsk);
152153
return vtsk;
153154
}
154155
EXPORT_SYMBOL_GPL(vhost_task_create);

0 commit comments

Comments
 (0)