@@ -19,6 +19,7 @@ struct cet_stat {
unsigned int ibt_enabled:1;
unsigned int locked:1;
unsigned int exec_shstk:2;
+ unsigned int exec_ibt:2;
};
#ifdef CONFIG_X86_INTEL_CET
@@ -20,6 +20,7 @@
#define ARCH_CET_EXEC 0x3004
#define ARCH_CET_ALLOC_SHSTK 0x3005
#define ARCH_CET_PUSH_SHSTK 0x3006
+#define ARCH_CET_LEGACY_BITMAP 0x3007
/*
* Settings for ARCH_CET_EXEC
@@ -19,6 +19,7 @@
* ARCH_CET_EXEC: set default features for exec()
* ARCH_CET_ALLOC_SHSTK: allocate shadow stack
* ARCH_CET_PUSH_SHSTK: put a return address on shadow stack
+ * ARCH_CET_LEGACY_BITMAP: allocate legacy bitmap
*/
static int handle_get_status(unsigned long arg2)
@@ -28,8 +29,12 @@ static int handle_get_status(unsigned long arg2)
if (current->thread.cet.shstk_enabled)
features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
+ if (current->thread.cet.ibt_enabled)
+ features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
if (current->thread.cet.exec_shstk == CET_EXEC_ALWAYS_ON)
cet_exec |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
+ if (current->thread.cet.exec_ibt == CET_EXEC_ALWAYS_ON)
+ cet_exec |= GNU_PROPERTY_X86_FEATURE_1_IBT;
shstk_size = current->thread.cet.exec_shstk_size;
if (in_compat_syscall()) {
@@ -94,9 +99,18 @@ static int handle_set_exec(unsigned long arg2)
return -EPERM;
}
+ if (features & GNU_PROPERTY_X86_FEATURE_1_IBT) {
+ if (!cpu_feature_enabled(X86_FEATURE_IBT))
+ return -EINVAL;
+ if ((current->thread.cet.exec_ibt == CET_EXEC_ALWAYS_ON) &&
+ (cet_exec != CET_EXEC_ALWAYS_ON))
+ return -EPERM;
+ }
+
if (features & GNU_PROPERTY_X86_FEATURE_1_SHSTK)
current->thread.cet.exec_shstk = cet_exec;
-
+ if (features & GNU_PROPERTY_X86_FEATURE_1_IBT)
+ current->thread.cet.exec_ibt = cet_exec;
current->thread.cet.exec_shstk_size = shstk_size;
return 0;
}
@@ -167,9 +181,36 @@ static int handle_alloc_shstk(unsigned long arg2)
return 0;
}
+static int handle_bitmap(unsigned long arg2)
+{
+ unsigned long addr, size;
+
+ if (current->thread.cet.ibt_enabled) {
+ if (!current->thread.cet.ibt_bitmap_addr)
+ cet_setup_ibt_bitmap();
+ addr = current->thread.cet.ibt_bitmap_addr;
+ size = current->thread.cet.ibt_bitmap_size;
+ } else {
+ addr = 0;
+ size = 0;
+ }
+
+ if (in_compat_syscall()) {
+ if (put_user(addr, (unsigned int __user *)arg2) ||
+ put_user(size, (unsigned int __user *)arg2 + 1))
+ return -EFAULT;
+ } else {
+ if (put_user(addr, (unsigned long __user *)arg2) ||
+ put_user(size, (unsigned long __user *)arg2 + 1))
+ return -EFAULT;
+ }
+ return 0;
+}
+
int prctl_cet(int option, unsigned long arg2)
{
- if (!cpu_feature_enabled(X86_FEATURE_SHSTK))
+ if (!cpu_feature_enabled(X86_FEATURE_SHSTK) &&
+ !cpu_feature_enabled(X86_FEATURE_IBT))
return -EINVAL;
switch (option) {
@@ -181,7 +222,8 @@ int prctl_cet(int option, unsigned long arg2)
return -EPERM;
if (arg2 & GNU_PROPERTY_X86_FEATURE_1_SHSTK)
cet_disable_free_shstk(current);
-
+ if (arg2 & GNU_PROPERTY_X86_FEATURE_1_IBT)
+ cet_disable_ibt();
return 0;
case ARCH_CET_LOCK:
@@ -197,6 +239,12 @@ int prctl_cet(int option, unsigned long arg2)
case ARCH_CET_PUSH_SHSTK:
return handle_push_shstk(arg2);
+ /*
+ * Allocate legacy bitmap and return address & size to user.
+ */
+ case ARCH_CET_LEGACY_BITMAP:
+ return handle_bitmap(arg2);
+
default:
return -EINVAL;
}
@@ -230,10 +230,14 @@ int arch_setup_features(void *ehdr_p, void *phdr_p,
}
if (cpu_feature_enabled(X86_FEATURE_IBT)) {
- if (ibt) {
- err = cet_setup_ibt();
- if (err < 0)
- goto out;
+ int exec = current->thread.cet.exec_ibt;
+
+ if (exec != CET_EXEC_ALWAYS_OFF) {
+ if (ibt || (exec == CET_EXEC_ALWAYS_ON)) {
+ err = cet_setup_ibt();
+ if (err < 0)
+ goto out;
+ }
}
}
@@ -801,6 +801,7 @@ long do_arch_prctl_common(struct task_struct *task, int option,
case ARCH_CET_EXEC:
case ARCH_CET_ALLOC_SHSTK:
case ARCH_CET_PUSH_SHSTK:
+ case ARCH_CET_LEGACY_BITMAP:
return prctl_cet(option, cpuid_enabled);
}