From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752147AbbCXLSA (ORCPT ); Tue, 24 Mar 2015 07:18:00 -0400 Received: from cantor2.suse.de ([195.135.220.15]:41486 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751713AbbCXLR6 (ORCPT ); Tue, 24 Mar 2015 07:17:58 -0400 Date: Tue, 24 Mar 2015 12:17:56 +0100 Message-ID: From: Takashi Iwai To: Andy Lutomirski Cc: Denys Vlasenko , Stefan Seyfried , X86 ML , Jiri Kosina , LKML , Tejun Heo Subject: Re: [PATCH] x86, entry: Check for syscall exit work with IRQs disabled In-Reply-To: <189320d42b4d671df78c10555976bb10af1ffc75.1427137498.git.luto@kernel.org> References: <189320d42b4d671df78c10555976bb10af1ffc75.1427137498.git.luto@kernel.org> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/24.4 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At Mon, 23 Mar 2015 12:32:54 -0700, Andy Lutomirski wrote: > > We currently have a race: if we're preempted during syscall exit, we > can fail to process syscall return work that is queued up while > we're preempted in ret_from_sys_call after checking ti.flags. > > Fix it by disabling interrupts before checking ti.flags. > > Fixes: 96b6352c1271 x86_64, entry: Remove the syscall exit audit and schedule optimizations > Reported-by: Stefan Seyfried > Reported-by: Takashi Iwai I tested the patch again and confirmed that it works with the latest Linus tree. Tested-by: Takashi Iwai thanks, Takashi > Signed-off-by: Andy Lutomirski > --- > > Ingo, I don't understand the LOCKDEP_SYS_EXIT stuff. Can you take a quick > look to confirm that it's okay to call it more than once? > > arch/x86/kernel/entry_64.S | 18 ++++++++++++++---- > 1 file changed, 14 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S > index 1d74d161687c..2babb393915e 100644 > --- a/arch/x86/kernel/entry_64.S > +++ b/arch/x86/kernel/entry_64.S > @@ -364,12 +364,21 @@ system_call_fastpath: > * Has incomplete stack frame and undefined top of stack. > */ > ret_from_sys_call: > - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) > - jnz int_ret_from_sys_call_fixup /* Go the the slow path */ > - > LOCKDEP_SYS_EXIT > DISABLE_INTERRUPTS(CLBR_NONE) > TRACE_IRQS_OFF > + > + /* > + * We must check ti flags with interrupts (or at least preemption) > + * off because we must *never* return to userspace without > + * processing exit work that is enqueued if we're preempted here. > + * In particular, returning to userspace with any of the one-shot > + * flags (TIF_NOTIFY_RESUME, TIF_USER_RETURN_NOTIFY, etc) set is > + * very bad. > + */ > + testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET) > + jnz int_ret_from_sys_call_fixup /* Go the the slow path */ > + > CFI_REMEMBER_STATE > /* > * sysretq will re-enable interrupts: > @@ -386,7 +395,7 @@ ret_from_sys_call: > > int_ret_from_sys_call_fixup: > FIXUP_TOP_OF_STACK %r11, -ARGOFFSET > - jmp int_ret_from_sys_call > + jmp int_ret_from_sys_call_irqs_off > > /* Do syscall tracing */ > tracesys: > @@ -432,6 +441,7 @@ tracesys_phase2: > GLOBAL(int_ret_from_sys_call) > DISABLE_INTERRUPTS(CLBR_NONE) > TRACE_IRQS_OFF > +int_ret_from_sys_call_irqs_off: > movl $_TIF_ALLWORK_MASK,%edi > /* edi: mask to check */ > GLOBAL(int_with_check) > -- > 2.3.0 >