Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp130217pxk; Wed, 2 Sep 2020 16:54:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0MfauGsugkNlSRxqjJb6GITpvd8ub5gO5sdsusFrxOvEIm6Y/LUVidXi5uM84UDkV4JB+ X-Received: by 2002:a17:906:cf8b:: with SMTP id um11mr610436ejb.540.1599090874640; Wed, 02 Sep 2020 16:54:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599090874; cv=none; d=google.com; s=arc-20160816; b=vd1Y0iwfv9EUm1U2ODcDzLcq/ZJhd69BVrX5e/qxQDARARiluuOSROpOoaE0k6ZOMF B9Xf+4YMCHohFvX18G/0/HtSRtTsNxJ2lp6V+iDm/ubHSzeb8RNsRLielhry0hUtJMWc 7D1lNbI0SfbYpYtUQSGjUTv7BfviYPbdBSFp1a4PP1LtQlpNrlZxJTZ/xGpo77e1XXvn QlizGIwT9zfEl13ajSQEC9ZSKMs0EvM8Dcq0HJO1s+9Jxth2+snaQGl3zDbg82Vcb6KY FbdWewTidL59aMJ1pKRUqa9/sC8SvoYlrOO8BRIF/Vqm/od0txWWpLTFFk2Q4OBvlOnc GCNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:in-reply-to:cc:references:message-id :date:subject:mime-version:from:content-transfer-encoding :dkim-signature; bh=52j/Kh79WBTwfCoci6XyBRUD0B5MrM8lpRUZ53T6r6c=; b=M2f3Y2WHfuzWFbzR5uzOXDlDhJ/4Dgvv8p3jH6CJX2PQ5wZxHsdEDJKNGfw16rv7lA NiRqVMDLGd5s/LyZnPLWNdeOjlTQgW2jZpODi6GaD6THpGX8IE3AspoNGMnc3TJwY7Bv tCeGUUUKsXGjrG94Y6r1uT2+NSYMTy8jhwXJU8YpzqzUx3kspdEwHnMK/X3s5wgq7gjV 2bUAJmDgNiP46gahLJzSzSWmrX2ISdD9BSKO5ZvAnivTJlCE1lM09K+1sDNXG0oj+/7p HzdkFL966ae6rRfxIdkVgQelwxh0sxz2mOgV3GPjdfRQsEB+XNg6Dih8w4pvh5tToaPR EIQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=is7KTIIg; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b19si560412edn.421.2020.09.02.16.54.08; Wed, 02 Sep 2020 16:54:34 -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=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=is7KTIIg; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726678AbgIBXui (ORCPT + 99 others); Wed, 2 Sep 2020 19:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgIBXuh (ORCPT ); Wed, 2 Sep 2020 19:50:37 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B444AC061246 for ; Wed, 2 Sep 2020 16:50:36 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id o20so673516pfp.11 for ; Wed, 02 Sep 2020 16:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:subject:date:message-id :references:cc:in-reply-to:to; bh=52j/Kh79WBTwfCoci6XyBRUD0B5MrM8lpRUZ53T6r6c=; b=is7KTIIg8tnyCVnXfRHW1zqu9WguvoK7VRQR0tcUVAhWNNnMt0afpmuqoSXKKDOqQ2 lOAO+TSk5rH+E7grKoBSNXbOHUuujEINvuG0qGnZKYpTmhU6vdxg5CRkRTu1rYsU8etp 18pwy0I0t8kxPw8tKuAkCYqCzyVFtBHogFDkbnP3g71YES9KWo4Llyc8PmixfyY9wyTq 771YhdsEiYuR47KHutTFgf8C9HN9WcWKl23JavtyLkVdK2crr9obWC7v51eS1llbQ2Wv ZuPHC6zfpgTgxSwa+hRNbyOb+chRDJPOp8Co0swB/PVLeYptrdTFdIwobjnPq+6zfp9Z QJQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version :subject:date:message-id:references:cc:in-reply-to:to; bh=52j/Kh79WBTwfCoci6XyBRUD0B5MrM8lpRUZ53T6r6c=; b=Cd3GTM4cxh1+sY9Kbhf7wh+gcD3k2VQ3f+z+kJ9kLBtwRDHBlNvGUxwlWp3BoR02Iv MCQpzD0ZdhggMuIWr73XjnL7osPPe7uIVuQ1I+uCcc/aJ/rarQ2od6k0mhZ30CnSf/ng 6p9pLRPmqAaaZn78tXZQksWaJQo9KJnOvWqMEutthzPsAg5VYLX8j/Nv2wEgYMy2Xe0W xL1CVGofvbU0kT3HmMV5r3h3aJGi+tBVvGeF3k1+0RfwA+akehS7oavPs3S6SPpCDJok Q+7Orpn1FbZttgyQpaEJHWvpFC+b22GAjxO/tX/cIPnQQ8VYmLb1vCyEmBZfHpAwmKtk qZNg== X-Gm-Message-State: AOAM533ZLbJ2rFcvBvthrqaNNSd9N85qgYQEndikSBudhSbeAzFCAoWO 62asofz/QAvjPCcvRXjVmmKl5Q== X-Received: by 2002:aa7:9f50:: with SMTP id h16mr849195pfr.178.1599090635689; Wed, 02 Sep 2020 16:50:35 -0700 (PDT) Received: from ?IPv6:2601:646:c200:1ef2:2197:2a30:2ff8:e80a? ([2601:646:c200:1ef2:2197:2a30:2ff8:e80a]) by smtp.gmail.com with ESMTPSA id o15sm427033pgi.74.2020.09.02.16.50.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Sep 2020 16:50:34 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Subject: Re: [PATCH v11 6/9] x86/cet: Add PTRACE interface for CET Date: Wed, 2 Sep 2020 16:50:32 -0700 Message-Id: References: <9be5356c-ec51-4541-89e5-05a1727a09a8@intel.com> 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 In-Reply-To: <9be5356c-ec51-4541-89e5-05a1727a09a8@intel.com> To: "Yu, Yu-cheng" X-Mailer: iPhone Mail (17G80) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Sep 2, 2020, at 3:13 PM, Yu, Yu-cheng wrote: >=20 > =EF=BB=BFOn 9/2/2020 1:03 PM, Jann Horn wrote: >>> On Tue, Aug 25, 2020 at 2:30 AM Yu-cheng Yu wrot= e: >>> Add REGSET_CET64/REGSET_CET32 to get/set CET MSRs: >>>=20 >>> 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 *r= egset, >>> + struct membuf to) >>> +{ >>> + struct fpu *fpu =3D &target->thread.fpu; >>> + struct cet_user_state *cetregs; >>> + >>> + if (!boot_cpu_has(X86_FEATURE_SHSTK)) >>> + return -ENODEV; >>> + >>> + 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(). >=20 > When a thread is not CET-enabled, its CET state does not exist. I looked a= t EFAULT, and it means "Bad address". Maybe this can be ENODEV, which means= "No such device"? >=20 > [...] >=20 >>> @@ -1284,6 +1293,13 @@ static struct user_regset x86_32_regsets[] __ro_a= fter_init =3D { >> [...] >>> + [REGSET_CET32] =3D { >>> + .core_note_type =3D NT_X86_CET, >>> + .n =3D sizeof(struct cet_user_state) / sizeof(u64), >>> + .size =3D sizeof(u64), .align =3D sizeof(u64), >>> + .active =3D cetregs_active, .regset_get =3D cetregs_get,= >>> + .set =3D 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. >=20 > Yes, the reason for two regsets is that fill_note_info() does not expect a= ny holes in a regsets. I will put this in the commit log. >=20 >=20 Perhaps we could fix that instead?=