Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp653036pxk; Thu, 3 Sep 2020 09:12:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvqQ9NEp9lTMDQUXjTYWKbuXmHO509jQAurufHJ8mB5aULqYpl5BKZg1vk4wEE+36k6qLC X-Received: by 2002:a50:f199:: with SMTP id x25mr3716017edl.347.1599149540325; Thu, 03 Sep 2020 09:12:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599149540; cv=none; d=google.com; s=arc-20160816; b=UeoF2kIdIJBCLTMkWMWsMIwEdXARGbE6uhPEt5rY577QNvsSA9ekyAdywie5w1kl7s 0rGKlwX0eicqUUD2G6Z7WidHzXcNwotEb11HDIV+NzlQqpz8T6tfI+R2i7/dr+C8tH9R c9wpUBUkSMwmWB8nbbEbOTqKn5BhjcZtT99EmRI50bjgEMZArgHZ6GiH4oqLXVMw1mUM 7wm34fd6dQzm5HfXP0tHZcAndmHr13dXzDcAItxWT+coBv3nn/JmDO0cw2JjNVEfrnSe WDpQshEax+tuil6ELrGnBGnOvAXB8PN7B4dDYhoA8XxZrNjKTUaZvHLMVzXt6j4ULoj+ PyRg== 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=rJWp+YAv8O3wuSQF7bveFyp3IIrq6l0WVkB/9UfZDYQ=; b=DInOrLEVPwDg6SCOS8nhsJdcdmqncBC9ql7LaiPWVb3joHgbSmZIeDveTyvJq0nL4X aaQQU63CX2aOXHxlzHTzQMS39xNSWDX6F+Bw872/KTnh7iIa05Itf64/FzItEz3q/7uF G243t7ugfSmoD9DZPM0k1J2WFFDPnIRbPV/s6T51Kzqyz7p+5Sq1FjXW0stif2jy2ZZH 9sl5utrZWVPGwk940jmAx0NA/wdhz5kXLZRLhxBCYdMKrqM7whkTmJL8eglSDYRrP08f /sU3Ox2a91wSvR5gQ6MOBwhvPMS0LViwpwxJVW15RAaz4gwlXQNKTH7M3Rsbs0Prcn4C A71Q== 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 j3si1949770edt.444.2020.09.03.09.11.54; Thu, 03 Sep 2020 09:12:20 -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 S1728561AbgICQJF (ORCPT + 99 others); Thu, 3 Sep 2020 12:09:05 -0400 Received: from mga12.intel.com ([192.55.52.136]:42295 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727786AbgICQJE (ORCPT ); Thu, 3 Sep 2020 12:09:04 -0400 IronPort-SDR: 1NhuyrsD94GV8ZMw89w7t0V1xuNWB8VuXgSJVnoettkb83VcOdd55dOpGtC+ZON/LuG7CYlF6c b7y8ofnHa3Fw== X-IronPort-AV: E=McAfee;i="6000,8403,9733"; a="137127466" X-IronPort-AV: E=Sophos;i="5.76,387,1592895600"; d="scan'208";a="137127466" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 09:09:03 -0700 IronPort-SDR: +C92qNo6vPQliFbZvRVoLeCI4c58RtTTyJZLqSfKqMdZx/NGqhVaiuZEkTHCzNP6ihEpbCixYB VQvGXEsgZUUQ== X-IronPort-AV: E=Sophos;i="5.76,387,1592895600"; d="scan'208";a="503116307" Received: from yyu32-mobl1.amr.corp.intel.com (HELO [10.209.173.133]) ([10.209.173.133]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Sep 2020 09:09:01 -0700 Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET To: Dave Hansen , 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: <46e42e5e-0bca-5f3f-efc9-5ab15827cc0b@intel.com> <40BC093A-F430-4DCC-8DC0-2BA90A6FC3FA@amacapital.net> From: "Yu, Yu-cheng" Message-ID: <88261152-2de1-fe8d-7ab0-acb108e97e04@intel.com> Date: Thu, 3 Sep 2020 09:09:01 -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/3/2020 7:26 AM, Dave Hansen wrote: > On 9/2/20 9:35 PM, Andy Lutomirski wrote: >>>>>>> + 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"? >> Having read the code, I’m unconvinced. It looks like a get_xsave_addr() failure means “state not saved; task sees INIT state”. So *maybe* it’s reasonable -ENODEV this, but I’m not really convinced. I tend to think we should return the actual INIT state and that we should permit writes and handle them correctly. > > PTRACE is asking for access to the values in the *registers*, not for > the value in the kernel XSAVE buffer. We just happen to only have the > kernel XSAVE buffer around. When get_xsave_addr() returns NULL, there are three possibilities: - XSAVE is not enabled or not supported; - The kernel does not support the requested feature; - The requested feature is in INIT state. If the debugger is going to write an MSR, only in the third case would this make a slight sense. For example, if the system has CET enabled, but the task does not have CET enabled, and GDB is writing to a CET MSR. But still, this is strange to me. > > If we want to really support PTRACE we have to allow the registers to be > get/set, regardless of what state they are in, INIT state or not. So, > yeah I agree with Andy. > GDB does not have a WRMSR mechanism. If GDB is going to write an MSR, it will call arch_prctl or an assembly routine in memory. Yu-cheng