Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp259788pxk; Wed, 2 Sep 2020 21:39:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPc3hw2VKktE0SkzCMSOrTWThsGQ50L3T/e0VXL/zHNiKwMSgBcJUc8ZfOmN0HIfEHUMLD X-Received: by 2002:a05:6402:3199:: with SMTP id di25mr1206961edb.315.1599107988633; Wed, 02 Sep 2020 21:39:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599107988; cv=none; d=google.com; s=arc-20160816; b=qMCr8FS5qBSmK0QyH+lmoNibIc7LdHy8LZfimfX6ByJOaTcZcay6RJRF4WH7CwOQTY d2RL4Z3y88uhfwG7CYoX51mN+Pf1CDK+IN8SyfNWsGZM0pyXVQCiHvTMG9V2i9w8+Ozd sBEAgxBP2xLbVqdZUSTxo26SCPlinlbMNgsbnod2M+E6MAIIo4T/JWBYFoRSo0oIoNme q/vcNjaHgiy/buj+ALQe0ElpTO3Ng/3OV4ZkKXmNnZkqksDLXw0+IMNklgQqzx8AkH3l hWNISmdQwozBuUozile+bHGinWCXrZdrWqWXSamwR9/5S1YZcZPyxa5GERARlYoh4q5N jlNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:in-reply-to:cc:references:message-id :date:subject:mime-version:from:content-transfer-encoding :dkim-signature; bh=c4AodrXdr1y4XfEvpz1cwzbqc0Ntf48J70eL2aX9oQI=; b=YGEFsuTW0nlu9hwwENRSKYru6ZM3NvUj6oPNUBcVLA3SQwxKbmQn90UQspnP+tDUtf tWQ5eBKng1rDnWa1w3KNMBKl3yX81RxOxgkpIRv423dp3NIwZ3nGKcSU+ZwJL3Cjmend dLOknUy5RLIV5uumy6GTBWl0abjjNrYUNypePjVxpZ8+/UVmK6LuW2FBTWmYfw5QDFfW Dky+borNDBmTX2klm6XEz/5ziKc3XDQ3yn95zEPCVnm25DeEwOmGNGBE5WD0/Gil+5zT spV6rLjIqh6+ZsNUGxvUykC+RCp+4HwGX2eYZLWbw/KoLbYXbTVJVlGJl9jbDuFudO9V 9L7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=2TRg6Pt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p11si1133637edj.203.2020.09.02.21.39.25; Wed, 02 Sep 2020 21:39:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=2TRg6Pt2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726221AbgICEgC (ORCPT + 99 others); Thu, 3 Sep 2020 00:36:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726111AbgICEgA (ORCPT ); Thu, 3 Sep 2020 00:36:00 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F006AC061249 for ; Wed, 2 Sep 2020 21:35:59 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id gf14so835280pjb.5 for ; Wed, 02 Sep 2020 21:35:59 -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=c4AodrXdr1y4XfEvpz1cwzbqc0Ntf48J70eL2aX9oQI=; b=2TRg6Pt2o98tfWujTDiLLf6/VEGtI649lNEM2WkQGpk5OujV684ZLl1+qouHnVzCxI ToSXizqAPkBQ6AVBn1hMw0OAXSQYfxGE+Cd7YpFLxFHGLySOQlE4kNo98rNNCUXhNf0c arXqJo4aLZK1ppcDlHPJks8e3VOXyXWWVLeJEapUQJBuJ4hMrixSWr1qgns1jUDjIWTx pdxrHsyVQ1Z/mAfec2PKKlgYL0dGUd7OABGH/Sq4mWZiDXD0WghrDhnCj/k2bluv3Zsk z/YObrYdwUpa0M6OjGrUwZtO5PSXH20kWbGxRS0XihZlJktcT2tnAMU9AWWtGZEscSCp lx+w== 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=c4AodrXdr1y4XfEvpz1cwzbqc0Ntf48J70eL2aX9oQI=; b=qGKgoeutg6KBEAR5XmCOsOFQYG28XqT/PesORrnH2lVlrlnfQtdMJa6C0naWOyMfdn DfLJgns6cVyzfgJKzPicYXspLzZy+5DvqVST4zuYjhgAo2Wdr5MQXs1Z6X7crFT05X7R 8ptVrxro+QVTn70ccHFAgWqIYp6MFLVZR0guGkh6hSa4hVF6PlFXlGL+c05e/V+alJ+v +WkddDWSObJmBHBRB0y6NI/u55Sdj6ArpNZWam/kdMnSjVNdomr7ArseQnV3gJvk0vuK EgokKitrWO6q7FBeOIhcbbmgubrMuZmUmB5EM0UQ1rOnXTAGBb+cJU7+ZYU0ba2II1th 3irw== X-Gm-Message-State: AOAM531eQNcicewSVNmvIOilybr8fpW4+XMEHrhJoVFsocEhH6YajwE5 g/grgE2gVM7cHAV8MIUn56taYw== X-Received: by 2002:a17:90a:160f:: with SMTP id n15mr1310345pja.75.1599107759363; Wed, 02 Sep 2020 21:35:59 -0700 (PDT) Received: from ?IPv6:2600:1010:b068:276f:834:4bae:7a0f:cb7d? ([2600:1010:b068:276f:834:4bae:7a0f:cb7d]) by smtp.gmail.com with ESMTPSA id q34sm917533pgl.28.2020.09.02.21.35.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Sep 2020 21:35:58 -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 v11 6/9] x86/cet: Add PTRACE interface for CET Date: Wed, 2 Sep 2020 21:35:56 -0700 Message-Id: <40BC093A-F430-4DCC-8DC0-2BA90A6FC3FA@amacapital.net> References: <46e42e5e-0bca-5f3f-efc9-5ab15827cc0b@intel.com> Cc: Jann Horn , the arch/x86 maintainers , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , linux-doc@vger.kernel.org, Linux-MM , linux-arch , Linux API , Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , 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 In-Reply-To: <46e42e5e-0bca-5f3f-efc9-5ab15827cc0b@intel.com> To: "Yu, Yu-cheng" X-Mailer: iPhone Mail (17G80) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Sep 2, 2020, at 7:53 PM, Yu, Yu-cheng wrote: >=20 > =EF=BB=BFOn 9/2/2020 4:50 PM, Andy Lutomirski wrote: >>>> On Sep 2, 2020, at 3:13 PM, Yu, Yu-cheng wrote:= >>>=20 >>> =EF=BB=BFOn 9/2/2020 1:03 PM, Jann Horn wrote: >>>>> On Tue, Aug 25, 2020 at 2:30 AM Yu-cheng Yu wr= ote: >>>>> Add REGSET_CET64/REGSET_CET32 to get/set CET MSRs: >>>>>=20 >>>>> IA32_U_CET (user-mode CET settings) and >>>>> IA32_PL3_SSP (user-mode Shadow Stack) >>>> [...] >>>>> diff --git a/arch/x86/kernel/fpu/regset.c b/arch/x86/kernel/fpu/regset= .c >>>> [...] >>>>> +int cetregs_get(struct task_struct *target, const struct user_regset *= regset, >>>>> + struct membuf to) >>>>> +{ >>>>> + struct fpu *fpu =3D &target->thread.fpu; >>>>> + struct cet_user_state *cetregs; >>>>> + >>>>> + if (!boot_cpu_has(X86_FEATURE_SHSTK)) >>>>> + return -ENODEV; >>>>> + >>>>> + fpu__prepare_read(fpu); >>>>> + cetregs =3D get_xsave_addr(&fpu->state.xsave, XFEATURE_CET_USE= R); >>>>> + if (!cetregs) >>>>> + return -EFAULT; >>>> Can this branch ever be hit without a kernel bug? If yes, I think >>>> -EFAULT is probably a weird error code to choose here. If no, this >>>> should probably use WARN_ON(). Same thing in cetregs_set(). >>>=20 >>> When a thread is not CET-enabled, its CET state does not exist. I looke= d at EFAULT, and it means "Bad address". Maybe this can be ENODEV, which me= ans "No such device"? Having read the code, I=E2=80=99m unconvinced. It looks like a get_xsave_add= r() failure means =E2=80=9Cstate not saved; task sees INIT state=E2=80=9D. S= o *maybe* it=E2=80=99s reasonable -ENODEV this, but I=E2=80=99m not really c= onvinced. I tend to think we should return the actual INIT state and that we= should permit writes and handle them correctly. Dave, what do you think? >>>=20 >>> [...] >>>=20 >>>>> @@ -1284,6 +1293,13 @@ static struct user_regset x86_32_regsets[] __ro= _after_init =3D { >>>> [...] >>>>> + [REGSET_CET32] =3D { >>>>> + .core_note_type =3D NT_X86_CET, >>>>> + .n =3D sizeof(struct cet_user_state) / sizeof(u64), >>>>> + .size =3D sizeof(u64), .align =3D sizeof(u64), >>>>> + .active =3D cetregs_active, .regset_get =3D cetregs_ge= t, >>>>> + .set =3D cetregs_set >>>>> + }, >>>>> }; >>>> Why are there different identifiers for 32-bit CET and 64-bit CET when >>>> they operate on the same structs and have the same handlers? If >>>> there's a good reason for that, the commit message should probably >>>> point that out. >>>=20 >>> Yes, the reason for two regsets is that fill_note_info() does not expect= any holes in a regsets. I will put this in the commit log. >>>=20 >>>=20 >> Perhaps we could fix that instead? >=20 > As long as we understand the root cause, leaving it as-is may be OK. The regset mechanism=E2=80=99s interactions with compat are awful. Let=E2=80= =99s please not make it worse. One CET regret is good; two is not good. >=20 > I had a patch in the past, but did not follow up on it. >=20 > https://lore.kernel.org/lkml/20180717162502.32274-1-yu-cheng.yu@intel.com/= >=20 > Yu-cheng