Thread (43 messages) 43 messages, 7 authors, 2018-07-03

Re: [RFC PATCH for 4.18] rseq: use __u64 for rseq_cs fields, validate user inputs

From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Date: 2018-07-02 23:00:29
Also in: lkml

----- On Jul 2, 2018, at 6:45 PM, Linus Torvalds torvalds@linux-foundation.org wrote:
On Mon, Jul 2, 2018 at 3:31 PM Mathieu Desnoyers
[off-list ref] wrote:
quoted
Change the rseq ABI so rseq_cs start_ip, post_commit_offset and abort_ip
fields are seen as 64-bit fields by both 32-bit and 64-bit kernels rather
that ignoring the 32 upper bits on 32-bit kernels. This ensures we have a
consistent behavior for a 32-bit binary executed on 32-bit kernels and in
compat mode on 64-bit kernels.
Actually, now that I see this again, I react to:

quoted
+static int check_rseq_cs_padding(struct task_struct *t)
+{
+       u32 pad;
+       int ret;
+
+       ret = __get_user(pad, &t->rseq->rseq_cs_padding);
+       if (ret)
+               return ret;
+       if (pad)
+               return -EINVAL;
+       return 0;
+}
This is all wrong.

Just make "rseq_cs" be an __u64" too. That will clean up everything,
and user space will have a much easier time filling it in too, since
it's just one field. Instead of having to remember about the "let's
fill in padding for 32-bit cases".

Then the rseq_get_rseq_cs() will be

       __u64 rseq_cs;

       ret = get_user(rseq_cs, &t->rseq->rseq_cs);
       if (ret)
               return ret;
       ptr = (void *)rseq_cs;
       if (rseq_cs != (unsigned long)ptr)
               return -EINVAL;

and it's all good, no #ifdef's etc needed.

Hmm?
Unfortunately, that rseq->rseq_cs field needs to be updated by user-space
with single-copy atomicity. Therefore, we want 32-bit user-space to initialize
the padding with 0, and only update the low bits with single-copy atomicity.
Sorry for the bike-shedding, but this is now the last remaining user
of that LINUX_FIELD_u32_u64, so let's just get rid of it entirely, ok?

Then we can also get rid of that silly uapi/linux/types_32_64.h header
file entirely.

That would be *lovely*. Simpler code, simpler and less error-prone
interfaces, and one less specialized header file.
We can easily switch from LINUX_FIELD_u32_u64 to __u64 for fields within
struct rseq_cs because we have no requirement on update single-copy
atomicity. However, this is not true for the rseq->rseq_cs pointer.

Thoughts ?

Thanks,

Mathieu

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help