From patchwork Sun Mar 19 00:15:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Edgecombe, Rick P" X-Patchwork-Id: 71694 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp532559wrt; Sat, 18 Mar 2023 18:36:17 -0700 (PDT) X-Google-Smtp-Source: AK7set/ba50oDyAvxU+T9OXv8bzqfalYR5d5VD5ljNvC1rw+wOBQjuwGvgumRgdYxVF9vIdkGk8C X-Received: by 2002:a05:6a20:6926:b0:c7:651c:1bae with SMTP id q38-20020a056a20692600b000c7651c1baemr13756897pzj.32.1679189777471; Sat, 18 Mar 2023 18:36:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679189777; cv=none; d=google.com; s=arc-20160816; b=msnbB+w2C3B/DF5UB7zPY3augfKAUt8R/SgIy5CTS0EXcweXtd1lDZV5Kn2QSsSTGR +MllTNMfeXdKbKI0LlxW+QUbyl3DTJrQVwxyAbnE1NZKeYPpWEkKC29HlwXdxWwb4bk0 3EXthSvRk9NKRdivRUqCEb3mapystiaD69hSxr5rlZJduYhe1tRVZjt/ADKDQsAXCak4 Ga1yhSQlC17ah6KExFyHBrF304r440wCiKfGFWWPC4iFWmrht7gzvrX62Sb3sGN217tw YdWtz9b/HEkkjgQQnJ3WPTwehbexRTKHvfMJJWcFFkdgd0O6+chOFnZ5Nqt3Kpo0qTx7 yrlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=gQxmIVCDyiXNijRz9GDbHj/9hmkObe8BeLOXxhdnjvY=; b=rIZArEJU6cs3lWY+lV0zzPEOLAwjpZGUkrYKaLlPH5+zk0A9VWUtooo++Vjjv3Ddy0 WIvvij49s8cwVKegqAmAWaa7EGxJXq8AluGIdHPh28X7vbn/ewpA5cKnk9T+Px1LcFm5 ZO0/SBZT3CvsB5i0aa1Z4nSVNwJhM5TzIT4uVWdYsLTtxdw/g6LhOYmhiWyAECwC+jFa x6t4I385KTJRaDNtR+XkpjEYfur4QX32GKu+w4PylW8woQNHL2xTEMDPFWVekKTkorjS IA9TmUraJRWhuy7bgkT9TZ33sCsCL23wH0mZoOn45Fg9TJsXFqKM+cWEQS0Csx/ABUp0 j0MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZcHZ+Plb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a634103000000b004fbc54ad3b6si6550344pga.470.2023.03.18.18.36.04; Sat, 18 Mar 2023 18:36:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ZcHZ+Plb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230016AbjCSAX2 (ORCPT + 99 others); Sat, 18 Mar 2023 20:23:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbjCSAWp (ORCPT ); Sat, 18 Mar 2023 20:22:45 -0400 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA6B22A151; Sat, 18 Mar 2023 17:20:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1679185226; x=1710721226; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=XWhd33s80bJV+B2OfEZjFLW5DvuhEuOlL0wc6R5POX8=; b=ZcHZ+Plb6w4zATX7xLbuJTEy7zEqYic7LTMTMp0GDKAxESu6hMkFr8Uv RqxWssiHFBuRRv7MWEkfjEj/+9v3e5S459EDJieHPJ6rpGJi5qJ3Fr/tY 8MpeFbsGkYbCyHXi8JafURPKwmXKBEXeVL0yjDBYE7Yk4F9qWWSrBPvNK ttafLOyQ92KM7EQitCy43F1NI57QhEzWIJg4dkMtxw7tZeuEGsI7Sl4Qt b5EWaiWKEolmcB+IrvUi4Io6s/I76/S9Gos96oVkbDThhUzki6nqW/KOO GnOhoji4vpEbuLggASXy7s98d08kH/h+Em2khPam/FOX/er+kmvQvl0bz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="338491534" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="338491534" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10653"; a="749672989" X-IronPort-AV: E=Sophos;i="5.98,272,1673942400"; d="scan'208";a="749672989" Received: from bmahatwo-mobl1.gar.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.135.34.5]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Mar 2023 17:16:53 -0700 From: Rick Edgecombe To: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, debug@rivosinc.com, szabolcs.nagy@arm.com Cc: rick.p.edgecombe@intel.com Subject: [PATCH v8 36/40] x86/shstk: Wire in shadow stack interface Date: Sat, 18 Mar 2023 17:15:31 -0700 Message-Id: <20230319001535.23210-37-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230319001535.23210-1-rick.p.edgecombe@intel.com> References: <20230319001535.23210-1-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760758100278005430?= X-GMAIL-MSGID: =?utf-8?q?1760758100278005430?= The kernel now has the main shadow stack functionality to support applications. Wire in the WRSS and shadow stack enable/disable functions into the existing shadow stack API skeleton. Signed-off-by: Rick Edgecombe Reviewed-by: Kees Cook Acked-by: Mike Rapoport (IBM) Tested-by: Pengfei Xu Tested-by: John Allen Tested-by: Kees Cook --- v4: - Remove "CET" references v2: - Split from other patches --- arch/x86/kernel/shstk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/shstk.c b/arch/x86/kernel/shstk.c index 01b45666f1b6..ee89c4206ac9 100644 --- a/arch/x86/kernel/shstk.c +++ b/arch/x86/kernel/shstk.c @@ -472,9 +472,17 @@ long shstk_prctl(struct task_struct *task, int option, unsigned long features) return -EINVAL; if (option == ARCH_SHSTK_DISABLE) { + if (features & ARCH_SHSTK_WRSS) + return wrss_control(false); + if (features & ARCH_SHSTK_SHSTK) + return shstk_disable(); return -EINVAL; } /* Handle ARCH_SHSTK_ENABLE */ + if (features & ARCH_SHSTK_SHSTK) + return shstk_setup(); + if (features & ARCH_SHSTK_WRSS) + return wrss_control(true); return -EINVAL; }