Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1079645ybl; Wed, 14 Aug 2019 10:21:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqxS3pZ6AmG3V2jJ9gyYrUEXbPIDLXHZKv7GcXqcBZWtrXolgt9AizZeQOljK7XocBLtQy2s X-Received: by 2002:a65:52c5:: with SMTP id z5mr259161pgp.118.1565803309017; Wed, 14 Aug 2019 10:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565803309; cv=none; d=google.com; s=arc-20160816; b=CcHmYkTlN2WhyjyeW5fUk4coqJjpNgU6Ss6eJdqbUSAirxbPus55qnSy6LwqyHL3PX kWX1+HZmTyWdT7+qdqg5dOuQHkDMtYG53cTCakS+ITbFShBU/4IfSymNi/3CgONrzF5x i8FOL9uQ8Ur+U2MyT+jekMKtK7NolPiA22uFXVMczHy68KFqIoDohc5iQd6hpl53Tg5l hb6KHJIfAlau6IF8s1ZJqzojVmhfxDPvPLVSiSXbS3cfXEVC1PATKSeMrCN6K3AvILj1 Tvo9z5DIT9FlujY8pEJ0SZpfjZYNZ/V1MEK6lN+bowryZpMXUNk6tQNc0LK4YIs1NGS+ aNUw== 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:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=e670mGFNNJiRe7dTnbDlWqdV8gKYNKd5awz5Vta9FfY=; b=iTAA1sPVgkc2KdnS8bGyLceEQhUD0d/C2v0/Z2KTqQe4VEwweTAi9hJDlhXmlomaJY AYfOBIUEYlcyse1BO8Q6tmWzccz35hGTMzxowo+UjLqU2r+PmwH/HyM6hyHZRisqmW5q bvRr0zBix5CQPuNsVen+FrnJEUp1hM/cAkMhetvr7brzZUHvfAOIssesIfFl1oSRk9uI TzbO9cr0FohDmWQirgvMr7XHq1TuMa8GQKwOCE07QF5CbCL9fRPX/SstFeyEdMQKN6dN JZIenvbK7lGu1T7gQAqUunIlO5Wd5YQDB8xQIjpvj60jGfW9HPs34xfKvJToyun0msvD /N1Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d19si219170pjw.36.2019.08.14.10.21.33; Wed, 14 Aug 2019 10:21:48 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730449AbfHNRKQ (ORCPT + 99 others); Wed, 14 Aug 2019 13:10:16 -0400 Received: from mga02.intel.com ([134.134.136.20]:43175 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729595AbfHNRKH (ORCPT ); Wed, 14 Aug 2019 13:10:07 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Aug 2019 10:10:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,386,1559545200"; d="scan'208";a="376806157" Received: from yyu32-desk1.sc.intel.com ([10.144.153.205]) by fmsmga006.fm.intel.com with ESMTP; 14 Aug 2019 10:10:05 -0700 Message-ID: Subject: Re: [PATCH v8 15/27] mm: Handle shadow stack page fault From: Yu-cheng Yu To: Dave Hansen , Andy Lutomirski Cc: 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 , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin Date: Wed, 14 Aug 2019 10:00:27 -0700 In-Reply-To: References: <20190813205225.12032-1-yu-cheng.yu@intel.com> <20190813205225.12032-16-yu-cheng.yu@intel.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2019-08-14 at 09:48 -0700, Dave Hansen wrote: > On 8/14/19 9:27 AM, Yu-cheng Yu wrote: > > On Tue, 2019-08-13 at 15:55 -0700, Andy Lutomirski wrote: > > > On Tue, Aug 13, 2019 at 2:02 PM 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. > > > > > > Is using VM_SHSTK and special-casing all of this really better than > > > using a special mapping or other pseudo-file-backed VMA and putting > > > all the magic in the vm_operations? > > > > A special mapping is cleaner. However, we also need to exclude normal [RO + > > dirty] pages from shadow stack. > > I don't understand what you are saying. > > Are you saying that we need this VM_SHSTK flag in order to exclude > RO+HW-Dirty pages from being created in non-shadow-stack VMAs? We use VM_SHSTK for page fault handling (the special-casing). If we have a special mapping, all these become cleaner (but more code). However, we still need most of the PTE macros (e.g. ptep_set_wrprotect, PAGE_DIRTY_SW, etc.). Yu-cheng