From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0C9FC433ED for ; Thu, 1 Apr 2021 11:15:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 6591861041 for ; Thu, 1 Apr 2021 11:15:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6591861041 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EC1B16B0080; Thu, 1 Apr 2021 07:15:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E71B86B0081; Thu, 1 Apr 2021 07:15:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D126A6B0082; Thu, 1 Apr 2021 07:15:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id B55566B0080 for ; Thu, 1 Apr 2021 07:15:51 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 6E01A182811C7 for ; Thu, 1 Apr 2021 11:15:51 +0000 (UTC) X-FDA: 77983543302.20.5732B97 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by imf24.hostedemail.com (Postfix) with ESMTP id 50BD7A00038A for ; Thu, 1 Apr 2021 11:15:49 +0000 (UTC) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-236-55FOPC1yNrCSB69XR94FFw-1; Thu, 01 Apr 2021 12:15:44 +0100 X-MC-Unique: 55FOPC1yNrCSB69XR94FFw-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 1 Apr 2021 12:15:43 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.012; Thu, 1 Apr 2021 12:15:43 +0100 From: David Laight To: 'Will Deacon' , Kees Cook CC: Thomas Gleixner , Elena Reshetova , "x86@kernel.org" , "Andy Lutomirski" , Peter Zijlstra , "Catalin Marinas" , Mark Rutland , Alexander Potapenko , Alexander Popov , Ard Biesheuvel , Jann Horn , Vlastimil Babka , David Hildenbrand , Mike Rapoport , Andrew Morton , Jonathan Corbet , Randy Dunlap , "kernel-hardening@lists.openwall.com" , "linux-hardening@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-mm@kvack.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v8 3/6] stack: Optionally randomize kernel stack offset each syscall Thread-Topic: [PATCH v8 3/6] stack: Optionally randomize kernel stack offset each syscall Thread-Index: AQHXJtFkunedSLxfaUq504kizLaNqaqfgZOw Date: Thu, 1 Apr 2021 11:15:43 +0000 Message-ID: <61ae9398a03d4fe7868b68c9026d5998@AcuMS.aculab.com> References: <20210330205750.428816-1-keescook@chromium.org> <20210330205750.428816-4-keescook@chromium.org> <20210401083034.GA8554@willie-the-truck> In-Reply-To: <20210401083034.GA8554@willie-the-truck> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Stat-Signature: fzjeutuz98z7adh8pwhqodx97j1pzen9 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 50BD7A00038A Received-SPF: none (aculab.com>: No applicable sender policy available) receiver=imf24; identity=mailfrom; envelope-from=""; helo=eu-smtp-delivery-151.mimecast.com; client-ip=185.58.85.151 X-HE-DKIM-Result: none/none X-HE-Tag: 1617275749-22055 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Will Deacon > Sent: 01 April 2021 09:31 ... > > +/* > > + * These macros must be used during syscall entry when interrupts and > > + * preempt are disabled, and after user registers have been stored to > > + * the stack. > > + */ > > +#define add_random_kstack_offset() do {=09=09=09=09=09\ > > +=09if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT,=09\ > > +=09=09=09=09&randomize_kstack_offset)) {=09=09\ > > +=09=09u32 offset =3D __this_cpu_read(kstack_offset);=09=09\ > > +=09=09u8 *ptr =3D __builtin_alloca(KSTACK_OFFSET_MAX(offset));=09\ > > +=09=09asm volatile("" : "=3Dm"(*ptr) :: "memory");=09=09\ >=20 > Using the "m" constraint here is dangerous if you don't actually evaluate= it > inside the asm. For example, if the compiler decides to generate an > addressing mode relative to the stack but with writeback (autodecrement),= then > the stack pointer will be off by 8 bytes. Can you use "o" instead? Is it allowed to use such a mode? It would have to know that the "m" was substituted exactly once. I think there are quite a few examples with 'strange' uses of memory asm arguments. However, in this case, isn't it enough to ensure the address is 'saved'? So: =09asm volatile("" : "=3Dr"(ptr) ); should be enough. =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)