Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933653AbdDESOk (ORCPT ); Wed, 5 Apr 2017 14:14:40 -0400 Received: from mail-it0-f45.google.com ([209.85.214.45]:35884 "EHLO mail-it0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933504AbdDESOg (ORCPT ); Wed, 5 Apr 2017 14:14:36 -0400 MIME-Version: 1.0 In-Reply-To: <20170405174921.GB2752@e104818-lin.cambridge.arm.com> References: <20170404174727.35478-1-thgarnie@google.com> <20170404174727.35478-4-thgarnie@google.com> <20170405142225.GA9072@e104818-lin.cambridge.arm.com> <20170405174921.GB2752@e104818-lin.cambridge.arm.com> From: Thomas Garnier Date: Wed, 5 Apr 2017 11:14:34 -0700 Message-ID: Subject: Re: [PATCH v6 4/4] arm64/syscalls: Specific usage of verify_pre_usermode_state To: Catalin Marinas Cc: Mark Rutland , Kernel Hardening , Heiko Carstens , LKML , David Howells , Dave Hansen , "H . Peter Anvin" , Ingo Molnar , Pavel Tikhomirov , linux-s390 , "the arch/x86 maintainers" , Russell King , Will Deacon , Christian Borntraeger , Ingo Molnar , "Paul E . McKenney" , Stephen Smalley , Rik van Riel , Kees Cook , Arnd Bergmann , Brian Gerst , =?UTF-8?Q?Ren=C3=A9_Nyffenegger?= , Borislav Petkov , Al Viro , Andy Lutomirski , Josh Poimboeuf , Thomas Gleixner , linux-arm-kernel@lists.infradead.org, Linux API , Oleg Nesterov , James Morse , Martin Schwidefsky , Paolo Bonzini , Andrew Morton , "Kirill A . Shutemov" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1830 Lines: 51 On Wed, Apr 5, 2017 at 10:49 AM, Catalin Marinas wrote: > On Wed, Apr 05, 2017 at 07:36:17AM -0700, Thomas Garnier wrote: >> On Wed, Apr 5, 2017 at 7:22 AM, Catalin Marinas wrote: >> > On Tue, Apr 04, 2017 at 10:47:27AM -0700, Thomas Garnier wrote: >> >> + >> >> ldr x1, [tsk, #TSK_TI_FLAGS] >> >> and x2, x1, #_TIF_WORK_MASK >> >> cbnz x2, work_pending >> >> @@ -779,6 +788,12 @@ finish_ret_to_user: >> >> kernel_exit 0 >> >> ENDPROC(ret_to_user) >> >> >> >> +addr_limit_fail: >> >> + stp x0, lr, [sp,#-16]! >> >> + bl asm_verify_pre_usermode_state >> >> + ldp x0, lr, [sp],#16 >> >> + ret lr >> > >> > Where is this supposed to return? What is the value of lr when branching >> > to addr_limit_fail? >> >> It is not supposed to return. Do you think I should remove stp, ldp, >> ret and jut add a brk 0x100 or jmp/call a break/bug function? > > Can you not just make addr_limit_fail a C function which never returns > (similar to what we to with bad_mode() on arm64)? Since addr_limit_fail > is only called when the segment is not the right one, I don't really see > why you need another call to asm_verify_pre_usermode_state() to do a > similar check again. Just panic in addr_limit_fail (unless I > misunderstood what you are trying to achieve). Calling asm_verify_pre_usermode_state has the advantage of having a clear BUG_ON for the error (versus a panic description). What do you think about replacing asm_verify_pre_usermode_state by a "address_limit_fail" function that still calls verify_pre_usermode_state but panic afterwards (because it should never return)? The assembly code would be easier to understand and in case of error the BUG_ON is clear for the user. > > -- > Catalin -- Thomas