Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp214211pxk; Wed, 2 Sep 2020 19:54:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeEEbWEQ7Szu+GG4t8qvUgLxJZmqlYq9NQh5/cIktrgw9E4MChr1UUciGf8KlTtJS1SeUh X-Received: by 2002:a17:906:178d:: with SMTP id t13mr1215718eje.410.1599101681983; Wed, 02 Sep 2020 19:54:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599101681; cv=none; d=google.com; s=arc-20160816; b=e6XOAIaPvZIAqBRERXJrU7RM6Kgc99cEXIUhf9Bb0ba7SYXse0ELLk3GmEcjV0rVv/ AjdkVuvb+9026BY/YD/KdneKxNI9SuX5VEP35XuYchN54iX6W2e5FfIoOEMNZDBXP4fQ ROCUIojNqa+cRXdjWJxXb9zfI0DdU9Mb6xzPaEkm/NKFyEDiW3sGKMOD6lNrnsMImUjV E8lX540HLFAkvZqLfNWdaVlvTPpl9DIJLzhrNWlFCf9+kNeGffvOYPiJOXVn3Vs/x2pS 4GhNuEx5f/SVEehzTAUOKxfDV7ZNhAJWvy5jTnAgxceQ0qOUR8n/xAmlmoP1NjwviFAw TBaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:ironport-sdr:ironport-sdr; bh=KHO56O0OrOpCOYSCc0QrF/1PU6pIFB+HoMkoJ9Lb8n4=; b=PA5WcLDDi6Q7ESuOc9QWN0Sv+VmsGJsO0vQzfU6CXT74K3LrF8a4CtMJWDNqRknKm4 TimC4t5A6ydfb7dnGSj5t8ZwitoD8VsElaCKK5CiRp4njEDHKgXEgmskWh/zhLQ1/s7Z eGJcOLvtgvDm8wVNfzffPHX00euSSVzo6z+sIPAWSzwAN6vKcrmzpp4iEqnjzMuZL/wZ CVWZoAkvGjuqWNz2JJj6Ywivnj/HI6jy5hgaW7yKiWnnSNhIqwQk2CIwNDokLegiwS8Z I3Np7p1M3ShhikLcz7ZmcPWCPRz7M7nao/M7evRTdXTobaIMHPDsqkgQc0u70RimVO94 fglA== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c20si750961edx.70.2020.09.02.19.54.19; Wed, 02 Sep 2020 19:54:41 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728104AbgICCx0 (ORCPT + 99 others); Wed, 2 Sep 2020 22:53:26 -0400 Received: from mga18.intel.com ([134.134.136.126]:55151 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726177AbgICCx0 (ORCPT ); Wed, 2 Sep 2020 22:53:26 -0400 IronPort-SDR: ctOvyHwD8IgpnkqdBTl3uOFfO8uA5EO9DQWRg1ZcFCLK0ApJpWMc6YjkOff4djrvruji+I3aLi nj0zvuqGyXwQ== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="145203420" X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="145203420" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga106.jf.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 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 9/2/2020 4:50 PM, Andy Lutomirski wrote: > > >> On Sep 2, 2020, at 3:13 PM, Yu, Yu-cheng wrote: >> >> On 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/regset.c >>> [...] >>>> +int cetregs_get(struct task_struct *target, const struct user_regset *regset, >>>> + struct membuf to) >>>> +{ >>>> + struct fpu *fpu = &target->thread.fpu; >>>> + struct cet_user_state *cetregs; >>>> + >>>> + if (!boot_cpu_has(X86_FEATURE_SHSTK)) >>>> + return -ENODEV; >>>> + >>>> + fpu__prepare_read(fpu); >>>> + cetregs = get_xsave_addr(&fpu->state.xsave, XFEATURE_CET_USER); >>>> + 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 looked at EFAULT, and it means "Bad address". Maybe this can be ENODEV, which means "No such device"? >> >> [...] >> >>>> @@ -1284,6 +1293,13 @@ static struct user_regset x86_32_regsets[] __ro_after_init = { >>> [...] >>>> + [REGSET_CET32] = { >>>> + .core_note_type = NT_X86_CET, >>>> + .n = sizeof(struct cet_user_state) / sizeof(u64), >>>> + .size = sizeof(u64), .align = sizeof(u64), >>>> + .active = cetregs_active, .regset_get = cetregs_get, >>>> + .set = 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. >> >> 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. >> >> > > Perhaps we could fix that instead? > 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