Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1201401imm; Wed, 11 Jul 2018 20:01:04 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcQv59XroalYqfyk8byOT1y2lzvSarj/9SuBJFhm3PS0y62m5dWUm/GuU6H9ZVNhqhn0zdX X-Received: by 2002:a63:dd09:: with SMTP id t9-v6mr438958pgg.370.1531364464256; Wed, 11 Jul 2018 20:01:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531364464; cv=none; d=google.com; s=arc-20160816; b=sLCW7YYeSbO0HMn3hjiXGQtpmXYbmnuiRoUfstTCPaNvDnd7D4du42UITa5Pl47aM2 ZwT4xp56JTQcJe8tL6IJHIUyLmKrr0rymDc41t/1rlaJpXDz14Qu1Q4hX+QyUJQj0DIY bK2hx///yjXZUisN9uk6o3xf1UmqfW0XkyHZdcMXfZQLtyq3Ok0ByKcsJQWIJPQwk8+W GrbqHEFIalQr2Hv02zlKasWG9+7n+mR+NO21RuHFxEvzmEE5pGzx+Q/A7wY4Jg6LGRwN SFoGHUFVfb1AazEsT0KiwLx8VkLyclwIFSF1LWMCsR4btzF+pl7vugZWhFcI0CJ/+iic mVEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature:arc-authentication-results; bh=TVRNTmRWO2wQytdTDFngybIz4dJcoC9eCZgev1fFilQ=; b=pmn9egqVeSpLHKcElrD7CAODVRgFs9sGmV4ZNVRPRocLGJjPOwmtLiCKiX1c08sspC kS1M7YDkWsGbSd2u5hGM8wq2V9zQGf1aCU4uzwwikNDZ1iBKce4oi0eBXzinOn6QeCjU d94N60/s1wn4Mp/KtNGAua9YcMiBf7lBIztkVjzw2u/zJCFR/pRJT5Qs/vBS5wIoIwrZ vRfPWP9HIIezSwuXV611rccPOMvUZxm4GNLpDNpMGTKeLd63IZKGpLf/0NtVMe4/KoI9 PH6tKkKznwscxmFzQ3G3eXePQOZPh+erXlkLkpvDW1EBGI/hpTi/sW5BP16YYlztqpGa OsNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Kv24bkNG; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17-v6si4600994pgg.628.2018.07.11.20.00.48; Wed, 11 Jul 2018 20:01:04 -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=@google.com header.s=20161025 header.b=Kv24bkNG; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390582AbeGKV6J (ORCPT + 99 others); Wed, 11 Jul 2018 17:58:09 -0400 Received: from mail-oi0-f68.google.com ([209.85.218.68]:40985 "EHLO mail-oi0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390571AbeGKV6J (ORCPT ); Wed, 11 Jul 2018 17:58:09 -0400 Received: by mail-oi0-f68.google.com with SMTP id k12-v6so52034861oiw.8 for ; Wed, 11 Jul 2018 14:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TVRNTmRWO2wQytdTDFngybIz4dJcoC9eCZgev1fFilQ=; b=Kv24bkNGejoTFY6SOcx+SfP4MLgqa0d46z+gTLmMVdcvzEAApGa8/oaNamlpLZipXy CNPfGGsYQpaVRlQwcTrX3IO6cfTFEeaqZB/kgqIXUFnzhVt2kh+iKfrb3U/DWkQzpdHe PjtjIOzMd8PiIqEmMkbSxDH116Yupsqs1RIe5Z3ntQMtJXQeSNAFaJLRmRbjGPWWTgMA WKHfX/3a+gS1JjWrnxOvoXSRe3fGpxefL2fRyqqrl8qnkjSVZIQfKOOlVAg8SbAMd6dU zFMrg7AEVOpRRF2CM6mWxSPT7D0vG5xqPobrxLMDtO4kjOK60lsMTQclpjknzTSQBbj8 nskQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TVRNTmRWO2wQytdTDFngybIz4dJcoC9eCZgev1fFilQ=; b=L8eq1Rgm36a2slT4vEqjEL8CcVFD2UYIuW15tCVj5BYujPDKF27A8b+1KXj7ctV6wf 7hv5kv3PUVjca0sRWMkZwNDijta7I/oF6jAAM+r1OxNjt6w8bkKxUBNZ/F8o0G8+RkKb dusuDSGSLNwp0myMUX6VuFS3oX2Ot/jTVP+0A59TDunR2FWCigbnKXIAOia/faxZNM3T mvzrZ6BeJjQtmIaeFWNCf6r9vgjTWUCWVWFTixR34mqDTaGZjnrIaCZZhMKDVkKvY7q3 KUnAnBph9PiSnQzZg2Bl69kCuuwuGpLJpAYB8+MpaNs6zR0wfs2qA1iF1VSVkWQLaAGz MaCA== X-Gm-Message-State: AOUpUlFO7DhAQr61SfFshTxrrvSickvV8uRWioWP2uZyAWVjNsvwFk0S amgeGm2FOSjiH7RoQ7Lg3Ml5IK5K4ipC0iCjeDeneg== X-Received: by 2002:aca:d015:: with SMTP id h21-v6mr511553oig.142.1531345907484; Wed, 11 Jul 2018 14:51:47 -0700 (PDT) MIME-Version: 1.0 References: <20180710222639.8241-1-yu-cheng.yu@intel.com> <20180710222639.8241-18-yu-cheng.yu@intel.com> <6F5FEFFD-0A9A-4181-8D15-5FC323632BA6@amacapital.net> In-Reply-To: <6F5FEFFD-0A9A-4181-8D15-5FC323632BA6@amacapital.net> From: Jann Horn Date: Wed, 11 Jul 2018 14:51:21 -0700 Message-ID: Subject: Re: [RFC PATCH v2 17/27] x86/cet/shstk: User-mode shadow stack support To: Andy Lutomirski Cc: yu-cheng.yu@intel.com, "the arch/x86 maintainers" , "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , bsingharora@gmail.com, Cyrill Gorcunov , Dave Hansen , Florian Weimer , hjl.tools@gmail.com, Jonathan Corbet , keescook@chromiun.org, Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , ravi.v.shankar@intel.com, vedvyas.shanbhogue@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 11, 2018 at 2:34 PM Andy Lutomirski wrote= : > > On Jul 11, 2018, at 2:10 PM, Jann Horn wrote: > > > >> On Tue, Jul 10, 2018 at 3:31 PM Yu-cheng Yu wr= ote: > >> > >> This patch adds basic shadow stack enabling/disabling routines. > >> A task's shadow stack is allocated from memory with VM_SHSTK > >> flag set and read-only protection. The shadow stack is > >> allocated to a fixed size. > >> > >> Signed-off-by: Yu-cheng Yu > > [...] > >> diff --git a/arch/x86/kernel/cet.c b/arch/x86/kernel/cet.c > >> new file mode 100644 > >> index 000000000000..96bf69db7da7 > >> --- /dev/null > >> +++ b/arch/x86/kernel/cet.c > > [...] > >> +static unsigned long shstk_mmap(unsigned long addr, unsigned long len= ) > >> +{ > >> + struct mm_struct *mm =3D current->mm; > >> + unsigned long populate; > >> + > >> + down_write(&mm->mmap_sem); > >> + addr =3D do_mmap(NULL, addr, len, PROT_READ, > >> + MAP_ANONYMOUS | MAP_PRIVATE, VM_SHSTK, > >> + 0, &populate, NULL); > >> + up_write(&mm->mmap_sem); > >> + > >> + if (populate) > >> + mm_populate(addr, populate); > >> + > >> + return addr; > >> +} [...] > > Should the kernel enforce that two shadow stacks must have a guard > > page between them so that they can not be directly adjacent, so that > > if you have too much recursion, you can't end up corrupting an > > adjacent shadow stack? > > I think the answer is a qualified =E2=80=9Cno=E2=80=9D. I would like to i= nstead enforce a general guard page on all mmaps that don=E2=80=99t use MAP= _FORCE. We *might* need to exempt any mmap with an address hint for compati= bility. I like this idea a lot. > My commercial software has been manually adding guard pages on every sing= le mmap done by tcmalloc for years, and it has caught a couple bugs and cos= ts essentially nothing. > > Hmm. Linux should maybe add something like Windows=E2=80=99 =E2=80=9Crese= rved=E2=80=9D virtual memory. It=E2=80=99s basically a way to ask for a VA = range that explicitly contains nothing and can be subsequently be turned in= to something useful with the equivalent of MAP_FORCE. What's the benefit over creating an anonymous PROT_NONE region? That the kernel won't have to scan through the corresponding PTEs when tearing down the mapping?