Re: [PATCH v3 2/3] x86/speculation: apply IBPB more strictly to avoid cross-process data leak

From: Peter Zijlstra
Date: Wed Sep 05 2018 - 05:40:22 EST


On Wed, Sep 05, 2018 at 10:02:41AM +0200, Jiri Kosina wrote:
> Yeah, I did more or less that earlier today; my series currently has

Excellent, maybe add a wee comment like so?

> +static bool ibpb_needed(struct task_struct *tsk, u64 last_ctx_id)
> +{
/*
* Check if the current (previous) task has access to the memory
* of the @tsk (next) task. If access is denied, make sure to
* issue a IBPB to stop user->user Spectre-v2 attacks.
*
* Note: __ptrace_may_access() returns 0 or -ERRNO.
*/
> + return (tsk && tsk->mm && tsk->mm->context.ctx_id != last_ctx_id &&
> + __ptrace_may_access(tsk, PTRACE_MODE_IBPB));
> +}