]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
rseq: Remove broken uapi field layout on 32-bit little endian
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 27 Jan 2022 15:27:20 +0000 (10:27 -0500)
committerStefan Bader <stefan.bader@canonical.com>
Fri, 20 May 2022 12:38:05 +0000 (14:38 +0200)
BugLink: https://bugs.launchpad.net/bugs/1969110
[ Upstream commit bfdf4e6208051ed7165b2e92035b4bf11f43eb63 ]

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.

Fixes: ec9c82e03a74 ("rseq: uapi: Declare rseq_cs field as union, update includes")
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220127152720.25898-1-mathieu.desnoyers@efficios.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
(cherry picked from commit 3bb11f3f6872a692759f653f90d10674deb330a4)
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
include/uapi/linux/rseq.h
kernel/rseq.c

index 9a402fdb60e97bc92591312ebc7071de54fa900c..77ee207623a9bfaeb151c92be753e667d5f1810e 100644 (file)
@@ -105,23 +105,11 @@ struct rseq {
         * Read and set by the kernel. Set by user-space with single-copy
         * atomicity semantics. This field should only be updated by the
         * thread which registered this data structure. Aligned on 64-bit.
+        *
+        * 32-bit architectures should update the low order bits of the
+        * rseq_cs field, leaving the high order bits initialized to 0.
         */
-       union {
-               __u64 ptr64;
-#ifdef __LP64__
-               __u64 ptr;
-#else
-               struct {
-#if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || defined(__BIG_ENDIAN)
-                       __u32 padding;          /* Initialized to zero. */
-                       __u32 ptr32;
-#else /* LITTLE */
-                       __u32 ptr32;
-                       __u32 padding;          /* Initialized to zero. */
-#endif /* ENDIAN */
-               } ptr;
-#endif
-       } rseq_cs;
+       __u64 rseq_cs;
 
        /*
         * Restartable sequences flags field.
index 6d45ac3dae7fb6714b9910ec8f2bca12f9481fa1..97ac20b4f7387f9276a3434b9a17fa61508997ae 100644 (file)
@@ -128,10 +128,10 @@ static int rseq_get_rseq_cs(struct task_struct *t, struct rseq_cs *rseq_cs)
        int ret;
 
 #ifdef CONFIG_64BIT
-       if (get_user(ptr, &t->rseq->rseq_cs.ptr64))
+       if (get_user(ptr, &t->rseq->rseq_cs))
                return -EFAULT;
 #else
-       if (copy_from_user(&ptr, &t->rseq->rseq_cs.ptr64, sizeof(ptr)))
+       if (copy_from_user(&ptr, &t->rseq->rseq_cs, sizeof(ptr)))
                return -EFAULT;
 #endif
        if (!ptr) {
@@ -217,9 +217,9 @@ static int clear_rseq_cs(struct task_struct *t)
         * Set rseq_cs to NULL.
         */
 #ifdef CONFIG_64BIT
-       return put_user(0UL, &t->rseq->rseq_cs.ptr64);
+       return put_user(0UL, &t->rseq->rseq_cs);
 #else
-       if (clear_user(&t->rseq->rseq_cs.ptr64, sizeof(t->rseq->rseq_cs.ptr64)))
+       if (clear_user(&t->rseq->rseq_cs, sizeof(t->rseq->rseq_cs)))
                return -EFAULT;
        return 0;
 #endif