@@ -40,10 +40,14 @@ DECLARE_PER_CPU(u32, kstack_offset);
40
40
*/
41
41
#define KSTACK_OFFSET_MAX (x ) ((x) & 0x3FF)
42
42
43
- /*
44
- * These macros must be used during syscall entry when interrupts and
43
+ /**
44
+ * add_random_kstack_offset - Increase stack utilization by previously
45
+ * chosen random offset
46
+ *
47
+ * This should be used in the syscall entry path when interrupts and
45
48
* preempt are disabled, and after user registers have been stored to
46
- * the stack.
49
+ * the stack. For testing the resulting entropy, please see:
50
+ * tools/testing/selftests/lkdtm/stack-entropy.sh
47
51
*/
48
52
#define add_random_kstack_offset () do { \
49
53
if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \
@@ -55,6 +59,23 @@ DECLARE_PER_CPU(u32, kstack_offset);
55
59
} \
56
60
} while (0 )
57
61
62
+ /**
63
+ * choose_random_kstack_offset - Choose the random offset for the next
64
+ * add_random_kstack_offset()
65
+ *
66
+ * This should only be used during syscall exit when interrupts and
67
+ * preempt are disabled. This position in the syscall flow is done to
68
+ * frustrate attacks from userspace attempting to learn the next offset:
69
+ * - Maximize the timing uncertainty visible from userspace: if the
70
+ * offset is chosen at syscall entry, userspace has much more control
71
+ * over the timing between choosing offsets. "How long will we be in
72
+ * kernel mode?" tends to be more difficult to predict than "how long
73
+ * will we be in user mode?"
74
+ * - Reduce the lifetime of the new offset sitting in memory during
75
+ * kernel mode execution. Exposure of "thread-local" memory content
76
+ * (e.g. current, percpu, etc) tends to be easier than arbitrary
77
+ * location memory exposure.
78
+ */
58
79
#define choose_random_kstack_offset (rand ) do { \
59
80
if (static_branch_maybe(CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT, \
60
81
&randomize_kstack_offset)) { \
0 commit comments