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=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 B05FEC47420 for ; Fri, 25 Sep 2020 16:51:20 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 33CD6208B6 for ; Fri, 25 Sep 2020 16:51:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=amacapital-net.20150623.gappssmtp.com header.i=@amacapital-net.20150623.gappssmtp.com header.b="X0DpLV6l" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 33CD6208B6 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=amacapital.net Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A9E566B0078; Fri, 25 Sep 2020 12:51:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A4CD36B007B; Fri, 25 Sep 2020 12:51:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 93B566B007E; Fri, 25 Sep 2020 12:51:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0185.hostedemail.com [216.40.44.185]) by kanga.kvack.org (Postfix) with ESMTP id 775CB6B0078 for ; Fri, 25 Sep 2020 12:51:19 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 39C7A40D6 for ; Fri, 25 Sep 2020 16:51:19 +0000 (UTC) X-FDA: 77302174278.12.end46_40090ac27169 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 0AE5918009B72 for ; Fri, 25 Sep 2020 16:51:19 +0000 (UTC) X-HE-Tag: end46_40090ac27169 X-Filterd-Recvd-Size: 6522 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Fri, 25 Sep 2020 16:51:18 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id l71so3088620pge.4 for ; Fri, 25 Sep 2020 09:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=4XOAAiIQRCCNU86tnCHCg8fQuqW/LCTSjYNlXVnzp2A=; b=X0DpLV6lbBuvB1scwWVNnCPJ80OMbFrr6SBJC0ex7XH+Ht2IzQxNvwOFji/qqPWGjF S5LnN+V0Xzbst7EJrAmht8e/NuEC2LQ3hryzKnae6jiw3KuTdH89kIZOv9crXVRpEV0d kztSv1hhTmHEUXwWQUnZ5aBZd3ET54DExUFdo08fB9vDiB1dqarhPK006pwMdCRR2Eet U0vFIe+YManXCc5WhujOi61ob2w/wPWE6BRy2GzmlbDNvzXBQ4ByT/RO4D0YSx/F75It 5gN41S6u7ob0ZU2i4eqvy5ibWW8yTZ4WTFNAj1A588SY/4pzv09gKFujgnwCULdpsKNT Ee0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=4XOAAiIQRCCNU86tnCHCg8fQuqW/LCTSjYNlXVnzp2A=; b=CP3BmIpph3BP5fDJwkHhRhVCH+xwRZAyB4q5D0lY4yXHKcssYqEcWGJ3h38tnHzsMQ 4arHGIKw2b+3/PedmISn0ZlTL0BlWkVwiB5skUEmtJw+O1+CBoefPs/pfUzOfQ+tFBKv WrFKKWkrrVx19sD49IhUPvQF1vigvSbFC5WQtneSpOkxua6GX8gp0d7jsKPFRqHJKO8T AUZddda6sl6047IGL4uDMalp9/HwDz2MBb5M4Iwe7rHcYq3PDcNKIfU22BLFNBMZAYrd PvkoRdAYDBkL6616iE//DRgnaolqj5fh9DtYBYYioiFbVjwW3jZWSCFrlfXlEbpn3LW/ d3Xg== X-Gm-Message-State: AOAM533p3o/2F7SRyprws/USitqBF1iVJKhQH4957efeeUu6ftXykaMw 1dwOCCOzAOY2y5psPxp1QXwIow== X-Google-Smtp-Source: ABdhPJzmrvzRE0ItT8WGaJW6i9EQyNgQz1eC7YkG4/zQ1uzyIKPyWaVCi2nURst6I0Tm6/QcDV8Ebg== X-Received: by 2002:a17:902:fe0e:b029:d1:e5ec:28d6 with SMTP id g14-20020a170902fe0eb02900d1e5ec28d6mr298326plj.66.1601052677488; Fri, 25 Sep 2020 09:51:17 -0700 (PDT) Received: from localhost.localdomain (c-67-180-165-146.hsd1.ca.comcast.net. [67.180.165.146]) by smtp.gmail.com with ESMTPSA id w185sm3382485pfc.36.2020.09.25.09.51.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 25 Sep 2020 09:51:16 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v13 8/8] x86/vsyscall/64: Fixup Shadow Stack and Indirect Branch Tracking for vsyscall emulation Date: Fri, 25 Sep 2020 09:51:14 -0700 Message-Id: <99B32E59-CFF2-4756-89BD-AEA0021F355F@amacapital.net> References: Cc: Andy Lutomirski , 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 , Weijiang Yang , Pengfei Xu In-Reply-To: To: "Yu, Yu-cheng" X-Mailer: iPhone Mail (18A373) 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 Sep 25, 2020, at 9:48 AM, Yu, Yu-cheng wrote: >=20 > =EF=BB=BFOn 9/25/2020 9:31 AM, Andy Lutomirski wrote: >>> On Fri, Sep 25, 2020 at 7:58 AM Yu-cheng Yu wrot= e: >>>=20 >=20 > [...] >=20 >>> @@ -286,6 +289,37 @@ bool emulate_vsyscall(unsigned long error_code, >>> /* Emulate a ret instruction. */ >>> regs->ip =3D caller; >>> regs->sp +=3D 8; >>> + >>> +#ifdef CONFIG_X86_CET >>> + if (tsk->thread.cet.shstk_size || tsk->thread.cet.ibt_enabled) {= >>> + struct cet_user_state *cet; >>> + struct fpu *fpu; >>> + >>> + fpu =3D &tsk->thread.fpu; >>> + fpregs_lock(); >>> + >>> + if (!test_thread_flag(TIF_NEED_FPU_LOAD)) { >>> + copy_fpregs_to_fpstate(fpu); >>> + set_thread_flag(TIF_NEED_FPU_LOAD); >>> + } >>> + >>> + cet =3D get_xsave_addr(&fpu->state.xsave, XFEATURE_CET_U= SER); >>> + if (!cet) { >>> + fpregs_unlock(); >>> + goto sigsegv; >> I *think* your patchset tries to keep cet.shstk_size and >> cet.ibt_enabled in sync with the MSR, in which case it should be >> impossible to get here, but a comment and a warning would be much >> better than a random sigsegv. >=20 > Yes, it should be impossible to get here. I will add a comment and a warn= ing, but still do sigsegv. Should this happen, and the function return, the= app gets a control-protection fault. Why not let it fail early? I=E2=80=99m okay with either approach as long as we get a comment and warnin= g. >=20 >>=20 >> Shouldn't we have a get_xsave_addr_or_allocate() that will never >> return NULL but instead will mark the state as in use and set up the >> init state if the feature was previously not in use? >=20 > We already have a static __raw_xsave_addr(), which returns a pointer to th= e requested xstate. Maybe we can export __raw_xsave_addr(), if that is need= ed. I don=E2=80=99t think that=E2=80=99s what we want in general =E2=80=94 we wa= nt the whole construct of initializing the state if needed.=