Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp644649pxk; Wed, 9 Sep 2020 15:10:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwkSWraon5TQ48XZnG0wNuQUcSEst8Q1qV5uloH4uz7NyJ9notuNj5ft2pNKcZEXRqfeLES X-Received: by 2002:aa7:cd06:: with SMTP id b6mr6067866edw.196.1599689442983; Wed, 09 Sep 2020 15:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599689442; cv=none; d=google.com; s=arc-20160816; b=fBmn8atWfLMPjCGdRz7FpfkPZYo96+w8f1Q1L5WwSmJz9KC+zksy3vB2SvnSOo1Oht PukKeBB9ftXBCLpVVGeh1CTm5HDCIE/t+/q3im65fltrz9gG0kFmbuDkSoFcCrwRrSlB +bX15MOEJDd5vhnVkmFzAbToFQCxMIeqm8rNIkNVnW+JPmEPpG7L/NBSF4UTagicSjQG WVgsICW/HkJdWlR+Tkg6l66ylTGdw4iBKIllMptLLsjTiNDE2hDsF5pME9tVNJZfZGTw sJqEe79FFsjxVvn8m9+6wCO5odd1gdDDOmGMn5cevnvHdLa3aeql3oRsB6wWw5g3UwCy aiaw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:ironport-sdr:ironport-sdr; bh=9OxRWXbVYXCVk7igJWaB20KNHqdY/SujNHfGQptdiMo=; b=ctugWDq+aZnezRMrZkvzK+tlyZ0yf5buw4zvYi9J6jL+/FVB1QlXOLJ9pIUeQ1yQ2j uBjtnHAe32WmOx9JpYlucCychuE6QHdwCfmDrDJ12XWqwWo0Ap6DI8S1pbzYx8Efq6RW cTaihk/ng8FEZNHP1Clsnw45QD/I8DLBXM0c1Qci/wJLVqXL81FufxUrOvY8+XvBSrnO U16idBBZnvL2drUUL35JcMDdedtLKTGX5GaxsO4trqwlcPF0UIvGaRjgSYInmpsab94E YOpnlQGqvvJwHFtxgCG6fz84LK6j6FgzYZt1i8dQWL67iYFlLo0c8s8p3SPO+QMFw8Ps bjiQ== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si2308837edo.147.2020.09.09.15.10.20; Wed, 09 Sep 2020 15:10:42 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728626AbgIIWIy (ORCPT + 99 others); Wed, 9 Sep 2020 18:08:54 -0400 Received: from mga07.intel.com ([134.134.136.100]:28827 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726426AbgIIWIx (ORCPT ); Wed, 9 Sep 2020 18:08:53 -0400 IronPort-SDR: rB88rTxmgn560Wmexb9D7k1QbAWcu/ZPcOfYVbnU6Lb/CIxBUsMbWBgSa/XeFq/k3wd1o9YmKB I74jvwwqVEUw== X-IronPort-AV: E=McAfee;i="6000,8403,9739"; a="222625560" X-IronPort-AV: E=Sophos;i="5.76,410,1592895600"; d="scan'208";a="222625560" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2020 15:08:49 -0700 IronPort-SDR: ja8xYzSOffLJsq2Ox9FFmdIletFOF3lyTH0VA4m1Vmw4b8qS0c7zsH23hE2CtOCFggzkvXnwkW DJKaNSKnGGMQ== X-IronPort-AV: E=Sophos;i="5.76,410,1592895600"; d="scan'208";a="505606420" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.212.243.130]) ([10.212.243.130]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Sep 2020 15:08:46 -0700 Subject: Re: [PATCH v11 25/25] x86/cet/shstk: Add arch_prctl functions for shadow stack From: "Yu, Yu-cheng" To: Dave Hansen , Andy Lutomirski Cc: Dave Martin , "H.J. Lu" , 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 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> <32005d57-e51a-7c7f-4e86-612c2ff067f3@intel.com> <46dffdfd-92f8-0f05-6164-945f217b0958@intel.com> <6e1e22a5-1b7f-2783-351e-c8ed2d4893b8@intel.com> Message-ID: <5979c58d-a6e3-d14d-df92-72cdeb97298d@intel.com> Date: Wed, 9 Sep 2020 15:08:45 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <6e1e22a5-1b7f-2783-351e-c8ed2d4893b8@intel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/8/2020 11:25 AM, Yu, Yu-cheng wrote: > On 9/8/2020 10:57 AM, Dave Hansen wrote: >> On 9/8/20 10:50 AM, Yu, Yu-cheng wrote: >>> What about this: >>> >>> - Do not add any new syscall or arch_prctl for creating a new shadow >>> stack. >>> >>> - Add a new arch_prctl that can turn an anonymous mapping to a shadow >>> stack mapping. >>> >>> This allows the application to do whatever is necessary.  It can even >>> allow GDB or JIT code to create or fix a call stack. >> >> Fine with me.  But, it's going to effectively be >> >>     arch_prctl(PR_CONVERT_TO_SHS..., addr, len); >> >> when it could just as easily be: >> >>     madvise(addr, len, MADV_SHSTK...); >> >> Or a new syscall.  The only question in my mind is whether we want to do >> something generic that we can use for other similar things in the >> future, like: >> >>     madvise2(addr, len, flags, MADV2_SHSTK...); >> >> I don't really feel strongly about it, though.  Could you please share >> your logic on why you want a prctl() as opposed to a whole new syscall? >> > > A new syscall is more intrusive, I think.  When creating a new shadow > stack, the kernel also installs a restore token on the top of the new > shadow stack, and it is somewhat x86-specific.  So far no other arch's > need this. > > Yes, madvise is better if the kernel only needs to change the mapping. > The application itself can create the restore token before calling > madvise(). After looking at this more, I found the changes are more similar to mprotect() than madvise(). We are going to change an anonymous mapping to a read-only mapping, and add the VM_SHSTK flag to it. Would an x86-specific mprotect(PROT_SHSTK) make more sense? One alternative would be requiring a read-only mapping for madvise(MADV_SHSTK). But that is inconvenient for the application. Yu-cheng