Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1917330pxk; Tue, 1 Sep 2020 10:47:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUuShHEaKf48Jdq8mKklUMVBCmv9WPsGgqYT+fi3QKIUn1r7peWXObffCAc+aADZrMzpus X-Received: by 2002:a17:906:300b:: with SMTP id 11mr2557328ejz.270.1598982432885; Tue, 01 Sep 2020 10:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598982432; cv=none; d=google.com; s=arc-20160816; b=e7YX8AudpsipV9Culc0dHpCIyRLY0eJfTVnhqdLiwfCVXE/3t1hmSC8znueEpmgWmJ d2C45qgXSiYdHeHdrBKN/IR0X1ZXGTVBkua5njRYyj56MOaUgjmFxM9qyYl2V2xVtnjs 93zr5LSmMYV6sWpVxp3Ki9PhqmyMrJtNJGBxOqcZ9FS4V258y94zZe1Gdac/YLtqu4qr gAI/Ba1zaejd5z5QATnC/mG38SE56xY0MXOu4+W/gbZIe/6buGVbYYBfwtmfjWpCJ2+k CNJqcwAcJC/Rl1CopIf/6jMzo3YaLzWlgGwCSkizUagtIWmO+iVtSU4OnPnz0HvXCcAp RWlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TmUTPVDzUeSVk+qOF0Khtq1tuXSxFTEgT3iKifIpXkE=; b=CzmYud6x7b8c3ATUIjo1m1GJNiPzYal0O0B7nyfzMAxqyqJ7Z0eABJqX92KCdI1Req PmDdIzARd5/Y84WeRUJU58oh/e4U/JeGeJoLKAdd1n7qCNnIZbdKvytoOxjr6ciL5aoz vIjhJT+lIV/ZgLWL4L17ftJdwPC9CO7M/ybF7Yp3vhcJTFM90FdSwwidiFm8tn9V0w1F WyDfVhq7ad5B67SSJY+pW4mXqr7d4IhhqhZ/1FIpz6+5PGS61q3P4Eo/8oM9EEGgrH+N 2XMBePzXn6zPdxhj28LyOnLhW+zzYG3kNV/ZD4flLdcX3Z4ddcYQoYzFjyhHHSXyPU06 qH7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Xxq4jGgC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r25si976118edy.478.2020.09.01.10.46.49; Tue, 01 Sep 2020 10:47:12 -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; dkim=pass header.i=@kernel.org header.s=default header.b=Xxq4jGgC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728875AbgIARqL (ORCPT + 99 others); Tue, 1 Sep 2020 13:46:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:34180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726941AbgIARqH (ORCPT ); Tue, 1 Sep 2020 13:46:07 -0400 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 807B02087D for ; Tue, 1 Sep 2020 17:46:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598982366; bh=XFZ88HewQoEjX2uJ9z8eaQBKTvSmcqHdw3MZB06++UA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=Xxq4jGgC3FP6E6gs/q13XQfdoEec6OPL6DZe2AMlX8NETGLlw5cCIhOa+6nXyzLUX uoPktWkJN7ohYD0ZUWHIzNAtWE+iimV6ZSWTLQ9YxeYXOo2wb1XfqVUBSE/b9QQaOs Mu+RS9g2Aa3YatA3A8fs18faklWbaNh4F1BXA5bo= Received: by mail-wm1-f52.google.com with SMTP id o21so2045227wmc.0 for ; Tue, 01 Sep 2020 10:46:06 -0700 (PDT) X-Gm-Message-State: AOAM530QGQPu/y58N35brMuFNcuLntL+sh2+SqTHrS4Zl0WywtSXpihn 1Cp8GcQaZnrTEEZ55/1VMB6oTNJPzAunGw/UgvLHAA== X-Received: by 2002:a1c:2983:: with SMTP id p125mr2831445wmp.21.1598982364949; Tue, 01 Sep 2020 10:46:04 -0700 (PDT) MIME-Version: 1.0 References: <086c73d8-9b06-f074-e315-9964eb666db9@intel.com> <73c2211f-8811-2d9f-1930-1c5035e6129c@intel.com> <20200826164604.GW6642@arm.com> <87ft892vvf.fsf@oldenburg2.str.redhat.com> <0e9996bc-4c1b-cc99-9616-c721b546f857@intel.com> <4f2dfefc-b55e-bf73-f254-7d95f9c67e5c@intel.com> <20200901102758.GY6642@arm.com> In-Reply-To: From: Andy Lutomirski Date: Tue, 1 Sep 2020 10:45:53 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v11 25/25] x86/cet/shstk: Add arch_prctl functions for shadow stack To: "Yu, Yu-cheng" Cc: Dave Martin , "H.J. Lu" , Dave Hansen , Andy Lutomirski , Florian Weimer , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , LKML , "open list:DOCUMENTATION" , Linux-MM , linux-arch , Linux API , Arnd Bergmann , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Weijiang Yang Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 1, 2020 at 10:23 AM Yu, Yu-cheng wrote: > > On 9/1/2020 3:28 AM, Dave Martin wrote: > > On Thu, Aug 27, 2020 at 06:26:11AM -0700, H.J. Lu wrote: > >> On Wed, Aug 26, 2020 at 12:57 PM Dave Hansen wrote: > >>> > >>> On 8/26/20 11:49 AM, Yu, Yu-cheng wrote: > >>>>> I would expect things like Go and various JITs to call it directly. > >>>>> > >>>>> If we wanted to be fancy and add a potentially more widely useful > >>>>> syscall, how about: > >>>>> > >>>>> mmap_special(void *addr, size_t length, int prot, int flags, int type); > >>>>> > >>>>> Where type is something like MMAP_SPECIAL_X86_SHSTK. Fundamentally, > >>>>> this is really just mmap() except that we want to map something a bit > >>>>> magical, and we don't want to require opening a device node to do it. > >>>> > >>>> One benefit of MMAP_SPECIAL_* is there are more free bits than MAP_*. > >>>> Does ARM have similar needs for memory mapping, Dave? > >>> > >>> No idea. > >>> > >>> But, mmap_special() is *basically* mmap2() with extra-big flags space. > >>> I suspect it will grow some more uses on top of shadow stacks. It could > >>> have, for instance, been used to allocate MPX bounds tables. > >> > >> There is no reason we can't use > >> > >> long arch_prctl (int, unsigned long, unsigned long, unsigned long, ..); > >> > >> for ARCH_X86_CET_MMAP_SHSTK. We just need to use > >> > >> syscall (SYS_arch_prctl, ARCH_X86_CET_MMAP_SHSTK, ...); > > > > > > For arm64 (and sparc etc.) we continue to use the regular mmap/mprotect > > family of calls. One or two additional arch-specific mmap flags are > > sufficient for now. > > > > Is x86 definitely not going to fit within those calls? > > That can work for x86. Andy, what if we create PROT_SHSTK, which can > been seen only from the user. Once in kernel, it is translated to > VM_SHSTK. One question for mremap/mprotect is, do we allow a normal > data area to become shadow stack? I'm unconvinced that we want to use a somewhat precious PROT_ or VM_ bit for this. Using a flag bit makes sense if we expect anyone to ever map an fd or similar as a shadow stack, but that seems a bit odd in the first place. To me, it seems more logical for a shadow stack to be a special sort of mapping with a special vm_ops, not a normal mapping with a special flag set. Although I realize that we want shadow stacks to work like anonymous memory with respect to fork(). Dave? --Andy