Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp17027pxk; Wed, 2 Sep 2020 13:05:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf85/z04ZBPUIiTPjqtP4dzqvkTKJ1dnri7uJvoz3I5n52zQ+9+ikc/PMdxDnXczQVEo62 X-Received: by 2002:a17:906:f1cf:: with SMTP id gx15mr1672774ejb.241.1599077114363; Wed, 02 Sep 2020 13:05:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599077114; cv=none; d=google.com; s=arc-20160816; b=VAj205Cw7wM9y/ZreIj469Sbl1MmsmuzdEraeCSscBmKeS16+bmxaKLR64bCs4Iuz9 WVwCKbz7GZ7jdU13qt3PNqcfqi6O8GHgP9cCeFd5nZFmyDY0uuSk8upDFn8wr2kr7Izy HZMWw1+Jrp/+9ObdWVRLLZKJnjpClAQpLh4swcB/Ah0g0zUV0uTbfkpe/7vuPavRqdp3 y1btZ8KiKeFKRR+AXHuFF5Vk2Nlvv8yifs9l7wOr9oJ3cSD8a58wIufHBEk1G7AeQ15k qokq1pC9B/l+i/1KZZyeiUzMI6MRHSRjoIGf09qiYC30Kt8V+i9dWNXW/idKVNjQuENb VrGQ== 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=F516FSLG1Fg8AtLKWaugsZmUz1NztosX6XlYqbdsuWY=; b=iV/g+712tNhuP4u9X/PW03g+yfNfyr9tX00Bnw7fMlKkBjJM7PbnjhuvDjeRpBQjgd lcjucPqJ1mcbFf72qbWgiudSNgVx3ZkIx/sfuUU9yr1GlP/m+lhIsNdWFHotHJHZGOJ5 6bgcQioHQvtXkBvOF7gyXW8hbJboRfNg3+ZhmgweBpOhqSZzZTEARb8DhMYBthtJxENb CcqwFRNXhKNhZ+soy5bBxdFhumwJrTQv/QAfJPTxmFWe6WxcXyQPgkQq1WADqvW1hkh+ zT5bbXfCcY0lsM4Pf770ROWaAs6zTpSoHByjH5cuNrVEyz7rUfnlujaAbdvNBTcD4mPA d9gA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=f6Y2z+4e; 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 co12si223537edb.104.2020.09.02.13.04.51; Wed, 02 Sep 2020 13:05:14 -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=f6Y2z+4e; 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 S1726479AbgIBUEI (ORCPT + 99 others); Wed, 2 Sep 2020 16:04:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbgIBUEC (ORCPT ); Wed, 2 Sep 2020 16:04:02 -0400 Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45774C061246 for ; Wed, 2 Sep 2020 13:04:01 -0700 (PDT) Received: by mail-ej1-x642.google.com with SMTP id a15so399530ejf.11 for ; Wed, 02 Sep 2020 13:04:01 -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=F516FSLG1Fg8AtLKWaugsZmUz1NztosX6XlYqbdsuWY=; b=f6Y2z+4eUCL25q5+1hV+JdNT5QdsgtJQm4tYO85DSSJSP6ZbhVl0Pu/DGRtriAVW+b WfP1t1YBGF9QBZamybjj9qIxqSYyBtWhFH+UNdEsL5i46u/W/nO3/DaUVi8nknD45c6h dQmMY6/P3s7DaNBO12JbCBxZsP/wuCG5/ZPos3Yi4GFKwWHFNFcBd24JwwQsnu+v+meI WccDRMkKFTcytzbZsyNJYl4UWpZa3uO5ENrpsL8JMWimpV6NgRkETZKsp6Je7IDQx/14 ZrGlSRPKBZHel/NtVFdQkQrr+l9Bnc9XSYPUtsdV77DkGFS9r+kfiSpO/cYOf/QQxkZV 3PIw== 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=F516FSLG1Fg8AtLKWaugsZmUz1NztosX6XlYqbdsuWY=; b=IAGntn00Z1ScyJ1TJiIjZLNf3xhrzgwFnpJKxB7JpEJL+9H+hb++/SYqqfJ5WmkKei VzoNsshJXv/sQA+petkDHoUpowMW9UM3/yk1GgKulETrqt1nnKV+dBSR7mq04sELu+5/ xWFZQbtcNCb/mlYQCE5fbSnnFt9/G3s6oH3+Rg3mU9nbUOcJfZM1i4cKA4H/KA5qJu/q 68b2mD1daFOOyV1qZ948zK7ho8G7QG92IHEb0Dxq8YtIzeiQDM8mf6lUWNWr9AyQJbuG AByYnKqezqKrE/yO5xn5tfQPIhCOX9gW6f/gzXHSl3kPapqGuTJKurW8/M94IZ30u8Lz X5yg== X-Gm-Message-State: AOAM5331KrjHndZvK66s9W0Zf3anJinYvSxC/SnUmYm72bksyoz1shj0 bmbC+d6hzBlsUe0MJ0FFBa9QnYjPjdUSpZwCBLFWuw== X-Received: by 2002:a17:906:4088:: with SMTP id u8mr1814815ejj.184.1599077039554; Wed, 02 Sep 2020 13:03:59 -0700 (PDT) MIME-Version: 1.0 References: <20200825002645.3658-1-yu-cheng.yu@intel.com> <20200825002645.3658-7-yu-cheng.yu@intel.com> In-Reply-To: <20200825002645.3658-7-yu-cheng.yu@intel.com> From: Jann Horn Date: Wed, 2 Sep 2020 22:03:33 +0200 Message-ID: Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET To: Yu-cheng Yu 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 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(). > + return membuf_write(&to, cetregs, sizeof(struct cet_user_state)); > +} [...] > diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c [...] > @@ -52,7 +52,9 @@ enum x86_regset { > REGSET_IOPERM64 = REGSET_XFP, > REGSET_XSTATE, > REGSET_TLS, > + REGSET_CET64 = REGSET_TLS, > REGSET_IOPERM32, > + REGSET_CET32, > }; [...] > @@ -1229,6 +1231,13 @@ static struct user_regset x86_64_regsets[] __ro_after_init = { [...] > + [REGSET_CET64] = { > + .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 > + }, > }; [...] > @@ -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.