From patchwork Thu Apr 13 18:42:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210537 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7159C77B71 for ; Thu, 13 Apr 2023 18:43:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230016AbjDMSnF (ORCPT ); Thu, 13 Apr 2023 14:43:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229959AbjDMSnA (ORCPT ); Thu, 13 Apr 2023 14:43:00 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C37E16E8B for ; Thu, 13 Apr 2023 11:42:37 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id v6so15148819wrv.8 for ; Thu, 13 Apr 2023 11:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411356; x=1684003356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=W3zF9L90WHl9HX3lIHN8PhlLKSh7mZHA2/MDuZLToOo=; b=bTBM0JW+C7BcYhZCr/ZwN4e0PJj2h+EypJpRzhNHtzdmPJ9j8O7zkDjNbB2AAyGH3T oslP9XaSbUfejZqApiMG7qhUAN/DJ7vfosUlrvZ29Yel3NVxbD08TroxGdmBiC1koic2 xYTYhpUWBE4T8Znm2+S31VhDQhrYIbMgu9RV8sF6/9IWLw11QkTqB8F8Z+4/lyBSpD35 B1JWqPFXqxuS0PnZoI1/uQTgxi6iS4s3xEUMZV1KA5NS2jJMDVloIPLd6RKAQSk2HfQd nuDuSvNlICgDVcY7c+xHMSq92MF9RUyEbCd6COnPc4Dzrljp2E5wody+r3asBrdXAD/4 JXQA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411356; x=1684003356; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=W3zF9L90WHl9HX3lIHN8PhlLKSh7mZHA2/MDuZLToOo=; b=MVNNgPSBXAFwHrd0Zs+xSCZ3bfVm38syNVTdp/XRZdfK4UMOnDtOZ6mr5OzjGT91Ac 5HR0kw/YQH5YOPCRxF8dz/5k5gBF8YMLoKHImvpjnDTnMn3k9O5GBucAVaUxSCn4YI/V xsPS7gTMtPx4ZRcotECzokTFDGqxYfGIzcejCW2g3Q2vrNSrtnwxiLJiEPZE0cHVSqFt 4vG9NCrYO8tJXyjBAIWDyjgE+CEcBCan8X8Uj+M2WY3bOgXMX8p2k8J+8zFaclKnoN1w dgfBl1ViAaBgXveLd25XMC6zR8LgzzwvbByHESTjDKYry/RBie8Uyv8EO8LTbUgF4eX2 5xIw== X-Gm-Message-State: AAQBX9dOC4e6DratK24H7Vor4IE9jAG9syGZs8j4RrS/krAi52krE6FI pS5lakG4xbiQlGSiTwuneQpYZA== X-Google-Smtp-Source: AKy350aRw8htUWdbvnPpcFbpyEpuVQs4L7rJo5vRSpgLgaecwjUsgpDcuzfkEF8di/oB25AYWTFikg== X-Received: by 2002:adf:e7c1:0:b0:2ce:9fb8:b560 with SMTP id e1-20020adfe7c1000000b002ce9fb8b560mr2250082wrn.8.1681411356302; Thu, 13 Apr 2023 11:42:36 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:35 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 01/16] x86: Drop types.h Date: Thu, 13 Apr 2023 20:42:04 +0200 Message-Id: <20230413184219.36404-2-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The file types.h never declared any types, only exception vectors which are partially re-defined in processor.h. Move the remaining vector definitions to processor.h and remove types.h, as all users already include processor.h Signed-off-by: Mathias Krause --- lib/x86/processor.h | 7 +++++++ x86/types.h | 21 --------------------- x86/cmpxchg8b.c | 1 - x86/emulator.c | 1 - x86/pmu_pebs.c | 1 - x86/svm.c | 1 - x86/svm_tests.c | 1 - x86/vmx_tests.c | 1 - 8 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 x86/types.h diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 6555056e8a13..91a9022ef43c 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -19,16 +19,23 @@ # define S "4" #endif +#define DE_VECTOR 0 #define DB_VECTOR 1 +#define NMI_VECTOR 2 #define BP_VECTOR 3 +#define OF_VECTOR 4 +#define BR_VECTOR 5 #define UD_VECTOR 6 +#define NM_VECTOR 7 #define DF_VECTOR 8 #define TS_VECTOR 10 #define NP_VECTOR 11 #define SS_VECTOR 12 #define GP_VECTOR 13 #define PF_VECTOR 14 +#define MF_VECTOR 16 #define AC_VECTOR 17 +#define MC_VECTOR 18 #define CP_VECTOR 21 #define X86_CR0_PE_BIT (0) diff --git a/x86/types.h b/x86/types.h deleted file mode 100644 index 56ce5ececdec..000000000000 --- a/x86/types.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef X86_TYPES_H -#define X86_TYPES_H - -#define DE_VECTOR 0 -#define DB_VECTOR 1 -#define NMI_VECTOR 2 -#define BP_VECTOR 3 -#define OF_VECTOR 4 -#define BR_VECTOR 5 -#define UD_VECTOR 6 -#define NM_VECTOR 7 -#define DF_VECTOR 8 -#define TS_VECTOR 10 -#define NP_VECTOR 11 -#define SS_VECTOR 12 -#define GP_VECTOR 13 -#define PF_VECTOR 14 -#define MF_VECTOR 16 -#define MC_VECTOR 18 - -#endif diff --git a/x86/cmpxchg8b.c b/x86/cmpxchg8b.c index a416f44f2067..8afe629ea257 100644 --- a/x86/cmpxchg8b.c +++ b/x86/cmpxchg8b.c @@ -2,7 +2,6 @@ #include "vm.h" #include "libcflat.h" #include "desc.h" -#include "types.h" #include "processor.h" static void test_cmpxchg8b(u32 *mem) diff --git a/x86/emulator.c b/x86/emulator.c index ad9437403fef..f8bdc26b70ad 100644 --- a/x86/emulator.c +++ b/x86/emulator.c @@ -4,7 +4,6 @@ #include "vm.h" #include "libcflat.h" #include "desc.h" -#include "types.h" #include "processor.h" #include "vmalloc.h" #include "alloc_page.h" diff --git a/x86/pmu_pebs.c b/x86/pmu_pebs.c index 894ae6c784f9..d1a68ca336ab 100644 --- a/x86/pmu_pebs.c +++ b/x86/pmu_pebs.c @@ -8,7 +8,6 @@ #include "alloc.h" #include "vm.h" -#include "types.h" #include "processor.h" #include "vmalloc.h" #include "alloc_page.h" diff --git a/x86/svm.c b/x86/svm.c index ba435b4ac3af..63a84720709d 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -10,7 +10,6 @@ #include "vm.h" #include "fwcfg.h" #include "smp.h" -#include "types.h" #include "alloc_page.h" #include "isr.h" #include "apic.h" diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 27ce47b4f98e..691ac937288a 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -5,7 +5,6 @@ #include "msr.h" #include "vm.h" #include "smp.h" -#include "types.h" #include "alloc_page.h" #include "isr.h" #include "apic.h" diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 7952ccb932ea..96104ab018d8 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -16,7 +16,6 @@ #include "isr.h" #include "desc.h" #include "apic.h" -#include "types.h" #include "vmalloc.h" #include "alloc_page.h" #include "smp.h" From patchwork Thu Apr 13 18:42:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210538 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5400AC77B61 for ; Thu, 13 Apr 2023 18:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230057AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229977AbjDMSnB (ORCPT ); Thu, 13 Apr 2023 14:43:01 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 908C983D2 for ; Thu, 13 Apr 2023 11:42:38 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id k36-20020a05600c1ca400b003f0a7c483feso1711424wms.4 for ; Thu, 13 Apr 2023 11:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411357; x=1684003357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JYXXnoJo+Fwln2HbBX+xMIeux/r/zLuBKEudRVnzx2E=; b=nkkA8q2rgTsyLijgsc53fPGfUHqn1lg3v7jT8eSoPG7D7aO/Jx48zvh3GwoRFWwZVF D79CjpffokQYS+buYX+8s1RksveTyO5eLnfxwDzJMDO+3n3eQDaOE0BNlz09I5Kn78VO Y0RKRYj6HrYb6GF6ueMwMTnR4q90IusmiA2gCbh4PDX9HnGMGk9QQgngNwaBX6O1IWHn r9/yrYlUc0CbuS2LZ8c8vRHlec+vNnMajXxtF+vux9pnnaBTISioTP5FA+5zVBbpEgYR P3uJ5TXrYaEPF8PgE2wjfFdXuVZkl/pxwwI8ICPVtiHB9kXhlZHk99jtJ+QxRMztKw+G cYWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411357; x=1684003357; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JYXXnoJo+Fwln2HbBX+xMIeux/r/zLuBKEudRVnzx2E=; b=QN0Y+J/GFrIbEVeyoF+9C7UPe5a5ZrIc7KecTLhoXQnnImo0SqWn8M7LXxmQx0+G7r 67nqoWZglW6cj/vFuld84sikdHWAoKI/IEztsh3aNyEaTspDV0xOoTMChtEXwHOXF2oD QxnrymWshlArjogEm4a4CzgWpNGj1QnwMFzKlrpN4Bs/WxXD+cH3ByhiBn/KWaDTXI/9 mnCzzLF2aca4lb915xD3IODamuRcBkQDM3dU5IfEa7AdITwXKveTCSakediYosEuFt36 eLmzGEdLwkkYQTy68K5UgT2FmiEAhpY9DeV/uKeRGZ500JUIk8Cx3py0SqEuthJcJPqs MsyA== X-Gm-Message-State: AAQBX9e3Y0q2Mza3LLHPhyRWPm/xEZkBQxvIMonkqtWrPtqZRB6xJ0f8 cxpoC/bKfTO4HnelxKuKLo9qeg== X-Google-Smtp-Source: AKy350b+yioJVqwTnhXmfEtT2Zt5y8j8F338o1kKSbmRYa7hxA2pw0ClhQE90DxL7xrTbkHC9K1RZA== X-Received: by 2002:a05:600c:3783:b0:3ee:1a70:7ea2 with SMTP id o3-20020a05600c378300b003ee1a707ea2mr2157294wmr.3.1681411357154; Thu, 13 Apr 2023 11:42:37 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:36 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 02/16] x86: Use symbolic names in exception_mnemonic() Date: Thu, 13 Apr 2023 20:42:05 +0200 Message-Id: <20230413184219.36404-3-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use existing symbolic definitions for vector numbers instead of plain numbers and streamline the stringification further by using a macro. While at it, add the missing case for #CP. Signed-off-by: Mathias Krause --- lib/x86/processor.h | 1 + lib/x86/desc.c | 39 +++++++++++++++++++++------------------ 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 91a9022ef43c..5dd7bce024fd 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -36,6 +36,7 @@ #define MF_VECTOR 16 #define AC_VECTOR 17 #define MC_VECTOR 18 +#define XM_VECTOR 19 #define CP_VECTOR 21 #define X86_CR0_PE_BIT (0) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index b293ae420f86..9402c0ef59d0 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -110,25 +110,28 @@ extern struct ex_record exception_table_start, exception_table_end; const char* exception_mnemonic(int vector) { switch(vector) { - case 0: return "#DE"; - case 1: return "#DB"; - case 2: return "#NMI"; - case 3: return "#BP"; - case 4: return "#OF"; - case 5: return "#BR"; - case 6: return "#UD"; - case 7: return "#NM"; - case 8: return "#DF"; - case 10: return "#TS"; - case 11: return "#NP"; - case 12: return "#SS"; - case 13: return "#GP"; - case 14: return "#PF"; - case 16: return "#MF"; - case 17: return "#AC"; - case 18: return "#MC"; - case 19: return "#XM"; +#define VEC(v) case v##_VECTOR: return "#" #v + VEC(DE); + VEC(DB); + VEC(NMI); + VEC(BP); + VEC(OF); + VEC(BR); + VEC(UD); + VEC(NM); + VEC(DF); + VEC(TS); + VEC(NP); + VEC(SS); + VEC(GP); + VEC(PF); + VEC(MF); + VEC(AC); + VEC(MC); + VEC(XM); + VEC(CP); default: return "#??"; +#undef VEC } } From patchwork Thu Apr 13 18:42:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210539 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC1B6C77B6E for ; Thu, 13 Apr 2023 18:43:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230129AbjDMSnK (ORCPT ); Thu, 13 Apr 2023 14:43:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229994AbjDMSnB (ORCPT ); Thu, 13 Apr 2023 14:43:01 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C46B68A50 for ; Thu, 13 Apr 2023 11:42:39 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id q6so3696478wrc.3 for ; Thu, 13 Apr 2023 11:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411358; x=1684003358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CA16exKM/MAm93RteWP69jmc/+5rGl2ghMakVcYJgHw=; b=n7xipshTGY8EfjYjgwizXbd1mJmZcyNwrXHPLXx8HPiJ9Ya5TDzlxBHLI4JSsxPmyS ZjRDFX84p2hfdSeQV2YV/VxCGNNHhRpq+xvJPfp3o81i5I1Dm8ppSdhWoyNzv7tV7BSx no9ViUA8xa/2hoSJcWjsGSGsWfUpXXaVb9ABBlCDq9z81ljLBltqWoWlEEm4HTOVvyIG XV9RsjFz+4dJxNQkJPt+a8XZaGfM+XO5yBTguX17HFAYgHNbbK3qFYeeyuRvqgRLi2Dd 5UWKFALL+sSta98maJHuBndUM1nhmtzxNaUXdTX3jU9CPWaavU2qEFQQRdzo1UFoXszm BKuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411358; x=1684003358; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CA16exKM/MAm93RteWP69jmc/+5rGl2ghMakVcYJgHw=; b=kaAdPXl2RBDgD9N+kf5p9w9MG8nFQLuOCFPHCOiMOoy4jLV2ZmN31dHVNOiWYldyeV xKHXeXnO0NHwEvEP6pjXDMoDNr1aaoAiM8L0lU7kNgtksCvFTpjzwnYcvLStiky6EoSk xRgu7F60MHP25FSrzKN1gfbSLkJPCs76JbToKTbwJ2ogFIuR6kCE0xOXAgyXfUgA1v57 fVCJNBwbbG0+O8RL6OIZKfFmf2LEZ11zjk5dXzcVNvBiYhnc6jgKSs84EsRWI8JQXe1B 2pcGFHgEPNvmyp6ByjoyQ+MIREg5y/Kw4hVLb34eSkO3zSvfFchpt51eyJvHJTc/VJ2p pxBg== X-Gm-Message-State: AAQBX9fV53n9Z2rleUPY3qdrUnu5F7Jwwp8Cw4TdYXQIvG8ggobzAHD5 NxrfTNC7oAHB4p5sfD6AH5y92Q== X-Google-Smtp-Source: AKy350ZIxlcs1dDroEIOREcuPVWbvldHeBsV9f/B8ZsaP38PWbFm0XJVLMB2WgC24AV9l0pVRTAucg== X-Received: by 2002:adf:f049:0:b0:2f0:21b1:2ad5 with SMTP id t9-20020adff049000000b002f021b12ad5mr2270668wro.66.1681411357956; Thu, 13 Apr 2023 11:42:37 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:37 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 03/16] x86: Add vendor specific exception vectors Date: Thu, 13 Apr 2023 20:42:06 +0200 Message-Id: <20230413184219.36404-4-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Intel and AMD have some vendor specific exception vectors, namely: - Intel only: #VE (20), - AMD only: #HV (28), #VC (29) and #SX (30). Also Intel's #XM (19) is called #XF for AMD. Add definitions for all of these and add comments stating they're vendor specific. Signed-off-by: Mathias Krause --- lib/x86/processor.h | 5 +++++ lib/x86/desc.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index 5dd7bce024fd..7590c0c44c79 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -37,7 +37,12 @@ #define AC_VECTOR 17 #define MC_VECTOR 18 #define XM_VECTOR 19 +#define XF_VECTOR XM_VECTOR /* AMD */ +#define VE_VECTOR 20 /* Intel only */ #define CP_VECTOR 21 +#define HV_VECTOR 28 /* AMD only */ +#define VC_VECTOR 29 /* AMD only */ +#define SX_VECTOR 30 /* AMD only */ #define X86_CR0_PE_BIT (0) #define X86_CR0_PE BIT(X86_CR0_PE_BIT) diff --git a/lib/x86/desc.c b/lib/x86/desc.c index 9402c0ef59d0..06bb3e3c1e5d 100644 --- a/lib/x86/desc.c +++ b/lib/x86/desc.c @@ -129,7 +129,11 @@ const char* exception_mnemonic(int vector) VEC(AC); VEC(MC); VEC(XM); + VEC(VE); VEC(CP); + VEC(HV); + VEC(VC); + VEC(SX); default: return "#??"; #undef VEC } From patchwork Thu Apr 13 18:42:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210540 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDE58C77B61 for ; Thu, 13 Apr 2023 18:43:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230136AbjDMSnL (ORCPT ); Thu, 13 Apr 2023 14:43:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229738AbjDMSnB (ORCPT ); Thu, 13 Apr 2023 14:43:01 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39CA8524B for ; Thu, 13 Apr 2023 11:42:40 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id e16so1885869wra.6 for ; Thu, 13 Apr 2023 11:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411359; x=1684003359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RYGT5UY5doMRTiQspqkI0SekOpJHqqaQDCKMd+5DObo=; b=DQ/wJLeRsLds5mhQVNMv4zqyjAjdz7dbLKfC4jzGqjZ9n4F1+FCRJ7TamGdV0payKF n3XUdMAA/wcl83AFzr6aVoi8b9pQ7PaJqSPI6jTRjVacTPX2LybdI+4CoFsD5sV2UqsY XgocCTRkbcTn6jIaVESYvZQ6If+24XHLUbp3vtbnhtshiipnbi8MP+29uCQv1b6NV7b4 E9xyvdSZJtLaaNKZOkMneqmsOFIqD+75691CpD0sUNccBfC97xMtjwZMRYy/WcFoCNx7 N3RApX0dPH6LpF5QObZdiW5RETB/LbJD8vd2rX6XomfHPaMY8ORNVk5d4+bVQAv/GANJ OG2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411359; x=1684003359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RYGT5UY5doMRTiQspqkI0SekOpJHqqaQDCKMd+5DObo=; b=eKlcLRsAaJ95xFV5iFxIYLZGkJisTUqXpD5ZnrGqdprEedUWk2st7gINJ0LM+TjExD hM4t4znSDtDR65uzcEZvTw9LGx9frQnUSs2XFPi3J1R/O0kbCCslpfouuUCIwtOFB5R5 Ha/DLTUzwm6vfNjK07+v6Qqrh9+2vyBLv+thibjYJu8+GwavuOGImgXL/qCdndp/InNe p9DN4zbXEvT0XxJn5aRujhPdYxYuR/vkzikF5NSbTK1G4d9sQmV93X1MfaKEkbHN1M3w lU7Or3FznlEUpH3pi3ikJ4Crl6ztKxuPueDFuvJ3npxF+E5FVL1TWZL2s7v780OVzXFs JEXg== X-Gm-Message-State: AAQBX9efRextuRk8cS9e/MCP5bitkjBUQ+Mke/XbaTwRattixt9DuCum qcv9EqyarvH0RLsnpKNYnkXkYw== X-Google-Smtp-Source: AKy350YFvmzZEaXxvVYi+3HggSHUSHXpYB7ly4bYNCvkXr5dnEiaNvaj6JBVHVnynYCoBhA3TfJORA== X-Received: by 2002:a5d:4d0b:0:b0:2f6:3930:fa7f with SMTP id z11-20020a5d4d0b000000b002f63930fa7fmr1747202wrt.7.1681411358707; Thu, 13 Apr 2023 11:42:38 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:38 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 04/16] x86/cet: Use symbolic name for #CP Date: Thu, 13 Apr 2023 20:42:07 +0200 Message-Id: <20230413184219.36404-5-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make use of the symbolic name for the #CP vector number instead of hard-coding its value. Signed-off-by: Mathias Krause --- x86/cet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/cet.c b/x86/cet.c index c01dd89d9082..42d2b1fc043f 100644 --- a/x86/cet.c +++ b/x86/cet.c @@ -83,7 +83,7 @@ int main(int ac, char **av) } setup_vm(); - handle_exception(21, handle_cp); + handle_exception(CP_VECTOR, handle_cp); /* Allocate one page for shadow-stack. */ shstk_virt = alloc_vpage(); From patchwork Thu Apr 13 18:42:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210541 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 556BEC77B6E for ; Thu, 13 Apr 2023 18:43:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229997AbjDMSnN (ORCPT ); Thu, 13 Apr 2023 14:43:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjDMSnD (ORCPT ); Thu, 13 Apr 2023 14:43:03 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 325CD8A74 for ; Thu, 13 Apr 2023 11:42:41 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id q6so3696556wrc.3 for ; Thu, 13 Apr 2023 11:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411359; x=1684003359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RlFO6VQHbvsrhkxBXUqkpVJD2i9H4aa/y980IKqKnx0=; b=vh9vH0MzKGfpsWxpzzx0UjXKALj9f9ReWwFcZ5M8wJvAgsM4OzHJ6wxQL+kfvjx4eB Is0DPWPrAmGlRp5GMj+6o46KOzZ/ynfevTzLzhzJcmRRsJbsFkajjM/rXb62z7tZPoVZ 7BdxQr92bkaIQApdOwIF7ptAiodQ5uz/VgAcvBCwDntUxQrxguzu6aNheM9CwwGdRwYt dE1htxvjnovHc4pbAXt0EL5Weebv8jIHLmgBRPHSkToPuWiFbyCBhAe6vpd1kWvy0LW2 RhFZgAgavGbtTix6WwFZH1p47XZWobqmOOG5xtiPwzhN9Vul4irAZlX2JdX8nGZ7oAOQ EDdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411359; x=1684003359; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RlFO6VQHbvsrhkxBXUqkpVJD2i9H4aa/y980IKqKnx0=; b=MdsPrCygZgaZKfPvUMqhO/jdlR6ybk6eDcIcHQwHgleDGg3s+ybV0PvXHuWDXqwzua fQ0LlasYv3ZLbGidM6OokGBmv8TtBnV+hkeeZwIksVLpx1odoE+hloM9y4s5xaDB/nfj OXCGCo4J7CqRdXdVE0vAex1nsvqLbKB9SQ4jEA+NozgVo+j2ciXF+xBHFslAhtYCC6XH Sv8GiHle393di4JspwjN8tGjyR1ZPdlI3Zkwik00yTQ7mv4uHMWULjw5gw1XMFSc4+tW KR4qk51lUdQ9DPPBFpBusUVQtNcQEe0Ag6lv4JM8PQyGznXk1RmYT5rqgk/l+ylEe3ba PYmQ== X-Gm-Message-State: AAQBX9cYGJPshljlNYhEnth0XFkrqiTvAIk5/MnLGxA5E0mU+stYpEJt MnSgEKGpzO4XPPeCH76r9EUZjA== X-Google-Smtp-Source: AKy350Yv7exdByGADAB1ejtZMi+3XVQKEx0GhI5EwCdtbUgv7qGwXXsM5NNWs4F5HHK6Doh//Htqeg== X-Received: by 2002:a5d:6a89:0:b0:2ef:b051:95c5 with SMTP id s9-20020a5d6a89000000b002efb05195c5mr2148177wru.60.1681411359680; Thu, 13 Apr 2023 11:42:39 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:39 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 05/16] x86/access: Use 'bool' type as defined via libcflat.h Date: Thu, 13 Apr 2023 20:42:08 +0200 Message-Id: <20230413184219.36404-6-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop the unneeded definitions of 'true' and 'false' and make use of the common 'bool' type instead of using the pre-C99 / post-C23 definitions. Signed-off-by: Mathias Krause --- x86/access.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/x86/access.c b/x86/access.c index 70d81bf02d9d..f90a72d6e951 100644 --- a/x86/access.c +++ b/x86/access.c @@ -5,10 +5,7 @@ #include "x86/vm.h" #include "access.h" -#define true 1 -#define false 0 - -static _Bool verbose = false; +static bool verbose = false; typedef unsigned long pt_element_t; static int invalid_mask; @@ -406,7 +403,7 @@ static int ac_test_bump_one(ac_test_t *at) #define F(x) ((flags & x##_MASK) != 0) -static _Bool ac_test_legal(ac_test_t *at) +static bool ac_test_legal(ac_test_t *at) { int flags = at->flags; unsigned reserved; @@ -738,7 +735,7 @@ static void dump_mapping(ac_test_t *at) walk_va(at, F(AC_PDE_PSE) ? 2 : 1, virt, __dump_pte, false); } -static void ac_test_check(ac_test_t *at, _Bool *success_ret, _Bool cond, +static void ac_test_check(ac_test_t *at, bool *success_ret, bool cond, const char *fmt, ...) { va_list ap; @@ -780,7 +777,7 @@ static int ac_test_do_access(ac_test_t *at) unsigned e; static unsigned char user_stack[4096]; unsigned long rsp; - _Bool success = true; + bool success = true; int flags = at->flags; ++unique; From patchwork Thu Apr 13 18:42:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210542 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3839C77B61 for ; Thu, 13 Apr 2023 18:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230085AbjDMSnO (ORCPT ); Thu, 13 Apr 2023 14:43:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230011AbjDMSnF (ORCPT ); Thu, 13 Apr 2023 14:43:05 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07FDC8A42 for ; Thu, 13 Apr 2023 11:42:41 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id j15so1423521wrb.11 for ; Thu, 13 Apr 2023 11:42:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411360; x=1684003360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J3elqJXS+bFQRPcED8Mmzb52OGHkprqFCPRDONeOQX8=; b=iFWy001yG7k9NEXUCsSndo8Nhwvgc0bmmCTHHxkF22Kg2s51TGmPLA9kQH1AAHfalI l1UIiv9FMYGKYyDcL45ofyLTMuO2ICrk23p5HbsEaKSDfHNhFSFJ793fsO3cuvVzOmG/ Fs6MpUklJZLgJvuilvjnLXVd/7JuTpTd0I0Jt9REFp2dvk0SqUv1Lk6MJ7O2mU1D1JRZ qZ9WYi8AqrGXd+dnM3iW7wKiCWe74h4l1STaoW0hHkCfQ92XecZY7PF879dJBXtv9mDP GenYZjQfnPs2h7cnObjoMov9bNt/BnpV3WBDGejhtXfIdhivi5DirtSLJIiQoQPMgbXd /dPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411360; x=1684003360; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J3elqJXS+bFQRPcED8Mmzb52OGHkprqFCPRDONeOQX8=; b=FDzTPnzxOUouUHzoFjTG881tCWmENdYku36e+AsiRhtIHfqAg5IDhaw5sLmEKBRULb AaCPea0KhV6qKrZx2xCsN7Wz8U23tQdTmw/e56wygzgIyWzaPqP8rTuhmRU1dDaNyq1Y tXGdvmrStm72DPX7GYIwjbId/Ga+iJBw2cmGvIcHYsUZL2NOyj4kixyrwqGcF7/ye5+C CaXsY9ozsAKETdSyQVf6RDvn7Iy10AtYsuRVyhniQkHGfrsY7i+gjvqTT5fYh4uwOcmp Z50IcgOKZOWTz7mGrtf137CsHOQxsu0FAaAyDppEvnop8Sp8sCGxwKLnYrJsXAHzWEsz m2Iw== X-Gm-Message-State: AAQBX9e8KKS/Wswa1Yoe33G/4d7T4Lf+AsvX7hX6HlCt8/l2s8Lh3gOW YTHZk2Fo3holL9j2Ipbj0sGMkdVzfxPOdhL7C3k= X-Google-Smtp-Source: AKy350a6ISM9678Na2Gp3sMzcSy58f8GR2ePSp9gLnvjqU2GpoaNp77Br209RB/wJnRDUuTz3fRQiQ== X-Received: by 2002:a5d:5943:0:b0:2ef:b525:bdf9 with SMTP id e3-20020a5d5943000000b002efb525bdf9mr2306149wri.48.1681411360585; Thu, 13 Apr 2023 11:42:40 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:40 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 06/16] x86/run_in_user: Change type of code label Date: Thu, 13 Apr 2023 20:42:09 +0200 Message-Id: <20230413184219.36404-7-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use an array type to refer to the code label 'ret_to_kernel'. No functional change. Signed-off-by: Mathias Krause --- lib/x86/usermode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c index e22fb8f0132b..b976123ca753 100644 --- a/lib/x86/usermode.c +++ b/lib/x86/usermode.c @@ -35,12 +35,12 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, bool *raised_vector) { - extern char ret_to_kernel; + extern char ret_to_kernel[]; uint64_t rax = 0; static unsigned char user_stack[USERMODE_STACK_SIZE]; *raised_vector = 0; - set_idt_entry(RET_TO_KERNEL_IRQ, &ret_to_kernel, 3); + set_idt_entry(RET_TO_KERNEL_IRQ, ret_to_kernel, 3); handle_exception(fault_vector, restore_exec_to_jmpbuf_exception_handler); From patchwork Thu Apr 13 18:42:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210543 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 930B2C77B71 for ; Thu, 13 Apr 2023 18:43:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230115AbjDMSnQ (ORCPT ); Thu, 13 Apr 2023 14:43:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230017AbjDMSnG (ORCPT ); Thu, 13 Apr 2023 14:43:06 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BCE419029 for ; Thu, 13 Apr 2023 11:42:42 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id e7so5083644wrc.12 for ; Thu, 13 Apr 2023 11:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411361; x=1684003361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=WbrPT/N7Surh1jkNSimNnuJgTuWjitARPKRftYu1iuE=; b=VzaX3qjaz8tstpMvEBOWnMi9YMB8Ye413hyy1XgtsT/2md4d8Dlho4NnWjtJCdU+qa 1yLb2N5bxVqlE45dInyGkui9toH9XjhbR3L+dXeP9CtoddJXHz8IJUjtcr/PKLcIXd4/ YbamCWT9O3sbwzbjFPPEr9p0ZpupZbkslF069qek7pHuA2cmkkR5VcPoRiEZ7pvE3K1E T2Dc8jfe9UgOqm64H5wnzhTBijcSBfRetpzqzegoPB29YPy1pJtlQqCgCODQ3vTvYB5T x7NJTc4iINK1InhXbCPu8SPtO5JCOlcnOJCcKPglk1kant2ncs4V0VPSLg98i0YPJctx Ufcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411361; x=1684003361; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WbrPT/N7Surh1jkNSimNnuJgTuWjitARPKRftYu1iuE=; b=FHizQWaZJRLu5P2H77g+92gyiBfMAY8ArrMDZXjguLcyumr/9wxdYShBgpQt2gc8MR l/sg/XsbYHbanYK5pyU9G3nHnrStuBAG5xEhQ7spBsSlR0vbpINGym5LHSo+fZCPkjfM 1rs6KRmmz6rpeXFlaG697Pmp4dCp/OIvBF0sEhT7EJNiJT9lhwNbCYpLaOyyQ/DfeAIz +8zTjjoS2xF3ZwUQ0D1r1vNPexIkXx0NQmvErEGTAsGtP1XaoeVYEv9c8vhHKllEXCpf 0rZVYiCyYMKd7rKY1Xu4Cszkk+4ef65cz/6yMG56l/XEG95Ua21UtdYTxZbJHogXEiq2 vesA== X-Gm-Message-State: AAQBX9fyTiIfygdQOMlcPIimeo4nFKDntlAwXUR9xGK1+JlD5Wb6vNZF VBEDzK2Do6fxkOxpyFSWNmUvsA== X-Google-Smtp-Source: AKy350b8DGOwzexJ00EeAUX3M/0Yxv+Vz0gZth1tZmp7wUCvniQ/lLJRnxEEvIY1R+cqpw5d/NlMKg== X-Received: by 2002:adf:ef05:0:b0:2c3:e7d8:245c with SMTP id e5-20020adfef05000000b002c3e7d8245cmr2605773wro.13.1681411361334; Thu, 13 Apr 2023 11:42:41 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:41 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 07/16] x86/run_in_user: Preserve exception handler Date: Thu, 13 Apr 2023 20:42:10 +0200 Message-Id: <20230413184219.36404-8-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org run_in_user() replaces the exception handler for the expected fault vector to ensure the code can properly return back to kernel mode in case of such exceptions. However, it leaves the exception handler in place which may confuse later test code triggering the same exception without installing a handler first. Fix this be restoring the previous exception handler. Running the longjmp() handler out of context will lead to no good. We now also need to make 'rax' volatile to avoid a related compiler warning. Signed-off-by: Mathias Krause --- lib/x86/usermode.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c index b976123ca753..10fcea288a62 100644 --- a/lib/x86/usermode.c +++ b/lib/x86/usermode.c @@ -36,15 +36,17 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, uint64_t arg4, bool *raised_vector) { extern char ret_to_kernel[]; - uint64_t rax = 0; + volatile uint64_t rax = 0; static unsigned char user_stack[USERMODE_STACK_SIZE]; + handler old_ex; *raised_vector = 0; set_idt_entry(RET_TO_KERNEL_IRQ, ret_to_kernel, 3); - handle_exception(fault_vector, - restore_exec_to_jmpbuf_exception_handler); + old_ex = handle_exception(fault_vector, + restore_exec_to_jmpbuf_exception_handler); if (setjmp(jmpbuf) != 0) { + handle_exception(fault_vector, old_ex); *raised_vector = 1; return 0; } @@ -114,5 +116,7 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, : "rsi", "rdi", "rcx", "rdx"); + handle_exception(fault_vector, old_ex); + return rax; } From patchwork Thu Apr 13 18:42:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210544 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D8FB1C77B73 for ; Thu, 13 Apr 2023 18:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230172AbjDMSnT (ORCPT ); Thu, 13 Apr 2023 14:43:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230031AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C1CC83F5 for ; Thu, 13 Apr 2023 11:42:43 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id s12so6687800wrb.1 for ; Thu, 13 Apr 2023 11:42:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411362; x=1684003362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=a1ne7VVT4agLFjOnm1Owk3nY9/vLSYqIcSHVXPl3cSM=; b=d3A7u3S8OrvxRtioAoHkP9p9cXs/jojcn5m5j9ntlB9U4GN7RTuTjR6bvyXCDzRT1q YanXVnOo9+UQfV6+FtwB1MgPSuBB3Mo+wKeQkNgaNBWVm7G05FB4/T78vzsqBZ8QJFmC zGj+vl7l4bpxiMuOUt2QJ4S/KzjlJhZPlwXniGyAs1R4jQpBBAH1Hw4gPePYDGpG050p iPh75xGqA0X9X3MRsr9QTUHPf8sygN/JzUcotFxfvqi+heU2nM+LicRlTRUfT/xJvMKf fU+9aXMG1vlIlZjRt99O7fS5R4QoL40iRDJfwJuZuYZBEJbaOLWGGBaTttQPAcFj+F3j au2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411362; x=1684003362; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a1ne7VVT4agLFjOnm1Owk3nY9/vLSYqIcSHVXPl3cSM=; b=Tn7BPG7VWcEO2xU0OG4vWoW8ubLDyH+pjkhgrzE02qMqMYydWlYcZIzSb3zTfXhUvg cWPzXj0Jo+LWBU6UCwJhdl2pTbE68m1R5GCKBnCzZe6UwVyys2hpbP2gCLcWEN56UyCY Qm9rIH/QRprsP/kBOrB2McrdiMtb0xA5ktMPNjCg4meHPcbGMulRUDRWM4JaGo2F1lII pM4Rb+P0Xlq6bfUTYIFtNViVsY1VcrhuNjoB7ONpHlawVh5RIQ0z6UPnrhaZGgrPsXs+ mT2Ivv1gFn112OIGnxR8v9aNMZ7+ShhT6QCF4iktbjnOkHvZu1O/OYE2blTvhFAMvttj fcoQ== X-Gm-Message-State: AAQBX9cE/3Yj4SweRLv6WltL0U/LqUGZ+1xLrYj5BgyVYxSwy7BivdlD asor/lUDm0xzDT6NY5vhOCYtgA== X-Google-Smtp-Source: AKy350YGiq2e/11hdnVQ/NAURvYhzy/uQ31HZlUfoNCvse4DWwfAut9zaXr2t7+zSqRbCaTtb4XiSA== X-Received: by 2002:adf:f388:0:b0:2d6:d05a:1fe0 with SMTP id m8-20020adff388000000b002d6d05a1fe0mr2325978wro.64.1681411362056; Thu, 13 Apr 2023 11:42:42 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:41 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 08/16] x86/run_in_user: Relax register constraints of inline asm Date: Thu, 13 Apr 2023 20:42:11 +0200 Message-Id: <20230413184219.36404-9-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The code doesn't clobber all the registers it states it would. It explicitly preserves the values of rcx, rdi and rsi. With a minor code change rdx can be preserved as well. The code does, however, needlessly save and restore rbx around the function call. Change the code to not clobber rdx and drop all the register clobbers from the asm constraints, as these registers are, in fact, preserved. The function call either returns without throwing an exception (and restoring all call clobbered registers itself) or via longjmp() (doing the same, basically, but with special handling in the compiler as well). Signed-off-by: Mathias Krause --- lib/x86/usermode.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c index 10fcea288a62..fd19551a7a2d 100644 --- a/lib/x86/usermode.c +++ b/lib/x86/usermode.c @@ -63,21 +63,20 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, "pushq %[user_stack_top]\n\t" "pushfq\n\t" "pushq %[user_cs]\n\t" - "lea user_mode(%%rip), %%rdx\n\t" - "pushq %%rdx\n\t" + "lea user_mode(%%rip), %%rax\n\t" + "pushq %%rax\n\t" "iretq\n" "user_mode:\n\t" - /* Back up registers before invoking func */ - "push %%rbx\n\t" + /* Back up volatile registers before invoking func */ "push %%rcx\n\t" "push %%rdx\n\t" + "push %%rdi\n\t" + "push %%rsi\n\t" "push %%r8\n\t" "push %%r9\n\t" "push %%r10\n\t" "push %%r11\n\t" - "push %%rdi\n\t" - "push %%rsi\n\t" /* Call user mode function */ "mov %[arg1], %%rdi\n\t" "mov %[arg2], %%rsi\n\t" @@ -85,15 +84,14 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, "mov %[arg4], %%rcx\n\t" "call *%[func]\n\t" /* Restore registers */ - "pop %%rsi\n\t" - "pop %%rdi\n\t" "pop %%r11\n\t" "pop %%r10\n\t" "pop %%r9\n\t" "pop %%r8\n\t" + "pop %%rsi\n\t" + "pop %%rdi\n\t" "pop %%rdx\n\t" "pop %%rcx\n\t" - "pop %%rbx\n\t" /* Return to kernel via system call */ "int %[kernel_entry_vector]\n\t" /* Kernel Mode */ @@ -112,9 +110,7 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, [user_cs]"i"(USER_CS), [user_stack_top]"r"(user_stack + sizeof(user_stack)), - [kernel_entry_vector]"i"(RET_TO_KERNEL_IRQ) - : - "rsi", "rdi", "rcx", "rdx"); + [kernel_entry_vector]"i"(RET_TO_KERNEL_IRQ)); handle_exception(fault_vector, old_ex); From patchwork Thu Apr 13 18:42:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210546 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13526C77B6E for ; Thu, 13 Apr 2023 18:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbjDMSnR (ORCPT ); Thu, 13 Apr 2023 14:43:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229492AbjDMSnI (ORCPT ); Thu, 13 Apr 2023 14:43:08 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8619D6A42 for ; Thu, 13 Apr 2023 11:42:44 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id j15so1423606wrb.11 for ; Thu, 13 Apr 2023 11:42:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411363; x=1684003363; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=UPrhWpKAB9HV29BJuUCmLvNKDCRzAddjdDbvTlL8W/w=; b=AwHkue3ft9b/chF3ZaSXmcU+Xeak+GQiOpeZbDOx8Vn9N/DEPP0WkLgSNkUtkGStvQ VwI0iF76jrHNxqr3xycTFXHvfiPEdSPpTcPxEffGQga95EmYoyeoJOhninXjziSqphIR eZG4+etGwP3P17hdXFTJKXL05e04G2qoc9qewqmU4rAC6REJMbJfDWZfb3Mb825gAM4M XW0L5Ew73J5OqxXR1ezrn5e6nOgtJ52pKCFLREHrg0IsVb2R+F1LNPR7WTers7KRUu59 UUYfZJfVZKqQJGyqf7ZBeLKMYKJFjC4fScs0X/Eq6gCWTH0DEzIkAY8aa5orSoi7F4zZ B6MA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411363; x=1684003363; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UPrhWpKAB9HV29BJuUCmLvNKDCRzAddjdDbvTlL8W/w=; b=EoVxajPefs7dUzUDNwrn37tWvvdi6JWd9BvT2nNkVy1ZrlVmFovAye0GUf5/2CIIDA jbYk+04AlrDV085RdITu981P8bj5ZtX4t8N478n9foubjMGIBioXdGViP7nvCxcOjLR1 3xxZ18rgvqghmqw5c3mEg17CWNCOpoZzJA+WSB96DR2ehYH/NEY1XdXhx5p/PFDHswaC dzOO8IowR7mgyeThGyAsSH4EffVNQkk4+uZmndobaumVHa2z1Wm0CI/q63So1bD8+BqW A48L3TEKxYicIGapX7YEfcKXJTiZcc3l1HGs43Cr0al0xPy8lsBYfjgVYNH/t/W1NKlM ZELA== X-Gm-Message-State: AAQBX9daV8/JXKSKJMxHJXs0TE0GbjTgOurLNBv7wGam8LOAbHG0kE5j Yt3D+JgBPYvXIBIryld1Dy+npw== X-Google-Smtp-Source: AKy350arK2lqIg8I1KREMe15AdttWzD1if8zeVvJlCwPtFdORiYypSKHHhOWT9lSw5hO0M/nYxSNbg== X-Received: by 2002:a5d:40c7:0:b0:2ef:a7d:54fd with SMTP id b7-20020a5d40c7000000b002ef0a7d54fdmr5472052wrq.32.1681411363003; Thu, 13 Apr 2023 11:42:43 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:42 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 09/16] x86/run_in_user: Reload SS after successful return Date: Thu, 13 Apr 2023 20:42:12 +0200 Message-Id: <20230413184219.36404-10-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Complement commit 663f9e447b98 ("x86: Fix a #GP from occurring in usermode library's exception handlers") and restore SS on a regular return as well. The INT-based "syscall" will make it get loaded with the NULL selector (see SDM Vol. 1, Interrupt and Exception Behavior in 64-Bit Mode: "The new SS is set to NULL if there is a change in CPL.") which makes the "mov null, %%ss" test of emulator64.c dubious, as SS is already loaded with the NULL selector. Fix this by loading SS with KERNEL_DS after a successful userland function call as well, as we already do in case of exceptions. Signed-off-by: Mathias Krause --- lib/x86/usermode.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/x86/usermode.c b/lib/x86/usermode.c index fd19551a7a2d..9ae4cb17fd63 100644 --- a/lib/x86/usermode.c +++ b/lib/x86/usermode.c @@ -97,6 +97,13 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, /* Kernel Mode */ "ret_to_kernel:\n\t" "mov %[rsp0], %%rsp\n\t" +#ifdef __x86_64__ + /* Restore SS, as it forcibly gets loaded with NULL */ + "push %%rax\n\t" + "mov %[kernel_ds], %%ax\n\t" + "mov %%ax, %%ss\n\t" + "pop %%rax\n\t" +#endif : "+a"(rax), [rsp0]"=m"(tss[0].rsp0) @@ -108,6 +115,7 @@ uint64_t run_in_user(usermode_func func, unsigned int fault_vector, [func]"m"(func), [user_ds]"i"(USER_DS), [user_cs]"i"(USER_CS), + [kernel_ds]"i"(KERNEL_DS), [user_stack_top]"r"(user_stack + sizeof(user_stack)), [kernel_entry_vector]"i"(RET_TO_KERNEL_IRQ)); From patchwork Thu Apr 13 18:42:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210547 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 288B8C77B73 for ; Thu, 13 Apr 2023 18:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230206AbjDMSnX (ORCPT ); Thu, 13 Apr 2023 14:43:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230046AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 445BD6E86 for ; Thu, 13 Apr 2023 11:42:45 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id v27so5949348wra.13 for ; Thu, 13 Apr 2023 11:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411364; x=1684003364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=CqfqWd6G1AH8YUNbkpR+KkIq4eBkb+8HCcDjE871iFM=; b=HJOatyWJ7QKwqsXWe0WpNl/vKg3NtVbEKXy5yfbzjgTg1sz5ly+uivqQexNLzoQmBa McHEyxeXx0iPQ0RzPcaGRl+sWlKs7fXw/yCiQHs/Fd9aYpF8l3vC5fBhnxyvqtPC9T8S qDkCkqNu18525qzP9URa+pAWK1JFoJoDbAO7SJp44BL2MZRQAyfd4kARtuk6J8/+3PGK RyEmmBSO3vVK5Tf600npFpgQ44i0RsaBS8zEK1939zJBQgZJ2c7GDI0oMcxNFvbKnYm3 q6REAR+/pdeW5FF6u7Jb1g5ImUe8ats+qVCgLKJGKmMPidlKlEem4miEk80yDVzVdhAG jCyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411364; x=1684003364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CqfqWd6G1AH8YUNbkpR+KkIq4eBkb+8HCcDjE871iFM=; b=VxGkK+PQ19icl4MTAi8e6p4Jnc7EhWVbghkyGAulBy5dP2fhqfnNDBCyhzy28gHaph UA1Qjsb85X6vZLPR8E7H3BPY+Q0Ma25h4vEouJFCUu1zMaxC5qCE7I4EKJ44j8pzNBoD WzqsAdJwIpjOMCm1VB8aZ7Z3XsW2qtZocl6HsFRicY8P+O8LfPe4FDgrxdbXiJYNKyv/ owEJkqbAZ9G+4lR5wpROGpqs5EuropQEmFnApj0gBYfCEazjiDfkTLAyZMi/adifRCfB 0N65R1/9VAv4RQVgxtL3wUnzKAL5iQnv7J6gtSaaxMHb5Z6MzRl1tcm0FAF5sAi8i5nO rbBw== X-Gm-Message-State: AAQBX9eZ3chr3taNmaBe7wLbfC054CGUmokqPjMGxTgiLWmh8CoTOR4W K0P3wAGjMX4uLPDIR73mJxk7XA== X-Google-Smtp-Source: AKy350YNl/iuOqIgTG81r5IinDQI119x9whoEo8B7Q9rKrYwrsU0pdg6QtRBbkoNkwajLs//ofkgGA== X-Received: by 2002:a5d:6a4a:0:b0:2d7:998c:5ad9 with SMTP id t10-20020a5d6a4a000000b002d7998c5ad9mr2332358wrw.8.1681411363908; Thu, 13 Apr 2023 11:42:43 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:43 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 10/16] x86/fault_test: Preserve exception handler Date: Thu, 13 Apr 2023 20:42:13 +0200 Message-Id: <20230413184219.36404-11-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org fault_test() replaces the exception handler for in-kernel tests with a longjmp() based exception handling. However, it leaves the exception handler in place which may confuse later test code triggering the same exception without installing a handler first. Fix this be restoring the previous exception handler, as running the longjmp() handler out of context will lead to no good. Signed-off-by: Mathias Krause --- lib/x86/fault_test.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/x86/fault_test.c b/lib/x86/fault_test.c index e15a21864562..614bdcb42535 100644 --- a/lib/x86/fault_test.c +++ b/lib/x86/fault_test.c @@ -19,18 +19,20 @@ static bool fault_test(struct fault_test_arg *arg) test_fault_func func = (test_fault_func) arg->func; /* Init as success in case there isn't callback */ bool callback_success = true; + handler old; if (arg->usermode) { val = run_in_user((usermode_func) func, arg->fault_vector, arg->arg[0], arg->arg[1], arg->arg[2], arg->arg[3], &raised_vector); } else { - handle_exception(arg->fault_vector, fault_test_fault); + old = handle_exception(arg->fault_vector, fault_test_fault); if (setjmp(jmpbuf) == 0) val = func(arg->arg[0], arg->arg[1], arg->arg[2], arg->arg[3]); else raised_vector = true; + handle_exception(arg->fault_vector, old); } if (!raised_vector) { From patchwork Thu Apr 13 18:42:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210545 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1084C77B78 for ; Thu, 13 Apr 2023 18:43:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbjDMSnU (ORCPT ); Thu, 13 Apr 2023 14:43:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230032AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB5583FA for ; Thu, 13 Apr 2023 11:42:45 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id g5so18542078wrb.5 for ; Thu, 13 Apr 2023 11:42:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411364; x=1684003364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wviqyZ85KGfFUzxOBpv3myd0D/M0XiS1I9CvoQwMgnY=; b=f5kq15Nrt9zSQ+lV03e5MG+DAm1TrRRdVx03AbbuvcEfN4nEYpU2yoL4rzYNU2TITJ Hsw3c8Cr3JW+grExeVccD/S3I84Oq+X8sA1zATGZNRDn8PpB6NvDNuEcOW2tF71Nu7IM uYeqgEpOrCf79aXCxZFpIoiD/HAWywkg6GTspXKrotuxg1dwBuZQix0DY3IgA/Ljq+/W 1GrxriLpxbCykH4nXZycFMS5h3exbtHx+MBj16E7stqeNw6aAIsec0f9JXaFlXlxPH2l 4ObmijpOlkRPrZR5TE5cRttgot6p22mKyekzbwElujvVTdOL8Zm+nBXUTJ2wORvaAQqL twDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411364; x=1684003364; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wviqyZ85KGfFUzxOBpv3myd0D/M0XiS1I9CvoQwMgnY=; b=R4LBsHlqSb1rCLqoVMDp5c+QMibb7O1Mp5UvCB6Ci/y8xGQrbG1E8PGsm5xTV74MI8 YD/ULAHYz5vAnLKcbAM6RSQrWD0kcenFZzl+Soh09CN6D+dRYR0d0NJ1hXy92egn4vqF bsDVH+zNYtya+pA+m8K98v+rW3WZeME3cHD1I0dtm6KP+DrMiZZtgDphLmZeOPpUjfZ8 lZSVZoqSH3iECzgKqpgshdmLAsov8b8YmRYTbvfiYWoynUb0T53kMnG8eqpaKMYzjhmI 9ZVImqOpsDhhqstQTYcb5FKhjWvTCMnEIZYfZNoibXMAuCriAbnyUl9btlqORvu2j+8C WVXw== X-Gm-Message-State: AAQBX9fj60gWKpXqEJFkpKgxaYiwJebPg8bGGTM3wLHbHuLuJ9+YfqrW DSQhPp3cAvmr7FTFJ8DWcgHR5xNX3hy/wFEXkgw= X-Google-Smtp-Source: AKy350YfgrH8WBJgrERCwwfu4RcquC5uYCsGZIJ6i8Kaaa03zpX4/v18xqtV8hjnfKI9uT4Q4ec1+Q== X-Received: by 2002:a5d:6a82:0:b0:2d3:33d4:1cfb with SMTP id s2-20020a5d6a82000000b002d333d41cfbmr2172302wru.36.1681411364609; Thu, 13 Apr 2023 11:42:44 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:44 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 11/16] x86/emulator64: Relax register constraints for usr_gs_mov() Date: Thu, 13 Apr 2023 20:42:14 +0200 Message-Id: <20230413184219.36404-12-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org There's no need to hard-code the registers, allow the compiler to choose ones that fit. Signed-off-by: Mathias Krause --- x86/emulator64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/emulator64.c b/x86/emulator64.c index c58441ca798c..4138eaae00c9 100644 --- a/x86/emulator64.c +++ b/x86/emulator64.c @@ -421,7 +421,7 @@ static uint64_t usr_gs_mov(void) uint64_t ret; dummy_ptr -= GS_BASE; - asm volatile("mov %%gs:(%%rcx), %%rax" : "=a"(ret): "c"(dummy_ptr) :); + asm volatile("mov %%gs:(%1), %0" : "=r"(ret) : "r"(dummy_ptr)); return ret; } From patchwork Thu Apr 13 18:42:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210548 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 696B6C77B6E for ; Thu, 13 Apr 2023 18:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230170AbjDMSnY (ORCPT ); Thu, 13 Apr 2023 14:43:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B19E793F6 for ; Thu, 13 Apr 2023 11:42:46 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id n19-20020a05600c501300b003f064936c3eso13713643wmr.0 for ; Thu, 13 Apr 2023 11:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411365; x=1684003365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ESQ+BfeZUo7v07/2Wqyt37Bb9GRSnMpcy+kHTBycy9Y=; b=uK5+hAMaF8H4NLLmqjUFeYI51VTtAb60r5CSkUPRv+Abj7OuN27oAupo95iWpiLNgp pmbQgF/CP9UjxGtXDA3/yCxyUqQ6iGkz7Uci9KuMpagrTlJtD0Foyo8vAuhdKxVsurqz 9Flj8LlqIc9BbWyAEZwQ/bpOA2+sod63ljSO3kRDWzUk/rsxkFZ+7uwezttQPRoaPRVS jvktwyU/Apm3BLZI7nDvakFx7XJMFIBlhJQ4RFlYgFyaT4RwFonwhrJ5DNfzzyhweRT/ CvxPxfNhbiXXWqCwv4Z69UOxthOU9o0rro1RDe9Zh9Xj8r/4c8AruoQWNUh6zhuXKsBw 0QLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411365; x=1684003365; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ESQ+BfeZUo7v07/2Wqyt37Bb9GRSnMpcy+kHTBycy9Y=; b=Azb2Z8Wbk5x8+zTsFpEqEbapTaspR4MdObJHfewuJXXC54AQv2CIMyLIzueRjMkQTl 6oArJ80FGV02BtVPYK5FUq3y3vipoVYzRUmhbklbmy137+buPpmCa11ZsmNESX9vDlbX NyCbbVjeIRqEUJJYkgc/QaqM54YQuo9cAQ8nk6vWHrVMIhxuetldtrZ4OOaox4qeykRi aVC3o3lYE0FS0yGUNNlKzK28uNsXubDDVQ/n3l4mBO6D3d2CF0qnFbTFgj6h3MamC+4F E4fboadMqViwM79lsWfW6Gs2prFd3vv6gOrVZiC72dJZ9oXXnFn/wv1mlNhHm3lu7YpJ qcVA== X-Gm-Message-State: AAQBX9fa9ufmY03S5r8dVHlzhTdVlOirpuWq+Yqf65bFQDokQVwTTQq3 yJtt7ZnMVTyGFrfDerxP2xmp1APlfczEXXpfhng= X-Google-Smtp-Source: AKy350Z8vmxwbQY0yue92CnvUxb+wDcBy6J/DqJzY3VUhgPTSJEttcckhnk1+DH747Yc6dhYb7R0/w== X-Received: by 2002:a05:600c:1e11:b0:3f0:4275:395f with SMTP id ay17-20020a05600c1e1100b003f04275395fmr2110437wmb.13.1681411365358; Thu, 13 Apr 2023 11:42:45 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:45 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 12/16] x86/emulator64: Switch test_sreg() to ASM_TRY() Date: Thu, 13 Apr 2023 20:42:15 +0200 Message-Id: <20230413184219.36404-13-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of registering a one-off exception handler, make use of ASM_TRY() to catch the exception. Also test the error code to match the failing segment selector (NULL) as the code now easily can access it. Signed-off-by: Mathias Krause --- x86/emulator64.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/x86/emulator64.c b/x86/emulator64.c index 4138eaae00c9..a98c66c2b44f 100644 --- a/x86/emulator64.c +++ b/x86/emulator64.c @@ -385,18 +385,9 @@ static void test_push16(uint64_t *mem) report(rsp1 == rsp2, "push16"); } -static void ss_bad_rpl(struct ex_regs *regs) -{ - extern char ss_bad_rpl_cont; - - ++exceptions; - regs->rip = (ulong)&ss_bad_rpl_cont; -} - static void test_sreg(volatile uint16_t *mem) { u16 ss = read_ss(); - handler old; // check for null segment load *mem = 0; @@ -404,13 +395,12 @@ static void test_sreg(volatile uint16_t *mem) report(read_ss() == 0, "mov null, %%ss"); // check for exception when ss.rpl != cpl on null segment load - exceptions = 0; - old = handle_exception(GP_VECTOR, ss_bad_rpl); *mem = 3; - asm volatile("mov %0, %%ss; ss_bad_rpl_cont:" : : "m"(*mem)); - report(exceptions == 1 && read_ss() == 0, + asm volatile(ASM_TRY("1f") "mov %0, %%ss; 1:" : : "m"(*mem)); + report(exception_vector() == GP_VECTOR && + exception_error_code() == 0 && read_ss() == 0, "mov null, %%ss (with ss.rpl != cpl)"); - handle_exception(GP_VECTOR, old); + write_ss(ss); } From patchwork Thu Apr 13 18:42:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210549 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E64E0C77B61 for ; Thu, 13 Apr 2023 18:43:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230242AbjDMSn2 (ORCPT ); Thu, 13 Apr 2023 14:43:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86A2286A8 for ; Thu, 13 Apr 2023 11:42:47 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id q6so3696822wrc.3 for ; Thu, 13 Apr 2023 11:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411366; x=1684003366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VEzPnT9BJgEXvliDbDR1VhVozm5deAohFLLUYFFrBSc=; b=H7aOLZRY/iUS6b27nuIM1MoBSXZt+ExRPdjmx7NTJX+eCcH2iDa1IFEWbjYKbi52eD Ok92+TL0FyyulJZNvnLMrwF/dq+qr1tT5ms5oCTKNsRiHK7BEPRzSApXqovau8owHlg4 wEoAG6FhX1/AOt5hUcoeLxkgJX3npaMbzSh3H+5Ay7vYDfXr3CWd4FMScuv9tniYkaju pCcVhNkpXEiruVJt0BfseZG445yN6dmHLdLabK8WgMm20mUzEOIHrQPb6HqHmaJF89ju k4XB+XcmH3cu7LcpmoZcyeR4wj3ceBFgM6C8GocKK2mcV8Y64y/Jm8IRAJs5m3Qvndup d+xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411366; x=1684003366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VEzPnT9BJgEXvliDbDR1VhVozm5deAohFLLUYFFrBSc=; b=VwcNWsq7zkQDeREnzB9CExMl8GCUFdJuXk1Rp9UXxk/gLofzQId0G7/rg/aBNCM95r sqnmaiKKrr/TOqSg5Gj3xjLZ4I03CFP6lt642WE8zW6LQdK82e5TTI4SDk7poPCljCfd NOXQZnPROn4BV6oxphhp1CE+auJOG40MkC2217y+LZx9+8f+Z3QQOmeT6/CRujzooHRo MdCvaCBacNufToFOpo0fGahi5MvphrfteTDxE6gJ8iTsb0KudngPZZlTZzKxBaHBhc6l kFDV4EUwSuBh6VihAA8QWyz40a/gzbrPXj9lVtwhOIfskuiojUK7Ffax4e3ObrjzVQiP GG7w== X-Gm-Message-State: AAQBX9dDJAHs2oyJNGRpxCQFwlCSTyBQZ5MM1VTrqUyrB/EgBuT7ZVgX S08QvJHJaQStfVqGIWfpoyJxzw== X-Google-Smtp-Source: AKy350Yk/Ft352jB0vtFJBgpo6mtO9m87CiPbw01r2kQx4ISkjhrBDTwRJ1Na1u6Ip5Kg4RHbBZJqg== X-Received: by 2002:a5d:4141:0:b0:2f0:2e3a:cbfa with SMTP id c1-20020a5d4141000000b002f02e3acbfamr2139364wrq.57.1681411366044; Thu, 13 Apr 2023 11:42:46 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:45 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 13/16] x86/emulator64: Add non-null selector test Date: Thu, 13 Apr 2023 20:42:16 +0200 Message-Id: <20230413184219.36404-14-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Complement the NULL selector based RPL!=CPL test with a non-NULL one to ensure the failing segment selector is correctly reported through the exception error code. Signed-off-by: Mathias Krause --- x86/emulator64.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x86/emulator64.c b/x86/emulator64.c index a98c66c2b44f..492e8a292839 100644 --- a/x86/emulator64.c +++ b/x86/emulator64.c @@ -401,6 +401,13 @@ static void test_sreg(volatile uint16_t *mem) exception_error_code() == 0 && read_ss() == 0, "mov null, %%ss (with ss.rpl != cpl)"); + // check for exception when ss.rpl != cpl on non-null segment load + *mem = KERNEL_DS | 3; + asm volatile(ASM_TRY("1f") "mov %0, %%ss; 1:" : : "m"(*mem)); + report(exception_vector() == GP_VECTOR && + exception_error_code() == KERNEL_DS && read_ss() == 0, + "mov non-null, %%ss (with ss.rpl != cpl)"); + write_ss(ss); } From patchwork Thu Apr 13 18:42:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210550 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A601C77B71 for ; Thu, 13 Apr 2023 18:43:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230259AbjDMSn3 (ORCPT ); Thu, 13 Apr 2023 14:43:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbjDMSnJ (ORCPT ); Thu, 13 Apr 2023 14:43:09 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A5F08A4F for ; Thu, 13 Apr 2023 11:42:48 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id s2so11890329wra.7 for ; Thu, 13 Apr 2023 11:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411366; x=1684003366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fbNSmdopHWdD2/8eXrDn8O1lhc85x+0fvqbJjVSSLV0=; b=ns64lkz7Ny1HglhPxc3dH14AI5Aam0j7OYOcbfzAu2TA0lkaupMWeIzw0Ypz7ftSsk w5BUPEG/WU73TLVPc6JK1F062VWqg6j+x1q3fUKoL/psQPRIgsfWpfHqdaQLMuET3YoK w64nSat0SVT5kufRgxtUO5dtTPbKKbg2JDx9DoOB5EYWK73uD1DxSy22dnv7PqFOvRUv lrxLCpNYrdxzSAxa1vpRDmHJp+PdYIZe0y+ZDs7E99IOdObMFJjaAXIb9nXt8Dp5mLQO Gkqit3pdBeWNbATqiWP30LQssppNEbvAedmRJUnxaQXpAOPuB3vKTr1WW8wrc0HW843A JHTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411366; x=1684003366; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fbNSmdopHWdD2/8eXrDn8O1lhc85x+0fvqbJjVSSLV0=; b=ATwV6KznP6zXGFXsqClHgfEBfI83MTKiMXHdnU+1FiV/YHCiP1aG4KCSCYYLwBEVb1 aE2XC6jbTQ0YkZbwW2bljG3AXtZsGY8veuEe9puAzGZnkRxFNa90l3Fm/l+/+NtfEhUS izMxKlfb16Lcud+Rr3QiIdH7iBYBpcWmGL/NJ2uqdPJaE2WwlN0EOkTkrS2Cea/qBY8P YuUmI1k9aBWdX+usB2yJF8r08imsaDsgZDN/GZTxgbpeGFaepar/K+6OAXUFero42OJu TxaP1K1auCVG5YKvtQnc8780p58jPv8wxMA8QAKQq0NZzc7wGGBB55ARO5Y0eRdOTEUZ 1dKw== X-Gm-Message-State: AAQBX9ckR0MAz3BY9JKX7Lh+jg7om+fPek/aAeKhA3JK0JmjqkZ6+dwc 4ZKkVTAv1vxxUtypcogy56VqIQ== X-Google-Smtp-Source: AKy350bmLTfWaYtUsqiZEdIAj4IrVQm2K11sMKwsFwOyYYSMDyRJXdUyZ0dWbjYBiz5qAmCAYWuljA== X-Received: by 2002:adf:edce:0:b0:2ee:e456:5347 with SMTP id v14-20020adfedce000000b002eee4565347mr2313939wro.13.1681411366762; Thu, 13 Apr 2023 11:42:46 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:46 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 14/16] x86/emulator64: Switch test_jmp_noncanonical() to ASM_TRY() Date: Thu, 13 Apr 2023 20:42:17 +0200 Message-Id: <20230413184219.36404-15-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Instead of registering a one-off exception handler, make use of ASM_TRY() to catch the exception. Also make use of the 'NONCANONICAL' define to refer to a non-canonical address. Signed-off-by: Mathias Krause --- x86/emulator64.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/x86/emulator64.c b/x86/emulator64.c index 492e8a292839..50a02bca6ac8 100644 --- a/x86/emulator64.c +++ b/x86/emulator64.c @@ -334,17 +334,10 @@ static void test_mmx_movq_mf(uint64_t *mem) static void test_jmp_noncanonical(uint64_t *mem) { - extern char nc_jmp_start, nc_jmp_end; - handler old; - - *mem = 0x1111111111111111ul; - - exceptions = 0; - rip_advance = &nc_jmp_end - &nc_jmp_start; - old = handle_exception(GP_VECTOR, advance_rip_and_note_exception); - asm volatile ("nc_jmp_start: jmp *%0; nc_jmp_end:" : : "m"(*mem)); - report(exceptions == 1, "jump to non-canonical address"); - handle_exception(GP_VECTOR, old); + *mem = NONCANONICAL; + asm volatile (ASM_TRY("1f") "jmp *%0; 1:" : : "m"(*mem)); + report(exception_vector() == GP_VECTOR, + "jump to non-canonical address"); } static void test_movabs(uint64_t *mem) From patchwork Thu Apr 13 18:42:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210552 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 94B9EC77B61 for ; Thu, 13 Apr 2023 18:43:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230200AbjDMSnc (ORCPT ); Thu, 13 Apr 2023 14:43:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230122AbjDMSnK (ORCPT ); Thu, 13 Apr 2023 14:43:10 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A57A6599 for ; Thu, 13 Apr 2023 11:42:48 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id s2so11890370wra.7 for ; Thu, 13 Apr 2023 11:42:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411367; x=1684003367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8q4B7NHV5vUbSHi1BOdJtLcPDnE9hcKZRDS4ZiVIfns=; b=SyCk5+Wsdsot2eGeT4bto9YyaUneNTOHgIBhVphr/M2SCZpZUY0i3P5g23XLHATCjX yQCwuxCjwpexBDy5kOPui2aK1aXk6+SlyMxco5vGiTpglgEhocp3rrlhEtoHOPGbES1N yTm9Ia3z0YpEmyQxg0dLtI7RQMxEnCqaorY6zxx7j6Kf4lMJkQYSCoo2GEHADBuXAhnH eYgl0W7nHZwsKbsHM+Cd27oSwmJZMr7vBq//kes9INsks8RmfG7/6fuG14xKraAd9jM1 ZWHSvRTGnEZ8vhz53Lhjgo++4rKDAltzhI8y58GQrnVEEO6Kobe29cc8IdYV7jkXS7/U z9Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411367; x=1684003367; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8q4B7NHV5vUbSHi1BOdJtLcPDnE9hcKZRDS4ZiVIfns=; b=PVm+p4/YnlgptiiupCi/hbnf4hV6V/xf2198yzhA/td8LPGEFAdHBGQwnVkqRLLaa8 Rm8wmdlWG+DNsF/8QU/zvvujzhHVkIcEajKRGm+ZTdoETLGDEHT9cfxcrlUKK5Z89eXO eN96Pi3kyT9WPaY97mYOCpxIujzIUQryMzSTVyWJ1KfaCvbSYS3xNDEf6u4xcgfAndxc U88rdgtmBfvb2WJinHPdBfcpjc7bo7XaS9EVaEjFtp0b5CXyXQsLvpLUtd1OWSKOh+6K e63GswV9yJ5JPz/6K9gQzKQAZk2UiB0w+Rw9OVLzUpuBk4diftRBVYIUozMLJHdKiZDz yCoQ== X-Gm-Message-State: AAQBX9d1RYBCHyfIGMT1vE7S6/o1UIZXblOIXJ89QJKAL4CGSvyvSZ0l kjoCk4bOI3jg+eNh7j7goYQwcw== X-Google-Smtp-Source: AKy350YEsATKQdlYb17FtW+4wsyCMUW4im6xGKm/z4+cXeZG7uhtSv/rLiaXdTHb/j+kyuwOBeUhfA== X-Received: by 2002:a5d:44c7:0:b0:2f5:fb37:c54b with SMTP id z7-20020a5d44c7000000b002f5fb37c54bmr2278843wrr.60.1681411367490; Thu, 13 Apr 2023 11:42:47 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:47 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 15/16] x86/emulator64: Switch test_mmx_movq_mf() to ASM_TRY() Date: Thu, 13 Apr 2023 20:42:18 +0200 Message-Id: <20230413184219.36404-16-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Drop the last user of the one-off exception handler by making use of ASM_TRY() for the #MF test. Also streamline the multiple scattered asm() statements into a single one making use of a real output value instead of hard-coding rax and relying on the instruction to generate an exception (instead of clobbering rax and not making gcc aware of it). As this removes the last user of advance_rip_and_note_exception() we can remove it for good! Signed-off-by: Mathias Krause --- x86/emulator64.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/x86/emulator64.c b/x86/emulator64.c index 50a02bca6ac8..f8ff99fc39cc 100644 --- a/x86/emulator64.c +++ b/x86/emulator64.c @@ -1,14 +1,6 @@ #define MAGIC_NUM 0xdeadbeefdeadbeefUL #define GS_BASE 0x400000 -static unsigned long rip_advance; - -static void advance_rip_and_note_exception(struct ex_regs *regs) -{ - ++exceptions; - regs->rip += rip_advance; -} - static void test_cr8(void) { unsigned long src, dst; @@ -313,23 +305,24 @@ static void test_cmov(u32 *mem) static void test_mmx_movq_mf(uint64_t *mem) { - /* movq %mm0, (%rax) */ - extern char movq_start, movq_end; - handler old; - uint16_t fcw = 0; /* all exceptions unmasked */ - write_cr0(read_cr0() & ~6); /* TS, EM */ - exceptions = 0; - old = handle_exception(MF_VECTOR, advance_rip_and_note_exception); - asm volatile("fninit; fldcw %0" : : "m"(fcw)); - asm volatile("fldz; fldz; fdivp"); /* generate exception */ + uint64_t val; - rip_advance = &movq_end - &movq_start; - asm(KVM_FEP "movq_start: movq %mm0, (%rax); movq_end:"); - /* exit MMX mode */ - asm volatile("fnclex; emms"); - report(exceptions == 1, "movq mmx generates #MF"); - handle_exception(MF_VECTOR, old); + write_cr0(read_cr0() & ~(X86_CR0_TS | X86_CR0_EM)); + asm volatile("fninit\n\t" + "fldcw %[fcw]\n\t" + "fldz\n\t" + "fldz\n\t" + /* generate exception (0.0 / 0.0) */ + "fdivp\n\t" + /* trigger #MF */ + ASM_TRY_FEP("1f") "movq %%mm0, %[val]\n\t" + /* exit MMX mode */ + "1: fnclex\n\t" + "emms\n\t" + : [val]"=m"(val) + : [fcw]"m"(fcw)); + report(exception_vector() == MF_VECTOR, "movq mmx generates #MF"); } static void test_jmp_noncanonical(uint64_t *mem) From patchwork Thu Apr 13 18:42:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Krause X-Patchwork-Id: 13210551 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 60286C77B6E for ; Thu, 13 Apr 2023 18:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbjDMSnb (ORCPT ); Thu, 13 Apr 2023 14:43:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbjDMSnK (ORCPT ); Thu, 13 Apr 2023 14:43:10 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F8C61A9 for ; Thu, 13 Apr 2023 11:42:49 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id v6so15149312wrv.8 for ; Thu, 13 Apr 2023 11:42:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=grsecurity.net; s=grsec; t=1681411368; x=1684003368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4R4jaYe2ibW2haL/9vyM0m/t0V1yg/Lyd4jH33J0aRM=; b=XdixZa9ZhVXD5PDTwOvteFmmV7AIiww6tiS6EjHJcicaDHlrNx2UqZsQ7Hdh1S5FHi d5dVNJa4uxMSxFMOcFEm75/DkCEgQRbu6OpWTk/XA3TCmAJYuSOoBc57FLradFnezKV9 3LHMKI8eFvLuIQGJG6PyvH1Gk03jZF723Q5f8xdtaTsTrEaWx4UDmNyYnMZK0A9k9UjL 9DANy1ZIPXaJYSaanp82/3ojxaznroZTNv3LbzHJZAoeex6dROteItwnRH+V63UZooH4 wp+Nxpxg0Y/fVmYmXjmM5IvjDfjFPM1hkfWEzVmZH4zJeYmVRk0aTRlJHuOR4TBy5QRO Zo3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681411368; x=1684003368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4R4jaYe2ibW2haL/9vyM0m/t0V1yg/Lyd4jH33J0aRM=; b=Aygy8xQ1QIxLgra38ePW4wkoH6QSrA0vBc1OWvkCg3NUIdss1k53Kwgau6ZCsMQ/kn vRZkZ7vBcSNrx+xxVJgLvTYg03PlkUUKi0ZBkjMZPUpMNgg0kiiTkUa57KezYOKGhCp4 hMACRZOwi8eSWTqaoZocYabtBLbt/jgUCxAUmUD9ICsfMgOEzfVkVFd9GCGKpN1JYrR3 qxp40QBbs2Z1v6yd6zEYeN/3DjmutfcFnMbuI6B++6nEfOIiDnujq2Itcb4HuL6FuLgQ 2zjJv9JWQP0RDcrcyf4lnSkyPynL/xhh7N6MNYPJmT0JeuFDbVkjo3Fmh3OaxnGTzNPT eOng== X-Gm-Message-State: AAQBX9eE5DeNoOfwfywZ8kBu7SFjgcddP2Ny4N9Js+p2GAkdvb0U/t+O OdkiHR/AhtVohSNKYC6z8qDfVw== X-Google-Smtp-Source: AKy350aWjT02JBCmjIpEh+gJaFp0RTV5RYknYa4bx71zNFTkn770OSv+kmI7ksZhp5vjsb8hE/BVWg== X-Received: by 2002:adf:ef52:0:b0:2cf:3a99:9c1e with SMTP id c18-20020adfef52000000b002cf3a999c1emr2242247wrp.49.1681411368201; Thu, 13 Apr 2023 11:42:48 -0700 (PDT) Received: from nuc.fritz.box (p200300f6af154800ce0bb7f104d5fcf7.dip0.t-ipconnect.de. [2003:f6:af15:4800:ce0b:b7f1:4d5:fcf7]) by smtp.gmail.com with ESMTPSA id x15-20020a5d6b4f000000b002c8476dde7asm1812652wrw.114.2023.04.13.11.42.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 11:42:47 -0700 (PDT) From: Mathias Krause To: Paolo Bonzini , Sean Christopherson , kvm@vger.kernel.org Cc: Mathias Krause Subject: [kvm-unit-tests PATCH v2 16/16] x86/emulator64: Test non-canonical memory access exceptions Date: Thu, 13 Apr 2023 20:42:19 +0200 Message-Id: <20230413184219.36404-17-minipli@grsecurity.net> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230413184219.36404-1-minipli@grsecurity.net> References: <20230413184219.36404-1-minipli@grsecurity.net> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org A stack based memory access should generate a #SS(0) exception but QEMU/TCG as of now (7.2) makes all exceptions based on a non-canonical address generate a #GP(0) instead (issue linked below). Add a test that will succeed when run under KVM but fail when using TCG. Link: https://gitlab.com/qemu-project/qemu/-/issues/928 Signed-off-by: Mathias Krause --- v2: use ASM_TRY() as suggested by Sean The non-canonical jump test is, apparently, broken under TCG as well. It "succeeds," as in changing RIP and thereby creating a #GP loop. I therefore put the new test in front of it to allow it to run. x86/emulator64.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/x86/emulator64.c b/x86/emulator64.c index f8ff99fc39cc..e1a0968f5236 100644 --- a/x86/emulator64.c +++ b/x86/emulator64.c @@ -333,6 +333,33 @@ static void test_jmp_noncanonical(uint64_t *mem) "jump to non-canonical address"); } +static void test_reg_noncanonical(void) +{ + /* RAX based, should #GP(0) */ + asm volatile(ASM_TRY("1f") "orq $0, (%[noncanonical]); 1:" + : : [noncanonical]"a"(NONCANONICAL)); + report(exception_vector() == GP_VECTOR && exception_error_code() == 0, + "non-canonical memory access, should %s(0), got %s(%u)", + exception_mnemonic(GP_VECTOR), + exception_mnemonic(exception_vector()), exception_error_code()); + + /* RSP based, should #SS(0) */ + asm volatile(ASM_TRY("1f") "orq $0, (%%rsp,%[noncanonical],1); 1:" + : : [noncanonical]"r"(NONCANONICAL)); + report(exception_vector() == SS_VECTOR && exception_error_code() == 0, + "non-canonical rsp-based access, should %s(0), got %s(%u)", + exception_mnemonic(SS_VECTOR), + exception_mnemonic(exception_vector()), exception_error_code()); + + /* RBP based, should #SS(0) */ + asm volatile(ASM_TRY("1f") "orq $0, (%%rbp,%[noncanonical],1); 1:" + : : [noncanonical]"r"(NONCANONICAL)); + report(exception_vector() == SS_VECTOR && exception_error_code() == 0, + "non-canonical rbp-based access, should %s(0), got %s(%u)", + exception_mnemonic(SS_VECTOR), + exception_mnemonic(exception_vector()), exception_error_code()); +} + static void test_movabs(uint64_t *mem) { /* mov $0x9090909090909090, %rcx */ @@ -459,5 +486,6 @@ static void test_emulator_64(void *mem) test_push16(mem); + test_reg_noncanonical(); test_jmp_noncanonical(mem); }