Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp597858pxk; Thu, 3 Sep 2020 07:55:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw39HT73FSgVjNbcD788+0rbTLSxZhfNx05LHF5clirOOmJheT9IpNQ7ohon2knfkZSCOg/ X-Received: by 2002:a17:906:6c5:: with SMTP id v5mr2469031ejb.323.1599144953698; Thu, 03 Sep 2020 07:55:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599144953; cv=none; d=google.com; s=arc-20160816; b=pwISMpkuGqkHvw53RKs5SOIRgYdRRXibVOq8ZJHnNxq3VWpXCELvyCefThDoSO58NO s7MpeuhO71Y58UiT1g4KMfTmgQBJ98ax6K1X2AZqfzJr4etWLEk9Az5Vyj1Jj97J+5y3 gxds1GFzGkgVi/2UliMqmsh8uSDxEh0j4nN0UjqCd1hma4QyRNBI25PMS0ghSGaX/Qog HZdC8fFj1hGH8KINHSdPcPPKdl8t/8as05CvuJOOWKVVYhHWVhk3I+e63sGf5uJ670vp qtUDktk7QDmNE8eiEo59rKERoYlV2JVY7j/DUepm1RSfqvCl7QqF0yzUu3Sg9H3i/kQd aQpg== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=G7FcCH4h6xbcGB8Xt1/mggJDwe4tQgLoIHE0mvHbrzo=; b=Cd9Q0uUyEikDNLd+sjTY96744OPXabFKPW+0qF993bNmkYqE+DkUX9sLuahmRVYuy0 YY/kxztJqipljfmuo745+uT+FrYC70fr8lIOOd/9+umWv+rGvQWRtkTOiOF3kYWm76q+ eLAxp0BngsNTUswagyhCS+977ja2QE1BTPIR3cHXFx9BXpNEYooJHsq/j3fAwR/f3lEx 6pzxYowd/Cb+chzdgmZp7PjSBuJPhXjlv2ijfS8JA8oQD2bBq7K//eYq+Hs4WoDrUucw BF1MPHSg/WOozDJ1hrNKyji6npwHzEI5Bgv4zYqj8xqufyDSbdDH4Iz9lWNjqKMUvFrj Bf3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MfmZFBjT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l10si1867551edr.220.2020.09.03.07.55.30; Thu, 03 Sep 2020 07:55:53 -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=@kernel.org header.s=default header.b=MfmZFBjT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729273AbgICOyW (ORCPT + 99 others); Thu, 3 Sep 2020 10:54:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:52036 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729308AbgICOyT (ORCPT ); Thu, 3 Sep 2020 10:54:19 -0400 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 49DEC208C7 for ; Thu, 3 Sep 2020 14:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599144858; bh=mriIatmtdubimfxx6F+KYhhAQsXMp4Zfj9n/rnqEnYg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=MfmZFBjT64s2kj82dccACMNfccL3q/EDxxTceknRnn5UC3AImrGOzEffZCZJBQLHb xsY0ha/O5YBHgCotpGQ0WDdqXQ8tT675l0QXQ1Xgz+E+lw7gbhM7WmZIOITJodOcZN IMv6xVYpajk0/OrPonK7qnFLO3OuTIBZUFe3Lv/M= Received: by mail-wm1-f44.google.com with SMTP id b79so3188047wmb.4 for ; Thu, 03 Sep 2020 07:54:18 -0700 (PDT) X-Gm-Message-State: AOAM53228dX+Bg74con9Uxwyswl5RifygYalon0THJhILGW6TAyHAiDV 3zJZqs/jiJx2Ia8xcWXWRup2TffjduLFthErGma18g== X-Received: by 2002:a1c:740c:: with SMTP id p12mr2909254wmc.176.1599144856798; Thu, 03 Sep 2020 07:54:16 -0700 (PDT) MIME-Version: 1.0 References: <46e42e5e-0bca-5f3f-efc9-5ab15827cc0b@intel.com> <40BC093A-F430-4DCC-8DC0-2BA90A6FC3FA@amacapital.net> In-Reply-To: From: Andy Lutomirski Date: Thu, 3 Sep 2020 07:54:05 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET To: Dave Hansen Cc: "Yu, Yu-cheng" , Jann Horn , "the arch/x86 maintainers" , "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , kernel list , "open list:DOCUMENTATION" , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 3, 2020 at 7:27 AM Dave Hansen wrote: > > On 9/2/20 9:35 PM, Andy Lutomirski wrote: > >>>>>> + fpu__prepare_read(fpu); > >>>>>> + cetregs =3D 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 l= ooked at EFAULT, and it means "Bad address". Maybe this can be ENODEV, whi= ch means "No such device"? > > Having read the code, I=E2=80=99m unconvinced. It looks like a get_xsav= e_addr() failure means =E2=80=9Cstate not saved; task sees INIT state=E2=80= =9D. So *maybe* it=E2=80=99s reasonable -ENODEV this, but I=E2=80=99m not = really convinced. I tend to think we should return the actual INIT state an= d 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. > > 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. I think the core dump code gets here, too, so the values might be in registers as well. I hope that fpu__prepare_read() does the right thing in this case. --Andy