Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6046196yba; Thu, 11 Apr 2019 10:53:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqynJ6V8hByYzzIpab887qZjrynei93x/7NvQEqB0WifUQ/bIKSVWCvhHTqAFckyglms4cc+ X-Received: by 2002:a17:902:988e:: with SMTP id s14mr49870991plp.167.1555005193537; Thu, 11 Apr 2019 10:53:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555005193; cv=none; d=google.com; s=arc-20160816; b=PZanGKJWZeEfGUAmXsbDL9moBcKt8O5LfI3M1Ox0BWAnw/8a9piKZrYnQNzWFwOm64 x/FGUDbgHLubiuHeLZ3RkH3RZpvFzCQIK51XBnVKKhSI5IN/CT0hPXGwZxiZlPi90/if /ib5nHqEpnC3QatRuxm6pHlz0593wWlwokAr6BqXkg7hRG1sxlFSMXUaMbH0emDDVdUA tSxFIl4lQCC/N+mNBLqbS7EYz0mGv2gRifAEZvOuXGlRlRxgVZSB2BJVC/243VLgAOtw ySCMHJI79Uwgwwx8SrULdjqXK0s30w8v50kJ0W9H5dicvWzDl2a/kx3TWjHBpZlOqaBO Usrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=vhsxrFXy1X+SwRp8Dcw0sUAHq25a6H/X/S6ETRMKmM8=; b=FVfcwwaL+/dbawMmeVVPxkqy+cROAQ5kVJ7u+gX+udMDRigm+pdxltjciw0RGZ/gDQ x5yMh0u5O9YOBVC78OO+Z2Fc4ZxTV2hmt3Qq17HRfdP0OZk/alQNy+ZIPB8WrQMzv/WY w7NEEc5DHGt/pSDYDedOk3qIvU8LOpUHoo55i6AjFukcC83gbzF43+oFssgea8tat/HU /cV0aGrWFvDzq0NItIxYDLiV5RNnxFnD2UHx/2OEJItnHrGX0ss69INNG8jkcUz2Zkc7 10U+f/utRRyNOcHnaqdKqdY/Bq1dIa10Q8VbtJ/SReYuilLGEwF2C4e0lD7bgU8yEyli x42w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=N2faBdda; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s17si21677662pfm.170.2019.04.11.10.52.57; Thu, 11 Apr 2019 10:53:13 -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; dkim=pass header.i=@efficios.com header.s=default header.b=N2faBdda; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbfDKRvz (ORCPT + 99 others); Thu, 11 Apr 2019 13:51:55 -0400 Received: from mail.efficios.com ([167.114.142.138]:58322 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726595AbfDKRvy (ORCPT ); Thu, 11 Apr 2019 13:51:54 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 6F7D71D3480; Thu, 11 Apr 2019 13:51:53 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id eK_xt-1xLeHD; Thu, 11 Apr 2019 13:51:52 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id B4B6F1D3475; Thu, 11 Apr 2019 13:51:52 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com B4B6F1D3475 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1555005112; bh=vhsxrFXy1X+SwRp8Dcw0sUAHq25a6H/X/S6ETRMKmM8=; h=Date:From:To:Message-ID:MIME-Version; b=N2faBddanJGu+zOA1uaw3QGNH9GpsSKBZT2BEu6Wdm7CvHLphg5Lix0Q7fwQXVxfu qafceUxF4ZbXjKnxrUPHeZrbuG6TRhbuWJ9tdIt/fBfGXMYaGgu+f08wrLWSD0NgsA ZUDxUnHXU3o0RfjlLNZv4irfWbEr0CXduZuARUI2IWTjoVzQmOWwCBIkHBz3VEggFn uaFrN3BlsAEDNCLG6quGwO9gXsxhpowp9fIRY+1VsHHodaTwsM6BaiAcSqxbaenmSo xsRUkWXfJJTlHv/z3LEjWJI2WL4+8NOHpS1ij1Mzh/4h5cWucbaZm7NDtDtsYatOQh 2wqE65TKdb8Pg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id oLaKaNOVLNiE; Thu, 11 Apr 2019 13:51:52 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 9178C1D346E; Thu, 11 Apr 2019 13:51:52 -0400 (EDT) Date: Thu, 11 Apr 2019 13:51:52 -0400 (EDT) From: Mathieu Desnoyers To: Will Deacon Cc: libc-alpha , linux-kernel , carlos , peter maydell , richard earnshaw Message-ID: <1469455003.811.1555005112414.JavaMail.zimbra@efficios.com> In-Reply-To: <20190411164219.GE29081@fuggles.cambridge.arm.com> References: <1050734985.2625.1554838340011.JavaMail.zimbra@efficios.com> <1933578130.3292.1554928159928.JavaMail.zimbra@efficios.com> <20190411164219.GE29081@fuggles.cambridge.arm.com> Subject: Re: rseq/arm32: choosing rseq code signature MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.12_GA_3794 (ZimbraWebClient - FF66 (Linux)/8.8.12_GA_3794) Thread-Topic: rseq/arm32: choosing rseq code signature Thread-Index: OaESARLi4wUkWowqO71sUhY1Y3b8bw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Apr 11, 2019, at 12:42 PM, Will Deacon will.deacon@arm.com wrote: > Hi Mathieu, > > On Wed, Apr 10, 2019 at 04:29:19PM -0400, Mathieu Desnoyers wrote: >> ----- On Apr 9, 2019, at 3:32 PM, Mathieu Desnoyers >> mathieu.desnoyers@efficios.com wrote: >> > We are about to include the code signature required prior to restartable >> > sequences abort handlers into glibc, which will make this ABI choice final. >> > We need architecture maintainer input on that signature value. >> > >> > That code signature is placed before each abort handler, so the kernel can >> > validate that it is indeed jumping to an abort handler (and not some >> > arbitrary attacker-chosen code). The signature is never executed. >> > >> > The current discussion thread on the glibc mailing list leads us towards >> > using a trap with uncommon immediate operand, which simplifies integration >> > with disassemblers, emulators, makes it easier to debug if the control >> > flow gets redirected there by mistake, and is nicer for some architecture's >> > speculative execution. >> > >> > We can have different signatures for each sub-architecture, as long as they >> > don't have to co-exist within the same process. We can special-case with >> > #ifdef for each sub-architecture and endianness if need be. If the architecture >> > has instruction set extensions that can co-exist with the architecture >> > instruction set within the same process (e.g. thumb for arm), we need to take >> > into account to which instruction the chosen signature value would map (and >> > possibly decide if we need to extend rseq to support many signatures). >> > >> > Here is an example of rseq signature definition template: >> > >> > /* >> > * TODO: document trap instruction objdump output on each sub-architecture >> > * instruction sets, as well as instruction set extensions. >> > */ >> > #define RSEQ_SIG 0x######## >> > >> > Ideally we'd need a patch on top of the Linux kernel >> > tools/testing/selftests/rseq/rseq-arm.h file that updates >> > the signature value, so I can then pick it up for the glibc >> > patchset. >> >> Would the following diff work for you ? If so, can I get your >> acked-by ? > > I had a quick chat with Richard and Peter (CC'd), since they're much more > familiar with the A32 instruction set than I am and also have a better view > of what might already be in use. > > Peter suggests that anything of the form 0xe7fxdefx should trap in both A32 > and T32, although it does assemble to UDF; B in T16. I'm not sure we > should get too obsessed with trying to encode a signature that universally > decodes to a trap. That's a nice trick. > > Whatever you choose, it would be worth checking that it doesn't clash with > other allocations such as software breakpoints in GDB. GDB seems to have [1] : #define ARM_LE_BREAKPOINT {0xFE,0xDE,0xFF,0xE7} #define ARM_BE_BREAKPOINT {0xE7,0xFF,0xDE,0xFE} #define THUMB_LE_BREAKPOINT {0xbe,0xbe} #define THUMB_BE_BREAKPOINT {0xbe,0xbe} None of which match the value you hint at. So I could pick "0xe7f5def3", which would map to the following comment: /* * RSEQ_SIG uses the udf A32 instruction with an uncommon immediate operand * value 0x5de3. This traps if user-space reaches this instruction by mistake, * and the uncommon operand ensures the kernel does not move the instruction * pointer to attacker-controlled code on rseq abort. * * The instruction pattern in the A32 instruction set is: * * e7f5def3 udf #24035 ; 0x5de3 * * This translates to the following instruction pattern in the T16 instruction * set: * * little endian: * def3 udf #243 ; 0xf3 * e7f5 b.n <7f5> * * big endian: * e7f5 b.n <7f5> * def3 udf #243 ; 0xf3 */ #define RSEQ_SIG 0xe7f5def3 Thoughts ? Thanks! Mathieu [1] https://github.com/bminor/binutils-gdb/blob/master/gdb/arm-tdep.c#L7705-L7742 -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com