[PATCH v11 08/13] task_isolation: add PR_TASK_ISOLATION_ONE_SHOT flag
From: Chris Metcalf
Date: Fri Mar 11 2016 - 17:11:53 EST
When this flag is set by the initial prctl(), the semantics of task
isolation change to be "one-shot", i.e. as soon as the kernel is
re-entered for any reason, task isolation is turned off.
During application development, use of this flag is best coupled with
STRICT mode, since otherwise any bug (e.g. an munmap from another
thread in the same task causing an IPI TLB flush) could cause the
task to fall out of task isolation mode without being aware of it.
In production it is typically still best to use STRICT mode, with
a signal handler that will report violations of task isolation
up to the application layer. However, if you are confident the
application will never fall out of task isolation mode, you may
wish to use ONE_SHOT mode to allow switching from userspace task
isolation mode, to using the kernel freely, without the small extra
penalty of invoking prctl() explicitly to turn task isolation off
before starting to use kernel services.
Signed-off-by: Chris Metcalf <cmetcalf@xxxxxxxxxxxx>
---
include/uapi/linux/prctl.h | 1 +
kernel/isolation.c | 7 +++++++
2 files changed, 8 insertions(+)
diff --git a/include/uapi/linux/prctl.h b/include/uapi/linux/prctl.h
index a5582ace987f..1e204f1a0f4a 100644
--- a/include/uapi/linux/prctl.h
+++ b/include/uapi/linux/prctl.h
@@ -202,6 +202,7 @@ struct prctl_mm_map {
#define PR_GET_TASK_ISOLATION 49
# define PR_TASK_ISOLATION_ENABLE (1 << 0)
# define PR_TASK_ISOLATION_STRICT (1 << 1)
+# define PR_TASK_ISOLATION_ONE_SHOT (1 << 2)
# define PR_TASK_ISOLATION_SET_SIG(sig) (((sig) & 0x7f) << 8)
# define PR_TASK_ISOLATION_GET_SIG(bits) (((bits) >> 8) & 0x7f)
diff --git a/kernel/isolation.c b/kernel/isolation.c
index db281dee7d7e..d94a137e0349 100644
--- a/kernel/isolation.c
+++ b/kernel/isolation.c
@@ -202,7 +202,11 @@ void _task_isolation_exception(const char *fmt, ...)
va_end(args);
task_isolation_interrupt(task, buf);
+ return;
}
+
+ if (task->task_isolation_flags & PR_TASK_ISOLATION_ONE_SHOT)
+ task_isolation_set_flags(task, 0);
}
/*
@@ -226,6 +230,9 @@ int task_isolation_syscall(int syscall)
return -1;
}
+ if (task->task_isolation_flags & PR_TASK_ISOLATION_ONE_SHOT)
+ task_isolation_set_flags(task, 0);
+
return 0;
}
--
2.7.2