Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4463553imm; Fri, 18 May 2018 05:39:20 -0700 (PDT) X-Google-Smtp-Source: AB8JxZr5r3eJh16TLx4Q48FDJTRcT7dgsGsCLPvxR4Welk10XNo5r5mouvM5aOTPXd8eHyhvydzA X-Received: by 2002:a63:7701:: with SMTP id s1-v6mr1583882pgc.196.1526647160753; Fri, 18 May 2018 05:39:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526647160; cv=none; d=google.com; s=arc-20160816; b=bcRFJoNvM+g7orO6x3KB6wlV5AD9MPsbwO0/tHIZNLBiUDHORf+rl4EDL6YMDp6uJZ bLuBTjpWzv6Ek1fT4Lk4EbCZyjCvp/iGdQxTH46YoSqJaaztsv4BNyrviqfZ8GsnUrb7 4Meyp7RB3WMUkTeV4hPmGn7QFc3RiHTQDWdQHsw0WTmZTxmX1KXWIQAgYabaMY22h6ab KCE2FydnCTjjYsRxI/rbyXSBJQ7g2YnjiiMjSbLWAFyNoREORYZYBNUigFOVWGIRTthv /M0iFAgxfgNaVsjCFsquDuf6tDFfOnQib8nvRUUJTX2I9/eNCk8H7t23R3/PRbrjXnt9 a+zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:arc-authentication-results; bh=wFESJzDH7/C+xT/ApJGHqCneGl98krf4ACKQq+8L3Xc=; b=iL7K7D1EmprpUq3d+XZrfFbJjsoCWajZaaqpHdfo4ODSLIqcxmqTZxhLQbA3t1OQC/ whsVmvVuzkZSAEJF4R4QTM8uuilCWdrr5/rS/ueHNQbyOO5q7zmkH6XNU5XyS9HFj9Sy RR690Bpa6nKeIWUvT2YzdCpXui7SjZFoqwQrM3SaIWqP2GbN58Mqu9G1O69u8I5YA5re AP7mavOv1OpNNDuBxdY+UEbv4m84deVP4lAOqMucFhBb6NFg3FE6EHwIiuwBsLVKErM7 aRkVgx7jz4NzQSSmuv5eqO6ijWh3vOsd8zqCrFNLbhByc1bdoXaqcmLnkLaJL8Tryhm6 FHJw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6-v6si6042784pgs.451.2018.05.18.05.39.06; Fri, 18 May 2018 05:39:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751985AbeERMiz (ORCPT + 99 others); Fri, 18 May 2018 08:38:55 -0400 Received: from ozlabs.org ([203.11.71.1]:41267 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750841AbeERMiw (ORCPT ); Fri, 18 May 2018 08:38:52 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 40nSQY28sGz9s29; Fri, 18 May 2018 22:38:44 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: Mathieu Desnoyers , Boqun Feng , Will Deacon Cc: Peter Zijlstra , "Paul E. McKenney" , Andy Lutomirski , Dave Watson , linux-kernel , linux-api , Paul Turner , Andrew Morton , Russell King , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" , Andrew Hunter , Andi Kleen , Chris Lameter , Ben Maurer , rostedt , Josh Triplett , Linus Torvalds , Catalin Marinas , Michael Kerrisk , Joel Fernandes , Benjamin Herrenschmidt , Paul Mackerras , linuxppc-dev Subject: Re: [PATCH 07/14] powerpc: Add support for restartable sequences In-Reply-To: <277374719.2144.1526570889798.JavaMail.zimbra@efficios.com> References: <20180430224433.17407-1-mathieu.desnoyers@efficios.com> <20180430224433.17407-8-mathieu.desnoyers@efficios.com> <20180516161837.GI12198@hirez.programming.kicks-ass.net> <112970629.1913.1526501596485.JavaMail.zimbra@efficios.com> <20180517011949.GA1121@tardis> <277374719.2144.1526570889798.JavaMail.zimbra@efficios.com> Date: Fri, 18 May 2018 22:38:44 +1000 Message-ID: <87sh6pxhnv.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Mathieu Desnoyers writes: > ----- On May 16, 2018, at 9:19 PM, Boqun Feng boqun.feng@gmail.com wrote: >> On Wed, May 16, 2018 at 04:13:16PM -0400, Mathieu Desnoyers wrote: >>> ----- On May 16, 2018, at 12:18 PM, Peter Zijlstra peterz@infradead.org wrote: >>> > On Mon, Apr 30, 2018 at 06:44:26PM -0400, Mathieu Desnoyers wrote: >>> >> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig >>> >> index c32a181a7cbb..ed21a777e8c6 100644 >>> >> --- a/arch/powerpc/Kconfig >>> >> +++ b/arch/powerpc/Kconfig >>> >> @@ -223,6 +223,7 @@ config PPC >>> >> select HAVE_SYSCALL_TRACEPOINTS >>> >> select HAVE_VIRT_CPU_ACCOUNTING >>> >> select HAVE_IRQ_TIME_ACCOUNTING >>> >> + select HAVE_RSEQ >>> >> select IRQ_DOMAIN >>> >> select IRQ_FORCED_THREADING >>> >> select MODULES_USE_ELF_RELA >>> >> diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c >>> >> index 61db86ecd318..d3bb3aaaf5ac 100644 >>> >> --- a/arch/powerpc/kernel/signal.c >>> >> +++ b/arch/powerpc/kernel/signal.c >>> >> @@ -133,6 +133,8 @@ static void do_signal(struct task_struct *tsk) >>> >> /* Re-enable the breakpoints for the signal stack */ >>> >> thread_change_pc(tsk, tsk->thread.regs); >>> >> >>> >> + rseq_signal_deliver(tsk->thread.regs); >>> >> + >>> >> if (is32) { >>> >> if (ksig.ka.sa.sa_flags & SA_SIGINFO) >>> >> ret = handle_rt_signal32(&ksig, oldset, tsk); >>> >> @@ -164,6 +166,7 @@ void do_notify_resume(struct pt_regs *regs, unsigned long >>> >> thread_info_flags) >>> >> if (thread_info_flags & _TIF_NOTIFY_RESUME) { >>> >> clear_thread_flag(TIF_NOTIFY_RESUME); >>> >> tracehook_notify_resume(regs); >>> >> + rseq_handle_notify_resume(regs); >>> >> } >>> >> >>> >> user_enter(); >>> > >>> > Again no rseq_syscall(). >>> >>> Same question for PowerPC as for ARM: >>> >>> Considering that rseq_syscall is implemented as follows: >>> >>> +void rseq_syscall(struct pt_regs *regs) >>> +{ >>> + unsigned long ip = instruction_pointer(regs); >>> + struct task_struct *t = current; >>> + struct rseq_cs rseq_cs; >>> + >>> + if (!t->rseq) >>> + return; >>> + if (!access_ok(VERIFY_READ, t->rseq, sizeof(*t->rseq)) || >>> + rseq_get_rseq_cs(t, &rseq_cs) || in_rseq_cs(ip, &rseq_cs)) >>> + force_sig(SIGSEGV, t); >>> +} >>> >>> and that x86 calls it from syscall_return_slowpath() (which AFAIU is >>> now used in the fast-path since KPTI), I wonder where we should call >> >> So we actually detect this after the syscall takes effect, right? I >> wonder whether this could be problematic, because "disallowing syscall" >> in rseq areas may means the syscall won't take effect to some people, I >> guess? >> >>> this on PowerPC ? I was under the impression that PowerPC return to >>> userspace fast-path was not calling C code unless work flags were set, >>> but I might be wrong. >>> >> >> I think you're right. So we have to introduce callsite to rseq_syscall() >> in syscall path, something like: >> >> diff --git a/arch/powerpc/kernel/entry_64.S b/arch/powerpc/kernel/entry_64.S >> index 51695608c68b..a25734a96640 100644 >> --- a/arch/powerpc/kernel/entry_64.S >> +++ b/arch/powerpc/kernel/entry_64.S >> @@ -222,6 +222,9 @@ system_call_exit: >> mtmsrd r11,1 >> #endif /* CONFIG_PPC_BOOK3E */ >> >> + addi r3,r1,STACK_FRAME_OVERHEAD >> + bl rseq_syscall >> + >> ld r9,TI_FLAGS(r12) >> li r11,-MAX_ERRNO >> andi. >> r0,r9,(_TIF_SYSCALL_DOTRACE|_TIF_SINGLESTEP|_TIF_USER_WORK_MASK|_TIF_PERSYSCALL_MASK) >> >> But I think it's important for us to first decide where (before or after >> the syscall) we do the detection. > > As Peter said, we don't really care whether it's on syscall entry or exit, as > long as the process gets killed when the erroneous use is detected. I think doing > it on syscall exit is a bit easier because we can clearly access the userspace > TLS, which AFAIU may be less straightforward on syscall entry. Coming in to the thread late, sorry if I'm missing the point. > We may want to add #ifdef CONFIG_DEBUG_RSEQ / #endif around the code you > proposed above, so it's only compiled in if CONFIG_DEBUG_RSEQ=y. That sounds good. A function call is not free even if it returns immediately. > On the ARM leg of the email thread, Will Deacon suggests to test whether current->rseq > is non-NULL before calling rseq_syscall(). I wonder if this added check is justified > as the assembly level, considering that this is just a debugging option. We already do > that check at the very beginning of rseq_syscall(). I guess it depends if this is one of those "debugging options" that's going to end up turned on in distro kernels? I think in that code we'd need to check paca->current->rseq, so that wouldn't be free either. cheers