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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 8F968C3F2D7 for ; Thu, 5 Mar 2020 18:30:26 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 620A5208CD for ; Thu, 5 Mar 2020 18:30:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 620A5208CD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id DCAA16B0005; Thu, 5 Mar 2020 13:30:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D550F6B0006; Thu, 5 Mar 2020 13:30:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C44946B0007; Thu, 5 Mar 2020 13:30:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0219.hostedemail.com [216.40.44.219]) by kanga.kvack.org (Postfix) with ESMTP id A59AC6B0005 for ; Thu, 5 Mar 2020 13:30:25 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 84E56180AD801 for ; Thu, 5 Mar 2020 18:30:25 +0000 (UTC) X-FDA: 76562148810.13.blood86_3a0debc99901 X-HE-Tag: blood86_3a0debc99901 X-Filterd-Recvd-Size: 3445 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Mar 2020 18:30:24 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Mar 2020 10:30:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,518,1574150400"; d="scan'208";a="233018095" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga007.fm.intel.com with ESMTP; 05 Mar 2020 10:30:22 -0800 Message-ID: Subject: Re: [RFC PATCH v9 14/27] mm: Handle Shadow Stack page fault From: Yu-cheng Yu To: Kees Cook Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , x86-patch-review@intel.com Date: Thu, 05 Mar 2020 10:30:22 -0800 In-Reply-To: <202002251218.F919026@keescook> References: <20200205181935.3712-1-yu-cheng.yu@intel.com> <20200205181935.3712-15-yu-cheng.yu@intel.com> <202002251218.F919026@keescook> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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: On Tue, 2020-02-25 at 12:20 -0800, Kees Cook wrote: > On Wed, Feb 05, 2020 at 10:19:22AM -0800, Yu-cheng Yu wrote: > > When a task does fork(), its Shadow Stack (SHSTK) must be duplicated for > > the child. This patch implements a flow similar to copy-on-write of an > > anonymous page, but for SHSTK. > > > > A SHSTK PTE must be RO and Dirty. This Dirty bit requirement is used to > > effect the copying. In copy_one_pte(), clear the Dirty bit from a SHSTK > > PTE to cause a page fault upon the next SHSTK access. At that time, fix > > the PTE and copy/re-use the page. > > Just to confirm, during the fork, it's really not a SHSTK for a moment > (it's still RO, but not dirty). Can other racing threads muck this up, > or is this bit removed only on the copied side? In [RFC PATCH v9 12/27] x86/mm: Modify ptep_set_wrprotect and pmdp_set_wrprotect for _PAGE_DIRTY_SW, _PAGE_DIRTY_HW is changed to _PAGE_DIRTY_SW with cmpxchg. That prevents racing. The hw dirty bit is removed from the original copy first. The next shadow stack access to the page causes copying. The copied page gets the hw dirty bit again. Yu-cheng