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=-4.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no 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 9B5A1C433E9 for ; Thu, 3 Sep 2020 14:54:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 584372072A for ; Thu, 3 Sep 2020 14:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599144864; bh=mriIatmtdubimfxx6F+KYhhAQsXMp4Zfj9n/rnqEnYg=; h=References:In-Reply-To:From:Date:Subject:To:Cc:List-ID:From; b=Xoa8rya5UuPFib5hL+28Cu3Y3UccTGKuruXezDS6/tlwxhB6FhJ+YAC1qW+bp2z2b ALUYdfeeINLI+zQ1515Y+iXIvlTeTtZwdSm5SXXrZqViLu3PXUaXKFx9yew51MWM1L maEDQJ0xl2vgC/f+ns3+Q9BSCc4dlp+Yh66CTqfE= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729272AbgICOyV (ORCPT ); Thu, 3 Sep 2020 10:54:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:52062 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729309AbgICOyT (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 5E4812137B 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 z9so3212238wmk.1 for ; Thu, 03 Sep 2020 07:54:18 -0700 (PDT) X-Gm-Message-State: AOAM532FIEBbV6CQ8YUaPfPXskxZU4I+ap4uj67gUT6v1B7sy07INLzB 4qpU74zvIHmeKzfg7+XrP0pBmroyEEHWQggIrFwhQg== X-Google-Smtp-Source: ABdhPJwZWPiuPxsfeWv1J/1dfx0Phx0Z+CR6jZc6Vth7ClO5Nnnsw9BnQ2BG0ronnM+rSbGLQcOzQkjyBYwFKrdO6uM= 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-api-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-api@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