Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp684931pxf; Thu, 1 Apr 2021 10:52:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjUXCbquOyNecm6GfNmkJEnhDPf90O8VXx+RL42tzRISTzrvX72Z3SHh60xQ7yBb+Gn4t2 X-Received: by 2002:a05:6e02:1564:: with SMTP id k4mr7757653ilu.8.1617299545115; Thu, 01 Apr 2021 10:52:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617299545; cv=none; d=google.com; s=arc-20160816; b=F+ptOWEiIxziKg9Y0eiUSGTDq+EAqJaMo77YRBKKbmkYxFWZ4N1/hLxUNKaxg0xEm9 ACaXGhTtwH6uFEf4DiJ0QB2TpWwqPluqn72I5UCu7W/CnZVLvbM7Du5+tshPjqGqVSVQ XZ7T49yaRp8Lsx81DyP1KouHBze4sMkCvg6AvYjZJZHiI0YvNKZNDudvlGfxFMAmv3lT N8TVm0z5cubB9oEL51D5ALlOiTarCw5a0HixaLYEAzthtuqknQGMsN+2yY8mO+w9eoJ0 EDzZ9TAGehEAgIL1oohdyVRbHsTM0twc9l06qwd8QyP0dgL8jjPZYEktJSTj0szndOKr /sSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=bTHtChRpWhHBCq6qeKuNt6K3DimNvUtkJAezHaXgFAk=; b=kRTe51zPBi6tpwBgX5sTKzGPOtbsX+QNjASDzVJS8HrY/6fijoOfnVek357wpOWDOk T+YMKwI8lhJHR47RkknWMeN69Gz1r6/LSGscwirzMXpYGb6vY9w5R3r6pLn412AEQ0tF hzO08no79W6fsu9LhvFhOGvDtQ5/3rRpwV7FMWyfODq/T7fs4s17gDV4/fN/uCUJsXr3 M3zDm3OBcnux4T/6uQDsTsoBobHO2Vtyyn+iToN8HOgScgNoe4ghmrTGc49ZJB+yZzIp +XmzZymaFu4SVrzQsygzAbG5YKeZ3Gi9zwl1m0zQ/FroofueAl743qryyfFmJFc9KL+4 EqlA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 12si5336415ilj.28.2021.04.01.10.52.11; Thu, 01 Apr 2021 10:52:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237178AbhDARux convert rfc822-to-8bit (ORCPT + 99 others); Thu, 1 Apr 2021 13:50:53 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:52958 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234798AbhDARkQ (ORCPT ); Thu, 1 Apr 2021 13:40:16 -0400 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: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 { \ > > + if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \ > > + &randomize_kstack_offset)) { \ > > + u32 offset = __this_cpu_read(kstack_offset); \ > > + u8 *ptr = __builtin_alloca(KSTACK_OFFSET_MAX(offset)); \ > > + asm volatile("" : "=m"(*ptr) :: "memory"); \ > > 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: asm volatile("" : "=r"(ptr) ); should be enough. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)