Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp150085pxk; Wed, 2 Sep 2020 17:35:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz9A/MtP6UX1D/l1Xx2jcnGGBF0T+pXuYIqafj2IYa2wSK2Oo712Wlo/1wikxa1wwkcetZg X-Received: by 2002:a17:906:c55:: with SMTP id t21mr761388ejf.276.1599093341554; Wed, 02 Sep 2020 17:35:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599093341; cv=none; d=google.com; s=arc-20160816; b=LFzMGEySh9hPd0i5mRzMAqOwua8gvXCOD17lenWblLegowGim28uj8D0JSQX9uZAJY yPwZuP4s6Wdnp23Xyuic6wJyN+eFb1LqW+qznBcC48gnN1yN2FK4pSTlQ+ncfteThswd VAG23cMHjjlyaHJQdp4tLTX6OZf0U6GpOlrF09oY0+79fsTMmTcVECScnDyarkZ3Dnbj PUzQtRhgdgO68zROU7dq+G0iiVt1V1t5k4msf0V3PAdHxmNMfyS+23PN0oVTsGfm0WBG ZixHWa4n2B4bn21s1YCCaHbKb+AEZSGasqiDLa3CsrlHoaMI82gXkISiMvfxeQFti/0L hdvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=zuE9S2kX3yBdAXx6VDq5nZON6IsB7oZg0hs9UuY921M=; b=yy4DmC4nJGYQFFyZA5iObAlKPfgDY6P8/xTCyBpALfPrbXFIawNdc6buRhPlCxwK8L SgMmrJqSHwJKdQLzK5NjNUDFrA2rGnPq7dFU8JLn1hHl6nP+/lPleKpofGKjVn2YMI/J Pk6C85tLqc+ibX62xtJcUqrz3oJKtFxgNKzq2Gi6TBkA39w2BqJw8cDM5mbqDmM+dN2J xgDEGDb6oKN5kslvW5lqfpZp3vkEkqH4sotCZibM81vP5vZYl0+2g9dcEQp0JS4Z1ndi 1KlxLgQ33IOziBzTJHxklonSaYYws8dVwaLnDqX/iJ7HmX8+XCHUd82lZ+q5MoEb0fAM wwmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tIkG82mn; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d26si537296edu.514.2020.09.02.17.35.18; Wed, 02 Sep 2020 17:35: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; dkim=pass header.i=@google.com header.s=20161025 header.b=tIkG82mn; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726594AbgICAe0 (ORCPT + 99 others); Wed, 2 Sep 2020 20:34:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726913AbgICAeW (ORCPT ); Wed, 2 Sep 2020 20:34:22 -0400 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C608C061245 for ; Wed, 2 Sep 2020 17:34:21 -0700 (PDT) Received: by mail-ej1-x643.google.com with SMTP id lo4so1226126ejb.8 for ; Wed, 02 Sep 2020 17:34:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zuE9S2kX3yBdAXx6VDq5nZON6IsB7oZg0hs9UuY921M=; b=tIkG82mnDBNJywHLRaI6/zVNwcstLoIiktcOv/j/drukTe3Yyf8awFxGW8oN7DprMj /nBjEF6hZNuvXxJvt99XuFKiiKoQaLXsnOU1IBa1RWC5BfCawHRiB9URI5005NpDX6xs L5pO6G6KT/PwCl6jgRVxuSsy80FZ3M+y1beOsg72cbOVQkMFozp03IbLPQm3197YaODp j0tABAaAuD4XEAUNNNpGNZsVAkglNMIs7s3ZL5q3AcE827mQrUOf11oKHpzGuqSqYqjw MS5Dlac5YTP4IPqx2IgZcTW3WaTfLmK8pVI+og5WhZ5rgXi+NbEF/kFwqQ0pGpEzW+nt qu/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=zuE9S2kX3yBdAXx6VDq5nZON6IsB7oZg0hs9UuY921M=; b=DaWaTivcZ6ovK2wITCuDuWglMiAFWsLblhRqIbx7h1PT3x6sUUonwP9nKvjJyJ8O02 q8QUJtUG/8InhMdAlocY3voKYQ4DQau5ISx0/2v9Dib+ZV3JdLsC99bLCYiYRzyytPmx Homk5kMi0Y7PE6L9iC8gNmfpyCCzoJmBYedUVWYUcMPSYIhtZLCIj8HN8WG80xJRZSnu EBGsonKre5mdunNFdXmTUefEesDNxzghgSRR/VtZ68huPKnPuplr42SzRXHEYoY4j7F4 jnI3stgmVHv2BmY1hK4ci47NUC0HGJ2qErIX70miyoiMesGmDouOTcujRsSF65vjDaXE 0fRw== X-Gm-Message-State: AOAM531ipDuKwQZ9M5flUUlxSAH2JqWEgJ569dmDS8fnT7tnNhqp8CTY 2OFS1+vkPW+57oApR3kFJuGQyjjgvVIJmRHg6cdEBg== X-Received: by 2002:a17:907:94cf:: with SMTP id dn15mr747386ejc.114.1599093259495; Wed, 02 Sep 2020 17:34:19 -0700 (PDT) MIME-Version: 1.0 References: <20200825002645.3658-1-yu-cheng.yu@intel.com> <20200825002645.3658-7-yu-cheng.yu@intel.com> <9be5356c-ec51-4541-89e5-05a1727a09a8@intel.com> In-Reply-To: <9be5356c-ec51-4541-89e5-05a1727a09a8@intel.com> From: Jann Horn Date: Thu, 3 Sep 2020 02:33:53 +0200 Message-ID: Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET To: "Yu, Yu-cheng" Cc: "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 Content-Type: text/plain; charset="UTF-8" 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 12:13 AM 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"? Yeah, I guess ENODEV might fit reasonably well.