Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2516269imm; Thu, 7 Jun 2018 12:00:20 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIw6uVJtodAsXE2+KFH40JU9zr4nE//u8LifEq1BhhzkCZlp73LRpDYqbmdip5cog1jNKJZ X-Received: by 2002:a63:9843:: with SMTP id l3-v6mr2585848pgo.208.1528398020353; Thu, 07 Jun 2018 12:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528398020; cv=none; d=google.com; s=arc-20160816; b=ICtAl9Vomw3ebCezdZPSaHoPH/zCrRQpDk+qV2yVd8oesmu/+dmPEFuiW0EPocvnB5 ievVoI1XJ1RDDKs5c77DtFh524Un2KWvQLNVrbdk9dveU7z+IjTIGQgvqEsJZjuoVgwS oW2WGFHyiNCej3zfFT7rKLajWn1QVIZothIC61u2mK+zKgi0Fgdf10pVi0w2UqaMpm3J lSsZ0r4TW4GX5mXlzTKA2Aje4Jpatw53JJesnRZm2C2YVcOqLU87gjvnMo6iq3kcPVcm erag+fuph8FKZxPTkR7uwO3CtXXE30cDi3G7FDocC9iVw4RFiV7aiEcnXudLMSFxFmNl DeAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature :arc-authentication-results; bh=x7ZZrX1wrIFa3VGlYQrOUxCexnYT9juHZVfIGolqb0A=; b=0CVcd7MREwCGnycyLQEDsSLUMVsLUACGs0i1C6Id8gqOZ5pCUl+glmBOuO776cXe59 p45dg3xBbWRWYoKfKrGVfSeP0VVQt+ec63mmQREMAmQGsH6v8aYJEw0ba7N/vYpSWsis MOrPlMpt98Z84HQwELHsc2Lx5WD0j42jcFR9HnPxY6k5bhaa3kErgP+UPj1oCL4b0jQ2 ykvaJWnKojc79GDbaHPh1VBqNLGyh04JoMoiQMsSCEukARwoxoGbCumxsM04FjCL8ULJ s11P8vVc12noB5hxFDTdUpQ1+eUZ4bQ5+onfKZhrVFgUa5GFLX3b6hOEE4PR5kXAWVJx XRVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2b+T3tOg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c16-v6si16195542pli.269.2018.06.07.12.00.06; Thu, 07 Jun 2018 12:00:20 -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; dkim=pass header.i=@kernel.org header.s=default header.b=2b+T3tOg; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753843AbeFGQ0x (ORCPT + 99 others); Thu, 7 Jun 2018 12:26:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:60480 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753833AbeFGQ0u (ORCPT ); Thu, 7 Jun 2018 12:26:50 -0400 Received: from mail-wr0-f175.google.com (mail-wr0-f175.google.com [209.85.128.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 19E2F208A6 for ; Thu, 7 Jun 2018 16:26:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1528388810; bh=bAee33NTLeWiZFNKKO+RMmSCpWT9lSA5FeSOsnTXCW0=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=2b+T3tOg6jTQSIW7liwuPhan3ad3E+X2BGBQAE9y9EiBCelpRNxf0T8cXwWVIVdKy Ww26FmVm3BpGRXmhUUoUlNN1S6txFdi/LazEq3v0EP0Sfn3MY/YIj2HGvLI34y/3ut hjlFN5FEVNfB0N0o7TPggltRMkFAG83wwuYK7iLc= Received: by mail-wr0-f175.google.com with SMTP id o12-v6so10469759wrm.12 for ; Thu, 07 Jun 2018 09:26:50 -0700 (PDT) X-Gm-Message-State: APt69E0QAMDfwmGVNkd3p16ElW8Ikhjf1TbuAWjO5LalfsmTCNZkZROh i24pYQcMp3MxTUVYLy80+e6JjRJygM4PqAws8DA7Gw== X-Received: by 2002:adf:b1ca:: with SMTP id r10-v6mr2153714wra.221.1528388808481; Thu, 07 Jun 2018 09:26:48 -0700 (PDT) MIME-Version: 1.0 References: <20180607143705.3531-1-yu-cheng.yu@intel.com> <20180607143705.3531-8-yu-cheng.yu@intel.com> In-Reply-To: <20180607143705.3531-8-yu-cheng.yu@intel.com> From: Andy Lutomirski Date: Thu, 7 Jun 2018 09:26:36 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 7/9] x86/mm: Shadow stack page fault error checking To: Yu-cheng Yu Cc: LKML , linux-doc@vger.kernel.org, Linux-MM , linux-arch , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , "H. J. Lu" , "Shanbhogue, Vedvyas" , "Ravi V. Shankar" , Dave Hansen , Jonathan Corbet , Oleg Nesterov , Arnd Bergmann , mike.kravetz@oracle.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 7, 2018 at 7:40 AM Yu-cheng Yu wrote: > > If a page fault is triggered by a shadow stack access (e.g. > call/ret) or shadow stack management instructions (e.g. > wrussq), then bit[6] of the page fault error code is set. > > In access_error(), we check if a shadow stack page fault > is within a shadow stack memory area. > > Signed-off-by: Yu-cheng Yu > diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c > index 73bd8c95ac71..2b3b9170109c 100644 > --- a/arch/x86/mm/fault.c > +++ b/arch/x86/mm/fault.c > @@ -1166,6 +1166,17 @@ access_error(unsigned long error_code, struct vm_area_struct *vma) > (error_code & X86_PF_INSTR), foreign)) > return 1; > > + /* > + * Verify X86_PF_SHSTK is within a shadow stack VMA. > + * It is always an error if there is a shadow stack > + * fault outside a shadow stack VMA. > + */ > + if (error_code & X86_PF_SHSTK) { > + if (!(vma->vm_flags & VM_SHSTK)) > + return 1; > + return 0; > + } > + What, if anything, would go wrong without this change? It seems like it might be purely an optimization. If so, can you mention that in the comment?