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=-8.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 7E857C433E2 for ; Thu, 3 Sep 2020 02:53:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2737120758 for ; Thu, 3 Sep 2020 02:53:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2737120758 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3077E8E0001; Wed, 2 Sep 2020 22:53:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B7DD6B0055; Wed, 2 Sep 2020 22:53:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1A7288E0001; Wed, 2 Sep 2020 22:53:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0079.hostedemail.com [216.40.44.79]) by kanga.kvack.org (Postfix) with ESMTP id 057D66B0037 for ; Wed, 2 Sep 2020 22:53:29 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id B0EFA181AEF09 for ; Thu, 3 Sep 2020 02:53:28 +0000 (UTC) X-FDA: 77220229296.08.pin15_3a0db78270a6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin08.hostedemail.com (Postfix) with ESMTP id 8B8951819E764 for ; Thu, 3 Sep 2020 02:53:28 +0000 (UTC) X-HE-Tag: pin15_3a0db78270a6 X-Filterd-Recvd-Size: 5474 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf45.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Sep 2020 02:53:27 +0000 (UTC) IronPort-SDR: +426ERJd5LN+VH1Nu6Nvn6cbU9SefIU+n9TcIpkoCoByCxubT320o8yq7Ws79Cy0K85mLKcfz9 TMXm6XWh6enQ== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="154911888" X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="154911888" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 19:53:25 -0700 IronPort-SDR: t+asyXuyfQSdPcnN23eLVIdO6o2QclIPFgTU1IGQt07uvHsMCCASuOZPLNnqwD9DPcUyoXp/aI zPYgRW+/WdRA== X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="446740721" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.209.147.104]) ([10.209.147.104]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 19:53:23 -0700 Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET To: Andy Lutomirski 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 References: <9be5356c-ec51-4541-89e5-05a1727a09a8@intel.com> From: "Yu, Yu-cheng" Message-ID: <46e42e5e-0bca-5f3f-efc9-5ab15827cc0b@intel.com> Date: Wed, 2 Sep 2020 19:53:22 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US X-Rspamd-Queue-Id: 8B8951819E764 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 Content-Transfer-Encoding: quoted-printable 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 9/2/2020 4:50 PM, Andy Lutomirski wrote: >=20 >=20 >> On Sep 2, 2020, at 3:13 PM, Yu, Yu-cheng wrote= : >> >> =EF=BB=BFOn 9/2/2020 1:03 PM, Jann Horn wrote: >>>> On Tue, Aug 25, 2020 at 2:30 AM Yu-cheng Yu = wrote: >>>> Add REGSET_CET64/REGSET_CET32 to get/set CET MSRs: >>>> >>>> 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/regs= et.c >>> [...] >>>> +int cetregs_get(struct task_struct *target, const struct user_regse= t *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_U= SER); >>>> + 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(). >> >> When a thread is not CET-enabled, its CET state does not exist. I loo= ked at EFAULT, and it means "Bad address". Maybe this can be ENODEV, whi= ch means "No such device"? >> >> [...] >> >>>> @@ -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_= get, >>>> + .set =3D cetregs_set >>>> + }, >>>> }; >>> Why are there different identifiers for 32-bit CET and 64-bit CET whe= n >>> 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. >> >> Yes, the reason for two regsets is that fill_note_info() does not expe= ct any holes in a regsets. I will put this in the commit log. >> >> >=20 > Perhaps we could fix that instead? >=20 As long as we understand the root cause, leaving it as-is may be OK. I had a patch in the past, but did not follow up on it. https://lore.kernel.org/lkml/20180717162502.32274-1-yu-cheng.yu@intel.com= / Yu-cheng