<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Sun, Aug 19, 2018 at 4:04 PM Dmitry V. Levin <<a href="mailto:ldv@altlinux.org">ldv@altlinux.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, Aug 18, 2018 at 06:45:52PM +0800, Zhibin Li wrote:<br>
> OK, it's in linux/drivers/input/evdev.c:<br>
> line 812: in function handle_eviocgbit:<br>
> return bits_to_user(bits, len, size, p, compat_mode);<br>
> and then in function bits_to_user:<br>
> int len = BITS_TO_LONGS(maxbit) * sizeof(long);<br>
> ...<br>
> return copy_to_user(p, bits, len) ? -EFAULT : len;<br>
> Correct me if I'm wrong, thanks :)<br>
<br>
I wish you've written something like this in the commit message. :)<br>
I suggest to apply the fix as a separate commit, e.g.<br>
<br>
Subject: [PATCH] evdev: fix decoding of bit sets<br>
<br>
According to drivers/input/evdev.c:bits_to_user(),<br>
the Linux kernel returns the number of bytes, not bits.<br>
<br>
* evdev.c (decode_bitset_): Treat syscall return value as the number<br>
of bytes.<br>
<br>
diff --git a/evdev.c b/evdev.c<br>
index 7ca15c9dd..3c1aaa8e2 100644<br>
--- a/evdev.c<br>
+++ b/evdev.c<br>
@@ -171,10 +171,10 @@ decode_bitset_(struct tcb *const tcp, const kernel_ulong_t arg,<br>
        tprints(", ");<br>
<br>
        unsigned int size;<br>
-       if ((kernel_ulong_t) tcp->u_rval > max_nr)<br>
+       if ((kernel_ulong_t) tcp->u_rval > max_nr / 8)<br>
                size = max_nr;<br>
        else<br>
-               size = tcp->u_rval;<br>
+               size = tcp->u_rval * 8;<br>
        char decoded_arg[size];<br>
<br>
        if (umove_or_printaddr(tcp, arg, &decoded_arg))<br>
<br>
What do you think?<br></blockquote><div>I agree. The fix for decoding of bit set isn't just about EVIOCGBIT. It also</div><div>affects other flags/cmds so I shouldn't mess this up with the fix for</div><div>decoding of EVIOCGBIT(0, ...)  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
-- <br>
ldv<br>
-- <br>
Strace-devel mailing list<br>
<a href="mailto:Strace-devel@lists.strace.io" target="_blank">Strace-devel@lists.strace.io</a><br>
<a href="https://lists.strace.io/mailman/listinfo/strace-devel" rel="noreferrer" target="_blank">https://lists.strace.io/mailman/listinfo/strace-devel</a><br>
</blockquote></div></div>