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 BF709C43217 for ; Tue, 15 Nov 2022 19:33:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8E7D26B0072; Tue, 15 Nov 2022 14:33:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 844516B0074; Tue, 15 Nov 2022 14:33:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5379D8E0001; Tue, 15 Nov 2022 14:33:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 38F236B0072 for ; Tue, 15 Nov 2022 14:33:56 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 1116D8012B for ; Tue, 15 Nov 2022 19:33:56 +0000 (UTC) X-FDA: 80136676872.29.3523EF3 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf13.hostedemail.com (Postfix) with ESMTP id 4744820003 for ; Tue, 15 Nov 2022 19:33:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=+TZHe91CVKHcCvipG59L2Mt6GN52GFDDf1u+Vof4nE8=; b=Q7ytUqvEOw0JQGQeiFz9eKB7XE u6IILmY6Rs0Zc6uh5cIj6pEjW+vBgPo0eHG6v2elnUwRtAC8nPSgOGuujaZpV0hZ79xT2Ivv1PiJD KfecqmbHOE6kDo00ZNMG0gOry5tG2JJqS6BGRCZY8ScUi3NDhq5scMHTJw4Eexwu7u38JC0t28g64 f7pP7BgeWXYSKITT0JtXpYtI8CyJK7AxypPIGUED56wzUpqpau7EuaPA0TuAS3QmwjHxM4dHThNWG gtOeX5R7Npcyfo6nvqYo7QPqxmBJaZLla4kr170lwgy6fcX+HTwQ9PSk4orOHlKHOhrFHOH/M8jJd e2gNgPOA==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ov1gd-00GXs4-9A; Tue, 15 Nov 2022 19:33:35 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id BA420300137; Tue, 15 Nov 2022 12:47:22 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 9E03B2015BE8A; Tue, 15 Nov 2022 12:47:22 +0100 (CET) Date: Tue, 15 Nov 2022 12:47:22 +0100 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" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Yu-cheng Yu Subject: Re: [PATCH v3 15/37] x86/mm: Check Shadow Stack page fault errors Message-ID: References: <20221104223604.29615-1-rick.p.edgecombe@intel.com> <20221104223604.29615-16-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221104223604.29615-16-rick.p.edgecombe@intel.com> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1668540835; a=rsa-sha256; cv=none; b=JxeezFiYbetq8JQxJ82oZmwBXhq7kr4YDKej8omWkLPchf2rM/33EQubVwsY1euRW9C2UW y0zpo9cpefcqO6kxLRIApQBjPIDx+wBU+98sPI/s474rTOUTWovm90rPub61nDQx0IoVDO VxPmP60cT573Mk1JDjdaYzNNShIb7y4= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Q7ytUqvE; spf=none (imf13.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1668540835; 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=+TZHe91CVKHcCvipG59L2Mt6GN52GFDDf1u+Vof4nE8=; b=omAWoFLjZg5ZXqLtwT4vEhs4W6FNLKhZnxVT+s3pyZtV6sInIRh171jR5FK9iOm2kLSXOK vnPYbmLz7jhFk+b+IJbUaqtjnZu4hFlSxlwZxyp5CM1X8uVgpqvmbMtWGQXkYg6Z0jP+dD Xc0VCh14rAx2kbl0rI2+nXoEpF0N790= X-Stat-Signature: jsq1wpfa9b3un99a4fgt8gkf5ggocem9 X-Rspamd-Queue-Id: 4744820003 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=Q7ytUqvE; spf=none (imf13.hostedemail.com: domain of peterz@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=peterz@infradead.org; dmarc=none X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1668540834-824702 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 Fri, Nov 04, 2022 at 03:35:42PM -0700, Rick Edgecombe wrote: > @@ -1331,6 +1345,18 @@ void do_user_addr_fault(struct pt_regs *regs, > > perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, address); > > + /* > + * To service shadow stack read faults, unlike normal read faults, the > + * fault handler needs to create a type of memory that will also be > + * writable (with instructions that generate shadow stack writes). > + * In the case of COW memory, the COW needs to take place even with > + * a shadow stack read. Otherwise the shared page will be left (shadow > + * stack) writable in userspace. So to trigger the appropriate behavior > + * by setting FAULT_FLAG_WRITE for shadow stack accesses, even if the > + * access was a shadow stack read. > + */ Clear as mud... So SS pages are 'Write=0,Dirty=1', which, per construction, lack a RW bit. And these pages are writable (WRUSS). pte_wrprotect() seems to do: _PAGE_DIRTY->_PAGE_COW (which is really weird in this situation), resulting in: 'Write=0,Dirty=0,Cow=1'. That's regular RO memory and won't raise read-faults. But I'm thinking RET will trip #PF here when it tries to read the SS because the SSP is not a proper shadow stack page? And in that case you want to tickle pte_mkwrite() to undo the pte_wrprotect() above? So while the #PF is a 'read' fault due to RET not actually writing to the shadow stack, you want to force a write fault so it will re-instate the SS page. Did I get that right? > + 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 >