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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 03A68C4332F for ; Fri, 14 Oct 2022 10:07:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 460B96B0072; Fri, 14 Oct 2022 06:07:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4108A6B0075; Fri, 14 Oct 2022 06:07:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B0D56B0078; Fri, 14 Oct 2022 06:07:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 171276B0072 for ; Fri, 14 Oct 2022 06:07:37 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id DB67A40CCF for ; Fri, 14 Oct 2022 10:07:36 +0000 (UTC) X-FDA: 80019128112.25.76A766B Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) by imf12.hostedemail.com (Postfix) with ESMTP id CA9CA4002F for ; Fri, 14 Oct 2022 10:07:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=L4LcT7d4jLsOBvjwIUOPjvR1C67SbCP8S9zjCTw+b2o=; b=MneAwRNqK978+qReSDZqbf8fim UdRSbq7lmjHyTh35JQdV6EthH34ObvMUiYYfpj08BShsMWHF52K0JjuOTlmahD6SHbiKfXPYikKYV /rzOQsR970gScpCntYCd7TwW+Y1ek1sy6mnIhepsW2PRKZPYCmg9olf8WL9MHREItELXqwt8xH88+ sna8Sc1k3lsXdvajEvbeYrzoZPTpaGoPCiPWLnVgG9VKn06Xu/S6aRRczUI0TQa8IU/K99NPKOfOF doqNcbA62hoHANW7n2c416I1Ts35IaJB6KhkkkQ+erlEeGR8rwDBQz+wplE1UT4Gf6pWByPcPIEci BPFiM9UQ==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ojHaw-003NqY-0V; Fri, 14 Oct 2022 10:07:10 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1C4E830008D; Fri, 14 Oct 2022 12:07:09 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id EDBD22C164D35; Fri, 14 Oct 2022 12:07:08 +0200 (CEST) Date: Fri, 14 Oct 2022 12:07:08 +0200 From: Peter Zijlstra To: Rick Edgecombe 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 , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, Yu-cheng Yu Subject: Re: [PATCH v2 15/39] x86/mm: Check Shadow Stack page fault errors Message-ID: References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-16-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220929222936.14584-16-rick.p.edgecombe@intel.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1665742055; a=rsa-sha256; cv=none; b=oWpmkVwPENaeq4bqK8EG7zBb+F6yUJMkuRotfCm0LufEb1lx97e39peac1nHseub3pZVFn K7bV49gSXdo/Z1p7EXw4RrEyAErYjy2Ed39R6SirwAcIxrFHig/peX4ojjlR6T0SRVL230 XpUysclPjoO/HJWBHNkFkZKOOAtJwHc= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=MneAwRNq; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1665742055; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=L4LcT7d4jLsOBvjwIUOPjvR1C67SbCP8S9zjCTw+b2o=; b=zudA0HbY0Qjgk6Hf5maBVETj7kXz7nYh4pUCBQUsAjpKqxcxxy+kpTuNZ8YuKZ6iyzB/j5 yo9ptF/eM37SmAKNWyO0W0oAEd9pr2F7vnPIKkZtqM9qSCbtrq5tno6fikS2J+DfkCCf1w SnpUlVjSB++yZ1qN/IJ8pXnJsfMXmfg= X-Stat-Signature: kcmkk3jowqa9bnd4h3f73p617kt4sq7w X-Rspamd-Queue-Id: CA9CA4002F Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=infradead.org header.s=desiato.20200630 header.b=MneAwRNq; dmarc=none; spf=none (imf12.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.92.199) smtp.mailfrom=peterz@infradead.org X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1665742054-77570 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 Thu, Sep 29, 2022 at 03:29:12PM -0700, Rick Edgecombe wrote: > The architecture has concepts of both shadow stack reads and shadow stack > writes. Any shadow stack access to non-shadow stack memory will generate > a fault with the shadow stack error code bit set. > > This means that, unlike normal write protection, the fault handler needs > to create a type of memory that can be written to (with instructions that > generate shadow stack writes), even to fulfill a read access. So in the > case of COW memory, the COW needs to take place even with a shadow stack > read. Otherwise the page will be left (shadow stack) writable in > userspace. So to trigger the appropriate behavior, set FAULT_FLAG_WRITE > for shadow stack accesses, even if the access was a shadow stack read. That ^ should be moved into the comment below > - Clarify reasoning for FAULT_FLAG_WRITE for all shadow stack accesses > @@ -1300,6 +1314,13 @@ void do_user_addr_fault(struct pt_regs *regs, > > perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); > > + /* > + * In order to fullfull a shadow stack access, the page needs > + * to be made (shadow stack) writable. So treat all shadow stack > + * accesses as writes. > + */ Because that's impenetrable. > + if (error_code & X86_PF_SHSTK) > + flags |= FAULT_FLAG_WRITE; > if (error_code & X86_PF_WRITE) > flags |= FAULT_FLAG_WRITE; > if (error_code & X86_PF_INSTR) > -- > 2.17.1 >