xserver: Branch 'master' - 2 commits

Peter Hutterer whot at kemper.freedesktop.org
Wed Nov 1 00:32:51 UTC 2017


 config/udev.c                |   65 +++++++++++++--------------
 test/bigreq/meson.build      |    8 +++
 test/bigreq/request-length.c |  101 +++++++++++++++++++++++++++++++++++++++++++
 test/meson.build             |    1 
 4 files changed, 142 insertions(+), 33 deletions(-)

New commits:
commit 14af8bee242fe40af0e91c61465d6720aaa60e97
Author: Eric Anholt <eric at anholt.net>
Date:   Mon Oct 9 17:14:32 2017 -0700

    test: Add a test for the overflow bug in bigreqs.
    
    The failing struct comes from the python test written by Michal Srb
    <msrb at suse.com>.
    
    v2: Use a drawable (root window) and gc, so that PolyLines hopefully
        actually tries processing things.  However, the request seems to
        process successfully so the poll() just stalls out.  However, this
        does let us distinguish between detecting the bigrequests error
        and not, at least.
    v3: Clean up the description of what we expect the poll() call to do.
    v4: Use XI2 instead of PolyLine to trigger a predictable error. We know the
        server replies with BadValue for a zero num_masks argument. So if we send
        a bigreq with a num_masks 0 and a length 0, we can just check whether we
        get killed (good) or a BadValue (bad). It doesn't test for specific memory
        overflows or crashes, but based on the assumption that we shouldn't look
        at *any* BigReq of size 0, this seems to be sufficient.
    
    Signed-off-by: Eric Anholt <eric at anholt.net>
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/test/bigreq/meson.build b/test/bigreq/meson.build
new file mode 100644
index 000000000..9462ede31
--- /dev/null
+++ b/test/bigreq/meson.build
@@ -0,0 +1,8 @@
+xcb_dep = dependency('xcb', required: false)
+
+if get_option('xvfb')
+    if xcb_dep.found()
+        requestlength = executable('request-length', 'request-length.c', dependencies: xcb_dep)
+        test('request-length', simple_xinit, args: [requestlength, '--', xvfb_server])
+    endif
+endif
diff --git a/test/bigreq/request-length.c b/test/bigreq/request-length.c
new file mode 100644
index 000000000..8174813ae
--- /dev/null
+++ b/test/bigreq/request-length.c
@@ -0,0 +1,101 @@
+/*
+ * Copyright © 2017 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <poll.h>
+#include <xcb/xcb.h>
+#include <xcb/bigreq.h>
+#include <xcb/xinput.h>
+
+int main(int argc, char **argv)
+{
+    xcb_connection_t *c = xcb_connect(NULL, NULL);
+    int fd = xcb_get_file_descriptor(c);
+
+    struct {
+        uint8_t extension;
+        uint8_t opcode;
+        uint16_t length;
+        uint32_t length_bigreq;
+        uint32_t win;
+        int num_masks;
+        uint16_t pad;
+    } xise_req = {
+        .extension = 0,
+        .opcode = XCB_INPUT_XI_SELECT_EVENTS,
+        /* The server triggers BadValue on a zero num_mask */
+        .num_masks = 0,
+        .win = 0,
+
+        /* This is the value that triggers the bug. */
+        .length_bigreq = 0,
+    };
+
+    xcb_query_extension_cookie_t cookie;
+    xcb_query_extension_reply_t *rep;
+
+    cookie = xcb_query_extension(c, 15, "XInputExtension");
+    rep = xcb_query_extension_reply(c, cookie, NULL);
+    xise_req.extension = rep->major_opcode;
+
+    free(xcb_big_requests_enable_reply(c, xcb_big_requests_enable(c), NULL));
+
+    /* Manually write out the bad request.  XCB can't help us here.*/
+    write(fd, &xise_req, sizeof(xise_req));
+
+    /* Block until the server has processed our mess and throws an
+     * error. If we get disconnected, then the server has noticed what we're
+     * up to. If we get an error back from the server, it looked at our fake
+     * request - which shouldn't happen.
+     */
+    struct pollfd pfd = {
+        .fd = fd,
+        .events = POLLIN,
+    };
+    poll(&pfd, 1, -1);
+
+    if (pfd.revents & POLLHUP) {
+        /* We got killed by the server for being naughty. Yay! */
+        return 0;
+    }
+
+    /* We didn't get disconnected, that's bad. If we get a BadValue from our
+     * request, we at least know that the bug triggered.
+     *
+     * If we get anything else back, something else has gone wrong.
+     */
+    xcb_generic_error_t error;
+    int r = read(fd, &error, sizeof(error));
+
+    if (r == sizeof(error) &&
+        error.error_code == 2 /* BadValue */  &&
+        error.major_code == xise_req.extension &&
+        error.minor_code == XCB_INPUT_XI_SELECT_EVENTS)
+        return 1; /* Our request was processed, which shouldn't happen */
+
+    /* Something else bad happened. We got something back but it's not the
+     * error we expected. If this happens, it needs to be investigated. */
+
+    return 2;
+}
diff --git a/test/meson.build b/test/meson.build
index 3e482d6f1..d413e9da5 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -23,4 +23,5 @@ if get_option('xvfb')
     endif
 endif
 
+subdir('bigreq')
 subdir('sync')
commit 5aad81445c8c3d6b7b30d503cfe26027fa482870
Author: Peter Hutterer <peter.hutterer at who-t.net>
Date:   Tue Sep 26 15:21:59 2017 +1000

    config/udev: consider ID_INPUT_FOO=0 as 'unset'
    
    Historically we didn't need to care about this case but more devices are
    having invalid types set and they cannot be unset with a hwdb entry (which
    doesn't handle the empty string). Allow for "0" to mean "unset" because
    anything else would be crazy anyway.
    
    Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>

diff --git a/config/udev.c b/config/udev.c
index 932f230c7..e198e8609 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -134,7 +134,8 @@ device_added(struct udev_device *udev_device)
     }
 #endif
 
-    if (!udev_device_get_property_value(udev_device, "ID_INPUT")) {
+    value = udev_device_get_property_value(udev_device, "ID_INPUT");
+    if (value && !strcmp(value, "0")) {
         LogMessageVerb(X_INFO, 10,
                        "config/udev: ignoring device %s without "
                        "property ID_INPUT set\n", path);
@@ -237,38 +238,36 @@ device_added(struct udev_device *udev_device)
         else if (!strcmp(key, "ID_VENDOR")) {
             LOG_PROPERTY(path, key, value);
             attrs.vendor = strdup(value);
-        }
-        else if (!strcmp(key, "ID_INPUT_KEY")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_KEY;
-        }
-        else if (!strcmp(key, "ID_INPUT_KEYBOARD")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_KEYBOARD;
-        }
-        else if (!strcmp(key, "ID_INPUT_MOUSE")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_POINTER;
-        }
-        else if (!strcmp(key, "ID_INPUT_JOYSTICK")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_JOYSTICK;
-        }
-        else if (!strcmp(key, "ID_INPUT_TABLET")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_TABLET;
-        }
-        else if (!strcmp(key, "ID_INPUT_TABLET_PAD")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_TABLET_PAD;
-        }
-        else if (!strcmp(key, "ID_INPUT_TOUCHPAD")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_TOUCHPAD;
-        }
-        else if (!strcmp(key, "ID_INPUT_TOUCHSCREEN")) {
-            LOG_PROPERTY(path, key, value);
-            attrs.flags |= ATTR_TOUCHSCREEN;
+        } else if (!strncmp(key, "ID_INPUT_", 9)) {
+            const struct pfmap {
+                const char *property;
+                unsigned int flag;
+            } map[] = {
+                { "ID_INPUT_KEY", ATTR_KEY },
+                { "ID_INPUT_KEYBOARD", ATTR_KEYBOARD },
+                { "ID_INPUT_MOUSE", ATTR_POINTER },
+                { "ID_INPUT_JOYSTICK", ATTR_JOYSTICK },
+                { "ID_INPUT_TABLET", ATTR_TABLET },
+                { "ID_INPUT_TABLET_PAD", ATTR_TABLET_PAD },
+                { "ID_INPUT_TOUCHPAD", ATTR_TOUCHPAD },
+                { "ID_INPUT_TOUCHSCREEN", ATTR_TOUCHSCREEN },
+                { NULL, 0 },
+            };
+
+            /* Anything but the literal string "0" is considered a
+             * boolean true. The empty string isn't a thing with udev
+             * properties anyway */
+            if (value && strcmp(value, "0")) {
+                const struct pfmap *m = map;
+
+                while (m->property != NULL) {
+                    if (!strcmp(m->property, key)) {
+                        LOG_PROPERTY(path, key, value);
+                        attrs.flags |= m->flag;
+                    }
+                    m++;
+                }
+            }
         }
     }
 


More information about the xorg-commit mailing list