History

rseq: Remove broken uapi field layout on 32-bit little endian

The rseq rseq_cs.ptr.{ptr32,padding} uapi endianness handling is entirely wrong on 32-bit little endian: a preprocessor logic mistake wrongly uses the big endian field layout on 32-bit little endian architectures. Fortunately, those ptr32 accessors were never used within the kernel, and only meant as a convenience for user-space. Remove those and replace the whole rseq_cs union by a __u64 type, as this is the only thing really needed to express the ABI. Document how 32-bit architectures are meant to interact with this field.

Mathieu Desnoyers committed 4 years ago

Commit bfdf4e61 parent 5c105d52 files · +8 −20Browse files

Unified · Split

2 files
  1. include/uapi/linux/rseq.h +4 −16
  2. kernel/rseq.c +4 −4
include/uapi/linux/rseq.h+4−16
@@ -105,23 +105,11 @@ struct rseq { · 104 unmodified lines
105105 * Read and set by the kernel. Set by user-space with single-copy
106106 * atomicity semantics. This field should only be updated by the
107107 * thread which registered this data structure. Aligned on 64-bit.
108+ *
109+ * 32-bit architectures should update the low order bits of the
110+ * rseq_cs field, leaving the high order bits initialized to 0.
108111 */
109− union {
110− __u64 ptr64;
111−#ifdef __LP64__
112− __u64 ptr;
113−#else
114− struct {
115−#if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || defined(__BIG_ENDIAN)
116− __u32 padding; /* Initialized to zero. */
117− __u32 ptr32;
118−#else /* LITTLE */
119− __u32 ptr32;
120− __u32 padding; /* Initialized to zero. */
121−#endif /* ENDIAN */
122− } ptr;
123−#endif
124− } rseq_cs;
112+ __u64 rseq_cs;
125113
126114 /*
127115 * Restartable sequences flags field.
kernel/rseq.c+4−4
@@ -128,10 +128,10 @@ static int rseq_get_rseq_cs(struct task_struct *t, struct rseq_cs *rseq_cs) · 127 unmodified lines
128128 int ret;
129129
130130 #ifdef CONFIG_64BIT
131− if (get_user(ptr, &t->rseq->rseq_cs.ptr64))
131+ if (get_user(ptr, &t->rseq->rseq_cs))
132132 return -EFAULT;
133133 #else
134− if (copy_from_user(&ptr, &t->rseq->rseq_cs.ptr64, sizeof(ptr)))
134+ if (copy_from_user(&ptr, &t->rseq->rseq_cs, sizeof(ptr)))
135135 return -EFAULT;
136136 #endif
137137 if (!ptr) {
@@ -217,9 +217,9 @@ static int clear_rseq_cs(struct task_struct *t) · 79 unmodified lines
217217 * Set rseq_cs to NULL.
218218 */
219219 #ifdef CONFIG_64BIT
220− return put_user(0UL, &t->rseq->rseq_cs.ptr64);
220+ return put_user(0UL, &t->rseq->rseq_cs);
221221 #else
222− if (clear_user(&t->rseq->rseq_cs.ptr64, sizeof(t->rseq->rseq_cs.ptr64)))
222+ if (clear_user(&t->rseq->rseq_cs, sizeof(t->rseq->rseq_cs)))
223223 return -EFAULT;
224224 return 0;
225225 #endif