View | Details | Raw Unified | Return to bug 196678 | Differences between
and this patch

Collapse All | Expand All

(-)Mk/bsd.xorg.mk (-8 / +10 lines)
Lines 58-69 Link Here
58
. endif
58
. endif
59
59
60
. if ${XORG_CAT} == "driver"
60
. if ${XORG_CAT} == "driver"
61
USE_XORG+=	xorg-server xproto randrproto xi renderproto xextproto \
61
USE_XORG+=	dri2proto dri3proto fontsproto glproto inputproto kbproto \
62
		inputproto kbproto fontsproto videoproto dri2proto dri3proto \
62
			presentproto randrproto renderproto resourceproto \
63
		xf86driproto presentproto glproto xineramaproto resourceproto \
63
			scrnsaverproto videoproto xextproto xf86driproto xi \
64
		scrnsaverproto
64
			xineramaproto xorg-server xproto
65
CONFIGURE_ENV+=	DRIVER_MAN_SUFFIX=4x DRIVER_MAN_DIR='$$(mandir)/man4'
65
CONFIGURE_ENV+=	DRIVER_MAN_SUFFIX=4x DRIVER_MAN_DIR='$$(mandir)/man4'
66
USES+=		libtool
66
CFLAGS+=		-Werror=uninitialized
67
USES+=			libtool
67
INSTALL_TARGET=	install-strip
68
INSTALL_TARGET=	install-strip
68
. endif
69
. endif
69
70
Lines 81-88 Link Here
81
.  endif
82
.  endif
82
83
83
. if ${XORG_CAT} == "lib"
84
. if ${XORG_CAT} == "lib"
84
USES+=		pathfix libtool
85
USES+=			libtool pathfix
85
USE_LDCONFIG=	yes
86
USE_LDCONFIG=	yes
87
CFLAGS+=		-Werror=uninitialized
86
CONFIGURE_ARGS+=--enable-malloc0returnsnull
88
CONFIGURE_ARGS+=--enable-malloc0returnsnull
87
. endif
89
. endif
88
90
Lines 93-102 Link Here
93
. if ${XORG_CAT} == "xserver"
95
. if ${XORG_CAT} == "xserver"
94
DISTFILES?=	xorg-server-${PORTVERSION}.tar.bz2
96
DISTFILES?=	xorg-server-${PORTVERSION}.tar.bz2
95
WRKSRC=		${WRKDIR}/xorg-server-${PORTVERSION}
97
WRKSRC=		${WRKDIR}/xorg-server-${PORTVERSION}
96
USES+=	pathfix
98
USES+=		libtool pathfix
99
CFLAGS+=	-Werror=uninitialized
97
CONFIGURE_ARGS+=	--with-xkb-path=${LOCALBASE}/share/X11/xkb \
100
CONFIGURE_ARGS+=	--with-xkb-path=${LOCALBASE}/share/X11/xkb \
98
					--with-fontrootdir=${LOCALBASE}/share/fonts
101
					--with-fontrootdir=${LOCALBASE}/share/fonts
99
100
LIB_PC_DEPENDS+=	${LOCALBASE}/libdata/pkgconfig/dri.pc:graphics/mesa-dri
102
LIB_PC_DEPENDS+=	${LOCALBASE}/libdata/pkgconfig/dri.pc:graphics/mesa-dri
101
USE_XORG+=	fontutil:build
103
USE_XORG+=	fontutil:build
102
. endif
104
. endif
(-)x11-servers/xephyr/Makefile (-2 lines)
Lines 16-23 Link Here
16
DESCR=		${.CURDIR}/pkg-descr
16
DESCR=		${.CURDIR}/pkg-descr
17
17
18
SLAVE_PORT=	yes
18
SLAVE_PORT=	yes
19
OPTIONS_EXCLUDE=DEVD HAL SUID
20
21
USE_XORG=	x11 xcb
19
USE_XORG=	x11 xcb
22
20
23
CONFIGURE_ARGS+=--enable-xephyr --disable-dmx --disable-xnest --disable-xvfb \
21
CONFIGURE_ARGS+=--enable-xephyr --disable-dmx --disable-xnest --disable-xvfb \
(-)x11-servers/xorg-dmx/Makefile (-2 lines)
Lines 11-18 Link Here
11
DESCR=		${.CURDIR}/pkg-descr
11
DESCR=		${.CURDIR}/pkg-descr
12
12
13
SLAVE_PORT=	yes
13
SLAVE_PORT=	yes
14
OPTIONS_EXCLUDE=DEVD HAL SUID
15
16
USE_XORG=	dmx dmxproto x11 xaw7 xext xfixes xi xmu xpm xrender xres xt xtst
14
USE_XORG=	dmx dmxproto x11 xaw7 xext xfixes xi xmu xpm xrender xres xt xtst
17
15
18
CONFIGURE_ARGS+=--enable-dmx --disable-xephyr --disable-xnest --disable-xvfb \
16
CONFIGURE_ARGS+=--enable-dmx --disable-xephyr --disable-xnest --disable-xvfb \
(-)x11-servers/xorg-nestserver/Makefile (-17 / +1 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	xorg-nestserver
4
PORTNAME=	xorg-nestserver
5
PORTVERSION=	1.19.1
6
PORTEPOCH=	2
5
PORTEPOCH=	2
7
6
8
COMMENT=	Nesting X server from X.Org
7
COMMENT=	Nesting X server from X.Org
Lines 11-42 Link Here
11
10
12
MASTERDIR=	${.CURDIR}/../xorg-server
11
MASTERDIR=	${.CURDIR}/../xorg-server
13
DESCR=		${.CURDIR}/pkg-descr
12
DESCR=		${.CURDIR}/pkg-descr
14
DISTINFO_FILE=	${.CURDIR}/distinfo
15
PATCHDIR=	${.CURDIR}/files
16
13
17
RUN_DEPENDS=	xkeyboard-config>=2.5:x11/xkeyboard-config
14
RUN_DEPENDS=	xkeyboard-config>=2.5:x11/xkeyboard-config
18
15
19
SLAVE_PORT=	yes
16
SLAVE_PORT=	yes
20
OPTIONS_EXCLUDE=DEVD HAL SUID
17
USE_XORG=	x11 xext
21
18
22
USE_XORG=	x11 xext xfont2
23
24
CONFIGURE_ARGS+=--enable-xnest --disable-dmx --disable-xephyr --disable-xvfb \
19
CONFIGURE_ARGS+=--enable-xnest --disable-dmx --disable-xephyr --disable-xvfb \
25
		--disable-xwayland
20
		--disable-xwayland
26
21
27
PLIST_FILES=	bin/Xnest man/man1/Xnest.1.gz
22
PLIST_FILES=	bin/Xnest man/man1/Xnest.1.gz
28
23
29
EXTRA_PATCHES=	${MASTERDIR}/files/patch-CVE-2017-12176 \
30
		${MASTERDIR}/files/patch-CVE-2017-12177 \
31
		${MASTERDIR}/files/patch-CVE-2017-12178 \
32
		${MASTERDIR}/files/patch-CVE-2017-12179 \
33
		${MASTERDIR}/files/patch-CVE-2017-12183 \
34
		${MASTERDIR}/files/patch-CVE-2017-1218x \
35
		${MASTERDIR}/files/patch-CVE-2017-1218y \
36
		${MASTERDIR}/files/patch-CVE-2017-13721 \
37
		${MASTERDIR}/files/patch-CVE-2017-13723 \
38
		${MASTERDIR}/files/patch-os_io.c
39
40
do-install:
24
do-install:
41
	cd ${WRKSRC}/hw/xnest; DESTDIR=${STAGEDIR} ${MAKE} install
25
	cd ${WRKSRC}/hw/xnest; DESTDIR=${STAGEDIR} ${MAKE} install
42
26
(-)x11-servers/xorg-nestserver/distinfo (-3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484388904
2
SHA256 (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 79ae2cf39d3f6c4a91201d8dad549d1d774b3420073c5a70d390040aa965a7fb
3
SIZE (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 6041792
(-)x11-servers/xorg-server/Makefile (-52 / +28 lines)
Lines 2-9 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME?=	xorg-server
4
PORTNAME?=	xorg-server
5
PORTVERSION?=	1.18.4
5
PORTVERSION?=	1.19.6
6
PORTREVISION?=	6
6
PORTREVISION?=	0
7
PORTEPOCH?=	1
7
PORTEPOCH?=	1
8
CATEGORIES=	x11-servers
8
CATEGORIES=	x11-servers
9
MASTER_SITES=	XORG/individual/xserver
9
MASTER_SITES=	XORG/individual/xserver
Lines 23-39 Link Here
23
OPTIONS_SUB=	yes
23
OPTIONS_SUB=	yes
24
OPTIONS_DEFINE=	SUID
24
OPTIONS_DEFINE=	SUID
25
OPTIONS_RADIO=	CONF
25
OPTIONS_RADIO=	CONF
26
OPTIONS_RADIO_CONF=	DEVD HAL
26
OPTIONS_RADIO_CONF=	DEVD HAL UDEV
27
DEVD_DESC=	Use devd for autoconfiguration of input devices
27
OPTIONS_DEFAULT=	DEVD SUID
28
HAL_DESC=	Use hald for autoconfiguration of input devices
29
SUID_DESC=	Install the Xorg server with setuid bit set
30
OPTIONS_DEFAULT=DEVD SUID
31
28
29
SUID_DESC=	Install setuid wrapper to allow startx as non-root
30
CONF_DESC=	Backend to use for input device configuration
31
DEVD_DESC=	Use devd (native)
32
HAL_DESC=	Use HAL (deprecated)
33
UDEV_DESC=	Use udev via libudev-devd (experimental)
34
32
OPTIONS_EXCLUDE_sparc64=	HAL
35
OPTIONS_EXCLUDE_sparc64=	HAL
33
36
34
.include <bsd.port.options.mk>
37
DEVD_CONFIGURE_ENABLE=	config-devd
38
HAL_CONFIGURE_ENABLE=	config-hal
39
HAL_LIB_DEPENDS=	libhal.so:sysutils/hal \
40
			libdbus-1.so:devel/dbus
41
SUID_CONFIGURE_ENABLE=	suid-wrapper
42
SUID_CONFIGURE_ON=	--libexecdir=${PREFIX}/bin	# set SUID_WRAPPER_DIR
43
UDEV_CONFIGURE_ENABLE=	config-udev
44
UDEV_CONFIGURE_ON=	--disable-config-udev-kms
45
UDEV_LIB_DEPENDS=	libudev.so:devel/libudev-devd
35
46
36
USES=		gmake libtool perl5 ssl tar:bzip2
47
USES=		gmake perl5 ssl
37
USE_PERL5=	build
48
USE_PERL5=	build
38
USE_GL+=	gl
49
USE_GL+=	gl
39
USE_XORG+=	bigreqsproto compositeproto damageproto dri2proto dri3proto \
50
USE_XORG+=	bigreqsproto compositeproto damageproto dri2proto dri3proto \
Lines 40-51 Link Here
40
		fixesproto fontsproto glproto inputproto kbproto pixman \
51
		fixesproto fontsproto glproto inputproto kbproto pixman \
41
		presentproto randrproto recordproto renderproto \
52
		presentproto randrproto recordproto renderproto \
42
		resourceproto scrnsaverproto videoproto xau \
53
		resourceproto scrnsaverproto videoproto xau \
43
		xcmiscproto xdmcp xextproto xf86driproto xfont \
54
		xcmiscproto xdmcp xextproto xf86driproto xfont2 \
44
		xineramaproto xkbfile xproto xshmfence xtrans
55
		xineramaproto xkbfile xproto xshmfence xtrans
45
CONFIGURE_ARGS+=--without-doxygen --without-xmlto --without-fop \
56
CONFIGURE_ARGS+=--without-doxygen --without-xmlto --without-fop \
46
		--localstatedir=/var --with-shared-memory-dir=/tmp \
57
		--without-dtrace --with-shared-memory-dir=/tmp \
47
		--disable-config-udev --disable-config-udev-kms \
58
		--disable-install-setuid
48
		--without-dtrace --enable-glamor
49
INSTALL_TARGET=	install-strip
59
INSTALL_TARGET=	install-strip
50
60
51
.if ${SLAVE_PORT} == "no" || ${PORTNAME} == "xephyr" || ${PORTNAME} == "xwayland"
61
.if ${SLAVE_PORT} == "no" || ${PORTNAME} == "xephyr" || ${PORTNAME} == "xwayland"
Lines 62-70 Link Here
62
		--disable-xwayland
72
		--disable-xwayland
63
SUB_FILES=	pkg-install pkg-deinstall
73
SUB_FILES=	pkg-install pkg-deinstall
64
.else
74
.else
65
CONFIGURE_ARGS+=--disable-xorg
75
CONFIGURE_ARGS+=	--disable-xorg
66
# for slave ports we need to overwrite PLIST, so it doesn't overwrite
76
OPTIONS_EXCLUDE=	DEVD HAL UDEV SUID
67
# PLIST_FILES, with the masterport plist.
77
# Set PLIST for slave ports so they only need to set PLIST_FILES
68
PLIST=		${.CURDIR}/pkg-plist
78
PLIST=		${.CURDIR}/pkg-plist
69
.endif
79
.endif
70
80
Lines 77-92 Link Here
77
CONFIGURE_ENV=	SHA1_LIB="-L/usr/lib -lcrypto" SHA1_CFLAGS="-I/usr/include"
87
CONFIGURE_ENV=	SHA1_LIB="-L/usr/lib -lcrypto" SHA1_CFLAGS="-I/usr/include"
78
.endif
88
.endif
79
89
80
.if ${PORT_OPTIONS:MHAL}
81
LIB_DEPENDS+=	libhal.so:sysutils/hal
82
CONFIGURE_ARGS+=	--enable-config-hal
83
.else
84
CONFIGURE_ARGS+=	--disable-config-hal
85
.endif
86
87
# We handle Xorg setuid in the plist. This allows to build xorg-server as a user.
88
CONFIGURE_ARGS+=--disable-install-setuid
89
90
.if ${ARCH} == "i386" || ${ARCH} == "amd64"
90
.if ${ARCH} == "i386" || ${ARCH} == "amd64"
91
LIB_DEPENDS+=	libunwind.so:devel/libunwind
91
LIB_DEPENDS+=	libunwind.so:devel/libunwind
92
.endif
92
.endif
Lines 97-135 Link Here
97
PLIST_SUB+=	SPARC64="@comment "
97
PLIST_SUB+=	SPARC64="@comment "
98
.endif
98
.endif
99
99
100
.if ${PORT_OPTIONS:MSUID}
101
pre-everything::
102
	@${ECHO_MSG} "By default, the X Server installs as a set-user-id root binary. When run by"
103
	@${ECHO_MSG} "a normal user, it checks arguments and environment as done in the x11/wrapper"
104
	@${ECHO_MSG} "port before handling them normally.  If you are concerned about the security"
105
	@${ECHO_MSG} "of this, but still want to run an X Server (for example using xdm/kdm/gdm,"
106
	@${ECHO_MSG} "which will still run the server as root), you can cancel the build and set"
107
	@${ECHO_MSG} "xorg-server_UNSET=SUID in /etc/make.conf."
108
.endif
109
110
post-patch:
100
post-patch:
111
	@${REINPLACE_CMD} 's/test.*-traditional.*;/true;/' \
101
	@${REINPLACE_CMD} 's/test.*-traditional.*;/true;/' \
112
		${WRKSRC}/configure
102
		${WRKSRC}/configure
113
# build libglx.so but don't install it yet. which is done in pre-install.
114
	@${REINPLACE_CMD} -e 's|@GLX_TRUE@GLXMODS =|@GLX_BOGUS@GLXMODS =|g' \
115
		-e 's|^LTLIBRARIES = |LTLIBRARIES = libglx.la |g' \
116
		${WRKSRC}/hw/xfree86/dixmods/Makefile.in
117
103
118
post-configure:
119
.if ${PORT_OPTIONS:MDEVD}
120
	@${REINPLACE_CMD} -e 's|config\.c|config.c devd.c|g' \
121
		-e 's|config\.lo|config.lo devd.lo|g' \
122
		${WRKSRC}/config/Makefile
123
	@${REINPLACE_CMD} -e 's|^/\* #undef CONFIG_UDEV \*/|#define CONFIG_DEVD 1|' \
124
		${WRKSRC}/include/dix-config.h
125
.endif
126
127
.if ${SLAVE_PORT} == "no"
104
.if ${SLAVE_PORT} == "no"
128
post-install:
105
post-install:
129
# The .xorg dir because else the xorg-server might not load the correct
106
# Avoid conflict with nvidia-driver, move libglx.so into .xorg directory
130
# libglx module.
131
	@${MKDIR} ${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg
107
	@${MKDIR} ${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg
132
	${INSTALL_LIB} ${WRKSRC}/hw/xfree86/dixmods/.libs/libglx.so \
108
	${MV} ${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/libglx.so \
133
		${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg/
109
		${STAGEDIR}${PREFIX}/lib/xorg/modules/extensions/.xorg/
134
	@${MKDIR} ${STAGEDIR}${PREFIX}/etc/X11/xorg.conf.d
110
	@${MKDIR} ${STAGEDIR}${PREFIX}/etc/X11/xorg.conf.d
135
.endif # ! SLAVE_PORT
111
.endif # ! SLAVE_PORT
(-)x11-servers/xorg-server/distinfo (-3 / +3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484803304
1
TIMESTAMP = 1521143244
2
SHA256 (xorg/xserver/xorg-server-1.18.4.tar.bz2) = 278459b2c31d61a15655d95a72fb79930c480a6bb8cf9226e48a07df8b1d31c8
2
SHA256 (xorg/xserver/xorg-server-1.19.6.tar.bz2) = a732502f1db000cf36a376cd0c010ffdbf32ecdd7f1fa08ba7f5bdf9601cc197
3
SIZE (xorg/xserver/xorg-server-1.18.4.tar.bz2) = 6009508
3
SIZE (xorg/xserver/xorg-server-1.19.6.tar.bz2) = 5984528
(-)x11-servers/xorg-server/files/config_Makefile.am (+16 lines)
Line 0 Link Here
1
* Build the devd config backend if activated
2
*
3
--- config/Makefile.am.orig	2017-03-16 05:24:43 UTC
4
+++ config/Makefile.am
5
@@ -4,6 +4,11 @@ noinst_LTLIBRARIES = libconfig.la
6
 libconfig_la_SOURCES = config.c config-backends.h
7
 libconfig_la_LIBADD =
8
 
9
+if CONFIG_DEVD
10
+libconfig_la_SOURCES += devd.c
11
+libconfig_la_LIBADD += -lusbhid
12
+endif
13
+
14
 if NEED_DBUS
15
 AM_CFLAGS += $(DBUS_CFLAGS)
16
 libconfig_la_SOURCES += dbus-core.c
(-)x11-servers/xorg-server/files/configure.ac (+97 lines)
Line 0 Link Here
1
* Plumb the devd config backend into configure
2
*
3
* define USE_DEV_IO for ARM platforms
4
*
5
* Only run pkg-config for udev if it is not disabled to prevent over-linking
6
*
7
* Automatically use systemd/logind only on Linux
8
*
9
--- configure.ac.orig	2017-03-15 18:05:25 UTC
10
+++ configure.ac
11
@@ -328,9 +328,12 @@ case $host_cpu in
12
 	esac
13
 	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
14
 	;;
15
-  arm*)
16
+  arm*|aarch64*)
17
 	ARM_VIDEO=yes
18
 	DEFAULT_INT10="stub"
19
+	case $host_os in
20
+		*freebsd*)	AC_DEFINE(USE_DEV_IO) ;;
21
+	esac
22
 	;;
23
   i*86)
24
 	I386_VIDEO=yes
25
@@ -628,6 +631,7 @@ AC_ARG_ENABLE(tslib,          AS_HELP_ST
26
 AC_ARG_ENABLE(dbe,            AS_HELP_STRING([--disable-dbe], [Build DBE extension (default: enabled)]), [DBE=$enableval], [DBE=yes])
27
 AC_ARG_ENABLE(xf86bigfont,    AS_HELP_STRING([--enable-xf86bigfont], [Build XF86 Big Font extension (default: disabled)]), [XF86BIGFONT=$enableval], [XF86BIGFONT=no])
28
 AC_ARG_ENABLE(dpms,           AS_HELP_STRING([--disable-dpms], [Build DPMS extension (default: enabled)]), [DPMSExtension=$enableval], [DPMSExtension=yes])
29
+AC_ARG_ENABLE(config-devd,    AS_HELP_STRING([--enable-config-devd], [Build devd support (default: auto)]), [CONFIG_DEVD=$enableval], [CONFIG_DEVD=auto])
30
 AC_ARG_ENABLE(config-udev,    AS_HELP_STRING([--enable-config-udev], [Build udev support (default: auto)]), [CONFIG_UDEV=$enableval], [CONFIG_UDEV=auto])
31
 AC_ARG_ENABLE(config-udev-kms,    AS_HELP_STRING([--enable-config-udev-kms], [Build udev kms support (default: auto)]), [CONFIG_UDEV_KMS=$enableval], [CONFIG_UDEV_KMS=auto])
32
 AC_ARG_ENABLE(config-hal,     AS_HELP_STRING([--disable-config-hal], [Build HAL support (default: auto)]), [CONFIG_HAL=$enableval], [CONFIG_HAL=auto])
33
@@ -924,10 +928,27 @@ if test "x$CONFIG_UDEV" = xyes && test "
34
 	AC_MSG_ERROR([Hotplugging through both libudev and hal not allowed])
35
 fi
36
 
37
-PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
38
-if test "x$CONFIG_UDEV" = xauto; then
39
-	CONFIG_UDEV="$HAVE_LIBUDEV"
40
-	AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if libudev is available.])
41
+if test "x$CONFIG_DEVD" = xauto; then
42
+	case $host_os in
43
+		*freebsd*)
44
+			CONFIG_DEVD=yes
45
+			;;
46
+		*)
47
+			CONFIG_DEVD=no
48
+			;;
49
+	esac
50
+fi
51
+AM_CONDITIONAL(CONFIG_DEVD, [test "x$CONFIG_DEVD" = xyes])
52
+if test "x$CONFIG_DEVD" = xyes; then
53
+	AC_DEFINE(CONFIG_DEVD, 1, [Use devd for input auto configuration])
54
+fi
55
+
56
+if test "x$CONFIG_UDEV" != xno; then
57
+	PKG_CHECK_MODULES(UDEV, $LIBUDEV, [HAVE_LIBUDEV=yes], [HAVE_LIBUDEV=no])
58
+	if test "x$CONFIG_UDEV" = xauto; then
59
+		CONFIG_UDEV="$HAVE_LIBUDEV"
60
+		AC_DEFINE(HAVE_LIBUDEV, 1, [Define to 1 if libudev is available.])
61
+	fi
62
 fi
63
 AM_CONDITIONAL(CONFIG_UDEV, [test "x$CONFIG_UDEV" = xyes])
64
 if test "x$CONFIG_UDEV" = xyes; then
65
@@ -975,7 +996,14 @@ AM_CONDITIONAL(CONFIG_HAL, [test "x$CONF
66
 
67
 if test "x$SYSTEMD_LOGIND" = xauto; then
68
         if test "x$HAVE_DBUS" = xyes -a "x$CONFIG_UDEV" = xyes ; then
69
-                SYSTEMD_LOGIND=yes
70
+            case $host_os in
71
+                *linux*)
72
+                        SYSTEMD_LOGIND=yes
73
+                        ;;
74
+                *)
75
+                        SYSTEMD_LOGIND=no
76
+                        ;;
77
+            esac
78
         else
79
                 SYSTEMD_LOGIND=no
80
         fi
81
@@ -2570,12 +2598,12 @@ AC_SUBST([prefix])
82
 
83
 AC_CONFIG_COMMANDS([sdksyms], [touch hw/xfree86/sdksyms.dep])
84
 
85
-if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno; then
86
+if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno && test "x$CONFIG_DEVD" = xno; then
87
     AC_MSG_WARN([
88
-             ***********************************************
89
-             Neither HAL nor udev backend will be enabled.
90
+             *****************************************************
91
+             Neither HAL, devd, nor udev backend will be enabled.
92
              Input device hotplugging will not be available!
93
-             ***********************************************])
94
+             *****************************************************])
95
 fi
96
 
97
 AC_CONFIG_FILES([
(-)x11-servers/xorg-server/files/hw_xfree86_Makefile.am (+14 lines)
Line 0 Link Here
1
* Don't overwrite Xorg binary with Xorg.sh when SUID_WRAPPER_DIR == bindir
2
* Instead, relink bin/X to Xorg.wrap rather than to Xorg (which isn't Xorg.sh)
3
*
4
--- hw/xfree86/Makefile.am.orig	2017-03-16 05:24:43 UTC
5
+++ hw/xfree86/Makefile.am
6
@@ -109,7 +109,7 @@ endif
7
 if SUID_WRAPPER
8
 	$(MKDIR_P) $(DESTDIR)$(SUID_WRAPPER_DIR)
9
 	mv $(DESTDIR)$(bindir)/Xorg $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg
10
-	${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg
11
+	(test ! -f $(DESTDIR)$(bindir)/Xorg && ${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg || cd $(DESTDIR)$(bindir) && rm -f X && $(LN_S) Xorg.wrap$(EXEEXT) X)
12
 	-chown root $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap && chmod u+s $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap
13
 endif
14
 
(-)x11-servers/xorg-server/files/patch-CVE-2017-12176 (-31 lines)
Lines 1-31 Link Here
1
From 95f605b42d8bbb6bea2834a1abfc205981c5b803 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Fri, 9 Jan 2015 10:15:46 -0500
4
Subject: Unvalidated extra length in ProcEstablishConnection (CVE-2017-12176)
5
6
Reviewed-by: Julien Cristau <jcristau@debian.org>
7
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
8
Signed-off-by: Julien Cristau <jcristau@debian.org>
9
(cherry picked from commit b747da5e25be944337a9cd1415506fc06b70aa81)
10
11
diff --git a/dix/dispatch.c b/dix/dispatch.c
12
index 0da431b..0fdfe11 100644
13
--- dix/dispatch.c
14
+++ dix/dispatch.c
15
@@ -3703,7 +3703,12 @@ ProcEstablishConnection(ClientPtr client)
16
     prefix = (xConnClientPrefix *) ((char *) stuff + sz_xReq);
17
     auth_proto = (char *) prefix + sz_xConnClientPrefix;
18
     auth_string = auth_proto + pad_to_int32(prefix->nbytesAuthProto);
19
-    if ((prefix->majorVersion != X_PROTOCOL) ||
20
+
21
+    if ((client->req_len << 2) != sz_xReq + sz_xConnClientPrefix +
22
+	pad_to_int32(prefix->nbytesAuthProto) +
23
+	pad_to_int32(prefix->nbytesAuthString))
24
+        reason = "Bad length";
25
+    else if ((prefix->majorVersion != X_PROTOCOL) ||
26
         (prefix->minorVersion != X_PROTOCOL_REVISION))
27
         reason = "Protocol version mismatch";
28
     else
29
-- 
30
cgit v0.10.2
31
(-)x11-servers/xorg-server/files/patch-CVE-2017-12177 (-41 lines)
Lines 1-41 Link Here
1
From cc41e5b581d287c56f8d7113a97a4882dcfdd696 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Fri, 9 Jan 2015 10:09:14 -0500
4
Subject: dbe: Unvalidated variable-length request in ProcDbeGetVisualInfo
5
 (CVE-2017-12177)
6
7
v2: Protect against integer overflow (Alan Coopersmith)
8
9
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
10
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
11
Reviewed-by: Julien Cristau <jcristau@debian.org>
12
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
13
Signed-off-by: Julien Cristau <jcristau@debian.org>
14
(cherry picked from commit 4ca68b878e851e2136c234f40a25008297d8d831)
15
16
diff --git a/dbe/dbe.c b/dbe/dbe.c
17
index 23f7e16..f31766f 100644
18
--- dbe/dbe.c
19
+++ dbe/dbe.c
20
@@ -574,6 +574,9 @@ ProcDbeGetVisualInfo(ClientPtr client)
21
     XdbeScreenVisualInfo *pScrVisInfo;
22
 
23
     REQUEST_AT_LEAST_SIZE(xDbeGetVisualInfoReq);
24
+    if (stuff->n > UINT32_MAX / sizeof(CARD32))
25
+        return BadLength;
26
+    REQUEST_FIXED_SIZE(xDbeGetVisualInfoReq, stuff->n * sizeof(CARD32));
27
 
28
     if (stuff->n > UINT32_MAX / sizeof(DrawablePtr))
29
         return BadAlloc;
30
@@ -924,7 +927,7 @@ SProcDbeSwapBuffers(ClientPtr client)
31
 
32
     swapl(&stuff->n);
33
     if (stuff->n > UINT32_MAX / sizeof(DbeSwapInfoRec))
34
-        return BadAlloc;
35
+        return BadLength;
36
     REQUEST_FIXED_SIZE(xDbeSwapBuffersReq, stuff->n * sizeof(xDbeSwapInfo));
37
 
38
     if (stuff->n != 0) {
39
-- 
40
cgit v0.10.2
41
(-)x11-servers/xorg-server/files/patch-CVE-2017-12178 (-29 lines)
Lines 1-29 Link Here
1
From 6c15122163a2d2615db7e998e8d436815a08dec6 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Wed, 24 Dec 2014 16:22:18 -0500
4
Subject: Xi: fix wrong extra length check in ProcXIChangeHierarchy
5
 (CVE-2017-12178)
6
7
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
8
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
9
Reviewed-by: Julien Cristau <jcristau@debian.org>
10
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
11
Signed-off-by: Julien Cristau <jcristau@debian.org>
12
(cherry picked from commit 859b08d523307eebde7724fd1a0789c44813e821)
13
14
diff --git a/Xi/xichangehierarchy.c b/Xi/xichangehierarchy.c
15
index f2b7785..7286eff 100644
16
--- Xi/xichangehierarchy.c
17
+++ Xi/xichangehierarchy.c
18
@@ -423,7 +423,7 @@ ProcXIChangeHierarchy(ClientPtr client)
19
     if (!stuff->num_changes)
20
         return rc;
21
 
22
-    len = ((size_t)stuff->length << 2) - sizeof(xXIAnyHierarchyChangeInfo);
23
+    len = ((size_t)stuff->length << 2) - sizeof(xXIChangeHierarchyReq);
24
 
25
     any = (xXIAnyHierarchyChangeInfo *) &stuff[1];
26
     while (stuff->num_changes--) {
27
-- 
28
cgit v0.10.2
29
(-)x11-servers/xorg-server/files/patch-CVE-2017-12179 (-52 lines)
Lines 1-52 Link Here
1
From c77cd08efcf386bcc5d8dfbd0427134b2b2d0888 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Fri, 9 Jan 2015 10:04:41 -0500
4
Subject: Xi: integer overflow and unvalidated length in
5
 (S)ProcXIBarrierReleasePointer
6
7
[jcristau: originally this patch fixed the same issue as commit
8
 211e05ac85 "Xi: Test exact size of XIBarrierReleasePointer", with the
9
 addition of these checks]
10
11
This addresses CVE-2017-12179
12
13
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
14
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
15
Reviewed-by: Julien Cristau <jcristau@debian.org>
16
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
17
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
18
Signed-off-by: Julien Cristau <jcristau@debian.org>
19
(cherry picked from commit d088e3c1286b548a58e62afdc70bb40981cdb9e8)
20
21
22
--- Xi/xibarriers.c.orig	2016-07-15 18:17:45.000000000 +0200
23
+++ Xi/xibarriers.c	2017-10-13 18:26:09.226006000 +0200
24
@@ -830,10 +830,15 @@
25
     REQUEST(xXIBarrierReleasePointerReq);
26
     int i;
27
 
28
-    info = (xXIBarrierReleasePointerInfo*) &stuff[1];
29
-
30
     swaps(&stuff->length);
31
+    REQUEST_AT_LEAST_SIZE(xXIBarrierReleasePointerReq);
32
+
33
     swapl(&stuff->num_barriers);
34
+    if (stuff->num_barriers > UINT32_MAX / sizeof(xXIBarrierReleasePointerInfo))
35
+        return BadLength;
36
+    REQUEST_FIXED_SIZE(xXIBarrierReleasePointerReq, stuff->num_barriers * sizeof(xXIBarrierReleasePointerInfo));
37
+
38
+    info = (xXIBarrierReleasePointerInfo*) &stuff[1];
39
     for (i = 0; i < stuff->num_barriers; i++, info++) {
40
         swaps(&info->deviceid);
41
         swapl(&info->barrier);
42
@@ -854,6 +859,10 @@
43
 
44
     REQUEST(xXIBarrierReleasePointerReq);
45
     REQUEST_AT_LEAST_SIZE(xXIBarrierReleasePointerReq);
46
+    if (stuff->num_barriers > UINT32_MAX / sizeof(xXIBarrierReleasePointerInfo))
47
+        return BadLength;
48
+    REQUEST_FIXED_SIZE(xXIBarrierReleasePointerReq, stuff->num_barriers * sizeof(xXIBarrierReleasePointerInfo));
49
+
50
 
51
     info = (xXIBarrierReleasePointerInfo*) &stuff[1];
52
     for (i = 0; i < stuff->num_barriers; i++, info++) {
(-)x11-servers/xorg-server/files/patch-CVE-2017-12183 (-95 lines)
Lines 1-95 Link Here
1
From 61502107a30d64f991784648c3228ebc6694a032 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Fri, 9 Jan 2015 11:43:05 -0500
4
Subject: xfixes: unvalidated lengths (CVE-2017-12183)
5
6
v2: Use before swap (Jeremy Huddleston Sequoia)
7
8
v3: Fix wrong XFixesCopyRegion checks (Alan Coopersmith)
9
10
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
11
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
12
Reviewed-by: Julien Cristau <jcristau@debian.org>
13
Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
14
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
15
Signed-off-by: Julien Cristau <jcristau@debian.org>
16
(cherry picked from commit 55caa8b08c84af2b50fbc936cf334a5a93dd7db5)
17
18
diff --git a/xfixes/cursor.c b/xfixes/cursor.c
19
index f009a78..6e84d71 100644
20
--- xfixes/cursor.c
21
+++ xfixes/cursor.c
22
@@ -281,6 +281,7 @@ int
23
 SProcXFixesSelectCursorInput(ClientPtr client)
24
 {
25
     REQUEST(xXFixesSelectCursorInputReq);
26
+    REQUEST_SIZE_MATCH(xXFixesSelectCursorInputReq);
27
 
28
     swaps(&stuff->length);
29
     swapl(&stuff->window);
30
@@ -414,7 +415,7 @@ ProcXFixesSetCursorName(ClientPtr client)
31
     REQUEST(xXFixesSetCursorNameReq);
32
     Atom atom;
33
 
34
-    REQUEST_AT_LEAST_SIZE(xXFixesSetCursorNameReq);
35
+    REQUEST_FIXED_SIZE(xXFixesSetCursorNameReq, stuff->nbytes);
36
     VERIFY_CURSOR(pCursor, stuff->cursor, client, DixSetAttrAccess);
37
     tchar = (char *) &stuff[1];
38
     atom = MakeAtom(tchar, stuff->nbytes, TRUE);
39
@@ -1007,6 +1008,8 @@ SProcXFixesCreatePointerBarrier(ClientPtr client)
40
     int i;
41
     CARD16 *in_devices = (CARD16 *) &stuff[1];
42
 
43
+    REQUEST_AT_LEAST_SIZE(xXFixesCreatePointerBarrierReq);
44
+
45
     swaps(&stuff->length);
46
     swaps(&stuff->num_devices);
47
     REQUEST_FIXED_SIZE(xXFixesCreatePointerBarrierReq, pad_to_int32(stuff->num_devices));
48
diff --git a/xfixes/region.c b/xfixes/region.c
49
index dd74d7f..f300d2b 100644
50
--- xfixes/region.c
51
+++ xfixes/region.c
52
@@ -359,6 +359,7 @@ ProcXFixesCopyRegion(ClientPtr client)
53
     RegionPtr pSource, pDestination;
54
 
55
     REQUEST(xXFixesCopyRegionReq);
56
+    REQUEST_SIZE_MATCH(xXFixesCopyRegionReq);
57
 
58
     VERIFY_REGION(pSource, stuff->source, client, DixReadAccess);
59
     VERIFY_REGION(pDestination, stuff->destination, client, DixWriteAccess);
60
@@ -375,7 +376,7 @@ SProcXFixesCopyRegion(ClientPtr client)
61
     REQUEST(xXFixesCopyRegionReq);
62
 
63
     swaps(&stuff->length);
64
-    REQUEST_AT_LEAST_SIZE(xXFixesCopyRegionReq);
65
+    REQUEST_SIZE_MATCH(xXFixesCopyRegionReq);
66
     swapl(&stuff->source);
67
     swapl(&stuff->destination);
68
     return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
69
diff --git a/xfixes/saveset.c b/xfixes/saveset.c
70
index eb3f658..aa365cf 100644
71
--- xfixes/saveset.c
72
+++ xfixes/saveset.c
73
@@ -62,6 +62,7 @@ int
74
 SProcXFixesChangeSaveSet(ClientPtr client)
75
 {
76
     REQUEST(xXFixesChangeSaveSetReq);
77
+    REQUEST_SIZE_MATCH(xXFixesChangeSaveSetReq);
78
 
79
     swaps(&stuff->length);
80
     swapl(&stuff->window);
81
diff --git a/xfixes/xfixes.c b/xfixes/xfixes.c
82
index 8d1bd4c..8b45c53 100644
83
--- xfixes/xfixes.c
84
+++ xfixes/xfixes.c
85
@@ -160,6 +160,7 @@ static int
86
 SProcXFixesQueryVersion(ClientPtr client)
87
 {
88
     REQUEST(xXFixesQueryVersionReq);
89
+    REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
90
 
91
     swaps(&stuff->length);
92
     swapl(&stuff->majorVersion);
93
-- 
94
cgit v0.10.2
95
(-)x11-servers/xorg-server/files/patch-CVE-2017-1218x (-601 lines)
Lines 1-601 Link Here
1
From d264da92f7f8129b8aad4f0114a6467fc38fc896 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Sun, 21 Dec 2014 01:10:03 -0500
4
Subject: hw/xfree86: unvalidated lengths
5
6
This addresses:
7
CVE-2017-12180 in XFree86-VidModeExtension
8
CVE-2017-12181 in XFree86-DGA
9
CVE-2017-12182 in XFree86-DRI
10
11
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
12
Reviewed-by: Julien Cristau <jcristau@debian.org>
13
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
14
Signed-off-by: Julien Cristau <jcristau@debian.org>
15
(cherry picked from commit 1b1d4c04695dced2463404174b50b3581dbd857b)
16
17
diff --git a/Xext/vidmode.c b/Xext/vidmode.c
18
index ea3ad13..76055c8 100644
19
--- Xext/vidmode.c
20
+++ Xext/vidmode.c
21
@@ -454,6 +454,20 @@ ProcVidModeAddModeLine(ClientPtr client)
22
     DEBUG_P("XF86VidModeAddModeline");
23
 
24
     ver = ClientMajorVersion(client);
25
+
26
+    if (ver < 2) {
27
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
28
+        len =
29
+            client->req_len -
30
+            bytes_to_int32(sizeof(xXF86OldVidModeAddModeLineReq));
31
+    }
32
+    else {
33
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
34
+        len =
35
+            client->req_len -
36
+            bytes_to_int32(sizeof(xXF86VidModeAddModeLineReq));
37
+    }
38
+
39
     if (ver < 2) {
40
         /* convert from old format */
41
         stuff = &newstuff;
42
@@ -501,18 +515,6 @@ ProcVidModeAddModeLine(ClientPtr client)
43
            stuff->after_vsyncend, stuff->after_vtotal,
44
            (unsigned long) stuff->after_flags);
45
 
46
-    if (ver < 2) {
47
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeAddModeLineReq);
48
-        len =
49
-            client->req_len -
50
-            bytes_to_int32(sizeof(xXF86OldVidModeAddModeLineReq));
51
-    }
52
-    else {
53
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeAddModeLineReq);
54
-        len =
55
-            client->req_len -
56
-            bytes_to_int32(sizeof(xXF86VidModeAddModeLineReq));
57
-    }
58
     if (len != stuff->privsize)
59
         return BadLength;
60
 
61
@@ -622,6 +624,20 @@ ProcVidModeDeleteModeLine(ClientPtr client)
62
     DEBUG_P("XF86VidModeDeleteModeline");
63
 
64
     ver = ClientMajorVersion(client);
65
+
66
+    if (ver < 2) {
67
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
68
+        len =
69
+            client->req_len -
70
+            bytes_to_int32(sizeof(xXF86OldVidModeDeleteModeLineReq));
71
+    }
72
+    else {
73
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
74
+        len =
75
+            client->req_len -
76
+            bytes_to_int32(sizeof(xXF86VidModeDeleteModeLineReq));
77
+    }
78
+
79
     if (ver < 2) {
80
         /* convert from old format */
81
         stuff = &newstuff;
82
@@ -649,18 +665,6 @@ ProcVidModeDeleteModeLine(ClientPtr client)
83
            stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
84
            (unsigned long) stuff->flags);
85
 
86
-    if (ver < 2) {
87
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeDeleteModeLineReq);
88
-        len =
89
-            client->req_len -
90
-            bytes_to_int32(sizeof(xXF86OldVidModeDeleteModeLineReq));
91
-    }
92
-    else {
93
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeDeleteModeLineReq);
94
-        len =
95
-            client->req_len -
96
-            bytes_to_int32(sizeof(xXF86VidModeDeleteModeLineReq));
97
-    }
98
     if (len != stuff->privsize) {
99
         DebugF("req_len = %ld, sizeof(Req) = %d, privsize = %ld, "
100
                "len = %d, length = %d\n",
101
@@ -744,6 +748,20 @@ ProcVidModeModModeLine(ClientPtr client)
102
     DEBUG_P("XF86VidModeModModeline");
103
 
104
     ver = ClientMajorVersion(client);
105
+
106
+    if (ver < 2) {
107
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
108
+        len =
109
+            client->req_len -
110
+            bytes_to_int32(sizeof(xXF86OldVidModeModModeLineReq));
111
+    }
112
+    else {
113
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
114
+        len =
115
+            client->req_len -
116
+            bytes_to_int32(sizeof(xXF86VidModeModModeLineReq));
117
+    }
118
+
119
     if (ver < 2) {
120
         /* convert from old format */
121
         stuff = &newstuff;
122
@@ -768,18 +786,6 @@ ProcVidModeModModeLine(ClientPtr client)
123
            stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend,
124
            stuff->vtotal, (unsigned long) stuff->flags);
125
 
126
-    if (ver < 2) {
127
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeModModeLineReq);
128
-        len =
129
-            client->req_len -
130
-            bytes_to_int32(sizeof(xXF86OldVidModeModModeLineReq));
131
-    }
132
-    else {
133
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeModModeLineReq);
134
-        len =
135
-            client->req_len -
136
-            bytes_to_int32(sizeof(xXF86VidModeModModeLineReq));
137
-    }
138
     if (len != stuff->privsize)
139
         return BadLength;
140
 
141
@@ -877,6 +883,19 @@ ProcVidModeValidateModeLine(ClientPtr client)
142
     DEBUG_P("XF86VidModeValidateModeline");
143
 
144
     ver = ClientMajorVersion(client);
145
+
146
+    if (ver < 2) {
147
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
148
+        len = client->req_len -
149
+            bytes_to_int32(sizeof(xXF86OldVidModeValidateModeLineReq));
150
+    }
151
+    else {
152
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
153
+        len =
154
+            client->req_len -
155
+            bytes_to_int32(sizeof(xXF86VidModeValidateModeLineReq));
156
+    }
157
+
158
     if (ver < 2) {
159
         /* convert from old format */
160
         stuff = &newstuff;
161
@@ -905,17 +924,6 @@ ProcVidModeValidateModeLine(ClientPtr client)
162
            stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
163
            (unsigned long) stuff->flags);
164
 
165
-    if (ver < 2) {
166
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeValidateModeLineReq);
167
-        len = client->req_len -
168
-            bytes_to_int32(sizeof(xXF86OldVidModeValidateModeLineReq));
169
-    }
170
-    else {
171
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeValidateModeLineReq);
172
-        len =
173
-            client->req_len -
174
-            bytes_to_int32(sizeof(xXF86VidModeValidateModeLineReq));
175
-    }
176
     if (len != stuff->privsize)
177
         return BadLength;
178
 
179
@@ -1027,6 +1035,20 @@ ProcVidModeSwitchToMode(ClientPtr client)
180
     DEBUG_P("XF86VidModeSwitchToMode");
181
 
182
     ver = ClientMajorVersion(client);
183
+
184
+    if (ver < 2) {
185
+        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeSwitchToModeReq);
186
+        len =
187
+            client->req_len -
188
+            bytes_to_int32(sizeof(xXF86OldVidModeSwitchToModeReq));
189
+    }
190
+    else {
191
+        REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
192
+        len =
193
+            client->req_len -
194
+            bytes_to_int32(sizeof(xXF86VidModeSwitchToModeReq));
195
+    }
196
+
197
     if (ver < 2) {
198
         /* convert from old format */
199
         stuff = &newstuff;
200
@@ -1055,18 +1077,6 @@ ProcVidModeSwitchToMode(ClientPtr client)
201
            stuff->vdisplay, stuff->vsyncstart, stuff->vsyncend, stuff->vtotal,
202
            (unsigned long) stuff->flags);
203
 
204
-    if (ver < 2) {
205
-        REQUEST_AT_LEAST_SIZE(xXF86OldVidModeSwitchToModeReq);
206
-        len =
207
-            client->req_len -
208
-            bytes_to_int32(sizeof(xXF86OldVidModeSwitchToModeReq));
209
-    }
210
-    else {
211
-        REQUEST_AT_LEAST_SIZE(xXF86VidModeSwitchToModeReq);
212
-        len =
213
-            client->req_len -
214
-            bytes_to_int32(sizeof(xXF86VidModeSwitchToModeReq));
215
-    }
216
     if (len != stuff->privsize)
217
         return BadLength;
218
 
219
@@ -1457,6 +1467,7 @@ ProcVidModeSetGammaRamp(ClientPtr client)
220
     VidModePtr pVidMode;
221
 
222
     REQUEST(xXF86VidModeSetGammaRampReq);
223
+    REQUEST_AT_LEAST_SIZE(xXF86VidModeSetGammaRampReq);
224
 
225
     if (stuff->screen >= screenInfo.numScreens)
226
         return BadValue;
227
diff --git a/hw/xfree86/common/xf86DGA.c b/hw/xfree86/common/xf86DGA.c
228
index c689dcb..039f38d 100644
229
--- hw/xfree86/common/xf86DGA.c
230
+++ hw/xfree86/common/xf86DGA.c
231
@@ -1272,13 +1272,14 @@ ProcXDGAOpenFramebuffer(ClientPtr client)
232
     char *deviceName;
233
     int nameSize;
234
 
235
+    REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq);
236
+
237
     if (stuff->screen >= screenInfo.numScreens)
238
         return BadValue;
239
 
240
     if (!DGAAvailable(stuff->screen))
241
         return DGAErrorBase + XF86DGANoDirectVideoMode;
242
 
243
-    REQUEST_SIZE_MATCH(xXDGAOpenFramebufferReq);
244
     rep.type = X_Reply;
245
     rep.length = 0;
246
     rep.sequenceNumber = client->sequence;
247
@@ -1305,14 +1306,14 @@ ProcXDGACloseFramebuffer(ClientPtr client)
248
 {
249
     REQUEST(xXDGACloseFramebufferReq);
250
 
251
+    REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq);
252
+
253
     if (stuff->screen >= screenInfo.numScreens)
254
         return BadValue;
255
 
256
     if (!DGAAvailable(stuff->screen))
257
         return DGAErrorBase + XF86DGANoDirectVideoMode;
258
 
259
-    REQUEST_SIZE_MATCH(xXDGACloseFramebufferReq);
260
-
261
     DGACloseFramebuffer(stuff->screen);
262
 
263
     return Success;
264
@@ -1328,10 +1329,11 @@ ProcXDGAQueryModes(ClientPtr client)
265
     xXDGAModeInfo info;
266
     XDGAModePtr mode;
267
 
268
+    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
269
+
270
     if (stuff->screen >= screenInfo.numScreens)
271
         return BadValue;
272
 
273
-    REQUEST_SIZE_MATCH(xXDGAQueryModesReq);
274
     rep.type = X_Reply;
275
     rep.length = 0;
276
     rep.number = 0;
277
@@ -1443,11 +1445,12 @@ ProcXDGASetMode(ClientPtr client)
278
     ClientPtr owner;
279
     int size;
280
 
281
+    REQUEST_SIZE_MATCH(xXDGASetModeReq);
282
+
283
     if (stuff->screen >= screenInfo.numScreens)
284
         return BadValue;
285
     owner = DGA_GETCLIENT(stuff->screen);
286
 
287
-    REQUEST_SIZE_MATCH(xXDGASetModeReq);
288
     rep.type = X_Reply;
289
     rep.length = 0;
290
     rep.offset = 0;
291
@@ -1533,14 +1536,14 @@ ProcXDGASetViewport(ClientPtr client)
292
 {
293
     REQUEST(xXDGASetViewportReq);
294
 
295
+    REQUEST_SIZE_MATCH(xXDGASetViewportReq);
296
+
297
     if (stuff->screen >= screenInfo.numScreens)
298
         return BadValue;
299
 
300
     if (DGA_GETCLIENT(stuff->screen) != client)
301
         return DGAErrorBase + XF86DGADirectNotActivated;
302
 
303
-    REQUEST_SIZE_MATCH(xXDGASetViewportReq);
304
-
305
     DGASetViewport(stuff->screen, stuff->x, stuff->y, stuff->flags);
306
 
307
     return Success;
308
@@ -1554,14 +1557,14 @@ ProcXDGAInstallColormap(ClientPtr client)
309
 
310
     REQUEST(xXDGAInstallColormapReq);
311
 
312
+    REQUEST_SIZE_MATCH(xXDGAInstallColormapReq);
313
+
314
     if (stuff->screen >= screenInfo.numScreens)
315
         return BadValue;
316
 
317
     if (DGA_GETCLIENT(stuff->screen) != client)
318
         return DGAErrorBase + XF86DGADirectNotActivated;
319
 
320
-    REQUEST_SIZE_MATCH(xXDGAInstallColormapReq);
321
-
322
     rc = dixLookupResourceByType((void **) &cmap, stuff->cmap, RT_COLORMAP,
323
                                  client, DixInstallAccess);
324
     if (rc != Success)
325
@@ -1575,14 +1578,14 @@ ProcXDGASelectInput(ClientPtr client)
326
 {
327
     REQUEST(xXDGASelectInputReq);
328
 
329
+    REQUEST_SIZE_MATCH(xXDGASelectInputReq);
330
+
331
     if (stuff->screen >= screenInfo.numScreens)
332
         return BadValue;
333
 
334
     if (DGA_GETCLIENT(stuff->screen) != client)
335
         return DGAErrorBase + XF86DGADirectNotActivated;
336
 
337
-    REQUEST_SIZE_MATCH(xXDGASelectInputReq);
338
-
339
     if (DGA_GETCLIENT(stuff->screen) == client)
340
         DGASelectInput(stuff->screen, client, stuff->mask);
341
 
342
@@ -1594,14 +1597,14 @@ ProcXDGAFillRectangle(ClientPtr client)
343
 {
344
     REQUEST(xXDGAFillRectangleReq);
345
 
346
+    REQUEST_SIZE_MATCH(xXDGAFillRectangleReq);
347
+
348
     if (stuff->screen >= screenInfo.numScreens)
349
         return BadValue;
350
 
351
     if (DGA_GETCLIENT(stuff->screen) != client)
352
         return DGAErrorBase + XF86DGADirectNotActivated;
353
 
354
-    REQUEST_SIZE_MATCH(xXDGAFillRectangleReq);
355
-
356
     if (Success != DGAFillRect(stuff->screen, stuff->x, stuff->y,
357
                                stuff->width, stuff->height, stuff->color))
358
         return BadMatch;
359
@@ -1614,14 +1617,14 @@ ProcXDGACopyArea(ClientPtr client)
360
 {
361
     REQUEST(xXDGACopyAreaReq);
362
 
363
+    REQUEST_SIZE_MATCH(xXDGACopyAreaReq);
364
+
365
     if (stuff->screen >= screenInfo.numScreens)
366
         return BadValue;
367
 
368
     if (DGA_GETCLIENT(stuff->screen) != client)
369
         return DGAErrorBase + XF86DGADirectNotActivated;
370
 
371
-    REQUEST_SIZE_MATCH(xXDGACopyAreaReq);
372
-
373
     if (Success != DGABlitRect(stuff->screen, stuff->srcx, stuff->srcy,
374
                                stuff->width, stuff->height, stuff->dstx,
375
                                stuff->dsty))
376
@@ -1635,14 +1638,14 @@ ProcXDGACopyTransparentArea(ClientPtr client)
377
 {
378
     REQUEST(xXDGACopyTransparentAreaReq);
379
 
380
+    REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq);
381
+
382
     if (stuff->screen >= screenInfo.numScreens)
383
         return BadValue;
384
 
385
     if (DGA_GETCLIENT(stuff->screen) != client)
386
         return DGAErrorBase + XF86DGADirectNotActivated;
387
 
388
-    REQUEST_SIZE_MATCH(xXDGACopyTransparentAreaReq);
389
-
390
     if (Success != DGABlitTransRect(stuff->screen, stuff->srcx, stuff->srcy,
391
                                     stuff->width, stuff->height, stuff->dstx,
392
                                     stuff->dsty, stuff->key))
393
@@ -1657,13 +1660,14 @@ ProcXDGAGetViewportStatus(ClientPtr client)
394
     REQUEST(xXDGAGetViewportStatusReq);
395
     xXDGAGetViewportStatusReply rep;
396
 
397
+    REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
398
+
399
     if (stuff->screen >= screenInfo.numScreens)
400
         return BadValue;
401
 
402
     if (DGA_GETCLIENT(stuff->screen) != client)
403
         return DGAErrorBase + XF86DGADirectNotActivated;
404
 
405
-    REQUEST_SIZE_MATCH(xXDGAGetViewportStatusReq);
406
     rep.type = X_Reply;
407
     rep.length = 0;
408
     rep.sequenceNumber = client->sequence;
409
@@ -1680,13 +1684,14 @@ ProcXDGASync(ClientPtr client)
410
     REQUEST(xXDGASyncReq);
411
     xXDGASyncReply rep;
412
 
413
+    REQUEST_SIZE_MATCH(xXDGASyncReq);
414
+
415
     if (stuff->screen >= screenInfo.numScreens)
416
         return BadValue;
417
 
418
     if (DGA_GETCLIENT(stuff->screen) != client)
419
         return DGAErrorBase + XF86DGADirectNotActivated;
420
 
421
-    REQUEST_SIZE_MATCH(xXDGASyncReq);
422
     rep.type = X_Reply;
423
     rep.length = 0;
424
     rep.sequenceNumber = client->sequence;
425
@@ -1725,13 +1730,14 @@ ProcXDGAChangePixmapMode(ClientPtr client)
426
     xXDGAChangePixmapModeReply rep;
427
     int x, y;
428
 
429
+    REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq);
430
+
431
     if (stuff->screen >= screenInfo.numScreens)
432
         return BadValue;
433
 
434
     if (DGA_GETCLIENT(stuff->screen) != client)
435
         return DGAErrorBase + XF86DGADirectNotActivated;
436
 
437
-    REQUEST_SIZE_MATCH(xXDGAChangePixmapModeReq);
438
     rep.type = X_Reply;
439
     rep.length = 0;
440
     rep.sequenceNumber = client->sequence;
441
@@ -1755,14 +1761,14 @@ ProcXDGACreateColormap(ClientPtr client)
442
     REQUEST(xXDGACreateColormapReq);
443
     int result;
444
 
445
+    REQUEST_SIZE_MATCH(xXDGACreateColormapReq);
446
+
447
     if (stuff->screen >= screenInfo.numScreens)
448
         return BadValue;
449
 
450
     if (DGA_GETCLIENT(stuff->screen) != client)
451
         return DGAErrorBase + XF86DGADirectNotActivated;
452
 
453
-    REQUEST_SIZE_MATCH(xXDGACreateColormapReq);
454
-
455
     if (!stuff->mode)
456
         return BadValue;
457
 
458
@@ -1791,10 +1797,11 @@ ProcXF86DGAGetVideoLL(ClientPtr client)
459
     int num, offset, flags;
460
     char *name;
461
 
462
+    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
463
+
464
     if (stuff->screen >= screenInfo.numScreens)
465
         return BadValue;
466
 
467
-    REQUEST_SIZE_MATCH(xXF86DGAGetVideoLLReq);
468
     rep.type = X_Reply;
469
     rep.length = 0;
470
     rep.sequenceNumber = client->sequence;
471
@@ -1831,9 +1838,10 @@ ProcXF86DGADirectVideo(ClientPtr client)
472
 
473
     REQUEST(xXF86DGADirectVideoReq);
474
 
475
+    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
476
+
477
     if (stuff->screen >= screenInfo.numScreens)
478
         return BadValue;
479
-    REQUEST_SIZE_MATCH(xXF86DGADirectVideoReq);
480
 
481
     if (!DGAAvailable(stuff->screen))
482
         return DGAErrorBase + XF86DGANoDirectVideoMode;
483
@@ -1889,10 +1897,11 @@ ProcXF86DGAGetViewPortSize(ClientPtr client)
484
     REQUEST(xXF86DGAGetViewPortSizeReq);
485
     xXF86DGAGetViewPortSizeReply rep;
486
 
487
+    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
488
+
489
     if (stuff->screen >= screenInfo.numScreens)
490
         return BadValue;
491
 
492
-    REQUEST_SIZE_MATCH(xXF86DGAGetViewPortSizeReq);
493
     rep.type = X_Reply;
494
     rep.length = 0;
495
     rep.sequenceNumber = client->sequence;
496
@@ -1917,14 +1926,14 @@ ProcXF86DGASetViewPort(ClientPtr client)
497
 {
498
     REQUEST(xXF86DGASetViewPortReq);
499
 
500
+    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
501
+
502
     if (stuff->screen >= screenInfo.numScreens)
503
         return BadValue;
504
 
505
     if (DGA_GETCLIENT(stuff->screen) != client)
506
         return DGAErrorBase + XF86DGADirectNotActivated;
507
 
508
-    REQUEST_SIZE_MATCH(xXF86DGASetViewPortReq);
509
-
510
     if (!DGAAvailable(stuff->screen))
511
         return DGAErrorBase + XF86DGANoDirectVideoMode;
512
 
513
@@ -1944,10 +1953,11 @@ ProcXF86DGAGetVidPage(ClientPtr client)
514
     REQUEST(xXF86DGAGetVidPageReq);
515
     xXF86DGAGetVidPageReply rep;
516
 
517
+    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
518
+
519
     if (stuff->screen >= screenInfo.numScreens)
520
         return BadValue;
521
 
522
-    REQUEST_SIZE_MATCH(xXF86DGAGetVidPageReq);
523
     rep.type = X_Reply;
524
     rep.length = 0;
525
     rep.sequenceNumber = client->sequence;
526
@@ -1962,11 +1972,11 @@ ProcXF86DGASetVidPage(ClientPtr client)
527
 {
528
     REQUEST(xXF86DGASetVidPageReq);
529
 
530
+    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
531
+
532
     if (stuff->screen >= screenInfo.numScreens)
533
         return BadValue;
534
 
535
-    REQUEST_SIZE_MATCH(xXF86DGASetVidPageReq);
536
-
537
     /* silently fail */
538
 
539
     return Success;
540
@@ -1980,14 +1990,14 @@ ProcXF86DGAInstallColormap(ClientPtr client)
541
 
542
     REQUEST(xXF86DGAInstallColormapReq);
543
 
544
+    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
545
+
546
     if (stuff->screen >= screenInfo.numScreens)
547
         return BadValue;
548
 
549
     if (DGA_GETCLIENT(stuff->screen) != client)
550
         return DGAErrorBase + XF86DGADirectNotActivated;
551
 
552
-    REQUEST_SIZE_MATCH(xXF86DGAInstallColormapReq);
553
-
554
     if (!DGAActive(stuff->screen))
555
         return DGAErrorBase + XF86DGADirectNotActivated;
556
 
557
@@ -2008,10 +2018,11 @@ ProcXF86DGAQueryDirectVideo(ClientPtr client)
558
     REQUEST(xXF86DGAQueryDirectVideoReq);
559
     xXF86DGAQueryDirectVideoReply rep;
560
 
561
+    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
562
+
563
     if (stuff->screen >= screenInfo.numScreens)
564
         return BadValue;
565
 
566
-    REQUEST_SIZE_MATCH(xXF86DGAQueryDirectVideoReq);
567
     rep.type = X_Reply;
568
     rep.length = 0;
569
     rep.sequenceNumber = client->sequence;
570
@@ -2030,14 +2041,14 @@ ProcXF86DGAViewPortChanged(ClientPtr client)
571
     REQUEST(xXF86DGAViewPortChangedReq);
572
     xXF86DGAViewPortChangedReply rep;
573
 
574
+    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
575
+
576
     if (stuff->screen >= screenInfo.numScreens)
577
         return BadValue;
578
 
579
     if (DGA_GETCLIENT(stuff->screen) != client)
580
         return DGAErrorBase + XF86DGADirectNotActivated;
581
 
582
-    REQUEST_SIZE_MATCH(xXF86DGAViewPortChangedReq);
583
-
584
     if (!DGAActive(stuff->screen))
585
         return DGAErrorBase + XF86DGADirectNotActivated;
586
 
587
diff --git a/hw/xfree86/dri/xf86dri.c b/hw/xfree86/dri/xf86dri.c
588
index 68f8b7e..65f368e 100644
589
--- hw/xfree86/dri/xf86dri.c
590
+++ hw/xfree86/dri/xf86dri.c
591
@@ -570,6 +570,7 @@ static int
592
 SProcXF86DRIQueryDirectRenderingCapable(register ClientPtr client)
593
 {
594
     REQUEST(xXF86DRIQueryDirectRenderingCapableReq);
595
+    REQUEST_SIZE_MATCH(xXF86DRIQueryDirectRenderingCapableReq);
596
     swaps(&stuff->length);
597
     swapl(&stuff->screen);
598
     return ProcXF86DRIQueryDirectRenderingCapable(client);
599
-- 
600
cgit v0.10.2
601
(-)x11-servers/xorg-server/files/patch-CVE-2017-1218y (-139 lines)
Lines 1-139 Link Here
1
From c206f36a4b6ecf2555ab2291c349ab7d7d0b02f5 Mon Sep 17 00:00:00 2001
2
From: Nathan Kidd <nkidd@opentext.com>
3
Date: Fri, 9 Jan 2015 09:57:23 -0500
4
Subject: Unvalidated lengths
5
6
v2: Add overflow check and remove unnecessary check (Julien Cristau)
7
8
This addresses:
9
CVE-2017-12184 in XINERAMA
10
CVE-2017-12185 in MIT-SCREEN-SAVER
11
CVE-2017-12186 in X-Resource
12
CVE-2017-12187 in RENDER
13
14
Reviewed-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
15
Reviewed-by: Julien Cristau <jcristau@debian.org>
16
Signed-off-by: Nathan Kidd <nkidd@opentext.com>
17
Signed-off-by: Julien Cristau <jcristau@debian.org>
18
(cherry picked from commit cad5a1050b7184d828aef9c1dd151c3ab649d37e)
19
20
diff --git a/Xext/panoramiX.c b/Xext/panoramiX.c
21
index 209df29..844ea49 100644
22
--- Xext/panoramiX.c
23
+++ Xext/panoramiX.c
24
@@ -988,10 +988,11 @@ ProcPanoramiXGetScreenSize(ClientPtr client)
25
     xPanoramiXGetScreenSizeReply rep;
26
     int rc;
27
 
28
+    REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
29
+
30
     if (stuff->screen >= PanoramiXNumScreens)
31
         return BadMatch;
32
 
33
-    REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
34
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
35
     if (rc != Success)
36
         return rc;
37
diff --git a/Xext/saver.c b/Xext/saver.c
38
index 750b8b9..45ac4d2 100644
39
--- Xext/saver.c
40
+++ Xext/saver.c
41
@@ -1185,6 +1185,8 @@ ProcScreenSaverUnsetAttributes(ClientPtr client)
42
         PanoramiXRes *draw;
43
         int rc, i;
44
 
45
+        REQUEST_SIZE_MATCH(xScreenSaverUnsetAttributesReq);
46
+
47
         rc = dixLookupResourceByClass((void **) &draw, stuff->drawable,
48
                                       XRC_DRAWABLE, client, DixWriteAccess);
49
         if (rc != Success)
50
diff --git a/Xext/xres.c b/Xext/xres.c
51
index ae779df..bc54133 100644
52
--- Xext/xres.c
53
+++ Xext/xres.c
54
@@ -947,6 +947,8 @@ ProcXResQueryResourceBytes (ClientPtr client)
55
     ConstructResourceBytesCtx    ctx;
56
 
57
     REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq);
58
+    if (stuff->numSpecs > UINT32_MAX / sizeof(ctx.specs[0]))
59
+        return BadLength;
60
     REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,
61
                        stuff->numSpecs * sizeof(ctx.specs[0]));
62
 
63
@@ -1052,8 +1054,8 @@ SProcXResQueryResourceBytes (ClientPtr client)
64
     int c;
65
     xXResResourceIdSpec *specs = (void*) ((char*) stuff + sizeof(*stuff));
66
 
67
-    swapl(&stuff->numSpecs);
68
     REQUEST_AT_LEAST_SIZE(xXResQueryResourceBytesReq);
69
+    swapl(&stuff->numSpecs);
70
     REQUEST_FIXED_SIZE(xXResQueryResourceBytesReq,
71
                        stuff->numSpecs * sizeof(specs[0]));
72
 
73
diff --git a/Xext/xvdisp.c b/Xext/xvdisp.c
74
index 8a35b7b..4d412b8 100644
75
--- Xext/xvdisp.c
76
+++ Xext/xvdisp.c
77
@@ -1493,12 +1493,14 @@ XineramaXvShmPutImage(ClientPtr client)
78
 {
79
     REQUEST(xvShmPutImageReq);
80
     PanoramiXRes *draw, *gc, *port;
81
-    Bool send_event = stuff->send_event;
82
+    Bool send_event;
83
     Bool isRoot;
84
     int result, i, x, y;
85
 
86
     REQUEST_SIZE_MATCH(xvShmPutImageReq);
87
 
88
+    send_event = stuff->send_event;
89
+
90
     result = dixLookupResourceByClass((void **) &draw, stuff->drawable,
91
                                       XRC_DRAWABLE, client, DixWriteAccess);
92
     if (result != Success)
93
diff --git a/hw/dmx/dmxpict.c b/hw/dmx/dmxpict.c
94
index 1f1022e..63caec9 100644
95
--- hw/dmx/dmxpict.c
96
+++ hw/dmx/dmxpict.c
97
@@ -716,6 +716,8 @@ dmxProcRenderSetPictureFilter(ClientPtr client)
98
         filter = (char *) (stuff + 1);
99
         params = (XFixed *) (filter + ((stuff->nbytes + 3) & ~3));
100
         nparams = ((XFixed *) stuff + client->req_len) - params;
101
+        if (nparams < 0)
102
+            return BadLength;
103
 
104
         XRenderSetPictureFilter(dmxScreen->beDisplay,
105
                                 pPictPriv->pict, filter, params, nparams);
106
diff --git a/pseudoramiX/pseudoramiX.c b/pseudoramiX/pseudoramiX.c
107
index d8b2593..95f6e10 100644
108
--- pseudoramiX/pseudoramiX.c
109
+++ pseudoramiX/pseudoramiX.c
110
@@ -297,10 +297,11 @@ ProcPseudoramiXGetScreenSize(ClientPtr client)
111
 
112
     TRACE;
113
 
114
+    REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
115
+
116
     if (stuff->screen >= pseudoramiXNumScreens)
117
       return BadMatch;
118
 
119
-    REQUEST_SIZE_MATCH(xPanoramiXGetScreenSizeReq);
120
     rc = dixLookupWindow(&pWin, stuff->window, client, DixGetAttrAccess);
121
     if (rc != Success)
122
         return rc;
123
diff --git a/render/render.c b/render/render.c
124
index bfacaa0..3a41e33 100644
125
--- render/render.c
126
+++ render/render.c
127
@@ -1757,6 +1757,9 @@ ProcRenderSetPictureFilter(ClientPtr client)
128
     name = (char *) (stuff + 1);
129
     params = (xFixed *) (name + pad_to_int32(stuff->nbytes));
130
     nparams = ((xFixed *) stuff + client->req_len) - params;
131
+    if (nparams < 0)
132
+	return BadLength;
133
+
134
     result = SetPictureFilter(pPicture, name, stuff->nbytes, params, nparams);
135
     return result;
136
 }
137
-- 
138
cgit v0.10.2
139
(-)x11-servers/xorg-server/files/patch-CVE-2017-13721 (-26 lines)
Lines 1-26 Link Here
1
From b95f25af141d33a65f6f821ea9c003f66a01e1f1 Mon Sep 17 00:00:00 2001
2
From: Michal Srb <msrb@suse.com>
3
Date: Fri, 28 Jul 2017 16:27:10 +0200
4
Subject: Xext/shm: Validate shmseg resource id (CVE-2017-13721)
5
6
Otherwise it can belong to a non-existing client and abort X server with
7
FatalError "client not in use", or overwrite existing segment of another
8
existing client.
9
10
Signed-off-by: Julien Cristau <jcristau@debian.org>
11
12
diff --git a/Xext/shm.c b/Xext/shm.c
13
index 91ea90b..2f9a788 100644
14
--- Xext/shm.c
15
+++ Xext/shm.c
16
@@ -1238,6 +1238,7 @@ ProcShmCreateSegment(ClientPtr client)
17
     };
18
 
19
     REQUEST_SIZE_MATCH(xShmCreateSegmentReq);
20
+    LEGAL_NEW_RESOURCE(stuff->shmseg, client);
21
     if ((stuff->readOnly != xTrue) && (stuff->readOnly != xFalse)) {
22
         client->errorValue = stuff->readOnly;
23
         return BadValue;
24
-- 
25
cgit v0.10.2
26
(-)x11-servers/xorg-server/files/patch-CVE-2017-13723 (-115 lines)
Lines 1-115 Link Here
1
From 94f11ca5cf011ef123bd222cabeaef6f424d76ac Mon Sep 17 00:00:00 2001
2
From: Keith Packard <keithp@keithp.com>
3
Date: Thu, 27 Jul 2017 10:08:32 -0700
4
Subject: xkb: Handle xkb formated string output safely (CVE-2017-13723)
5
6
Generating strings for XKB data used a single shared static buffer,
7
which offered several opportunities for errors. Use a ring of
8
resizable buffers instead, to avoid problems when strings end up
9
longer than anticipated.
10
11
Reviewed-by: Michal Srb <msrb@suse.com>
12
Signed-off-by: Keith Packard <keithp@keithp.com>
13
Signed-off-by: Julien Cristau <jcristau@debian.org>
14
15
diff --git a/xkb/xkbtext.c b/xkb/xkbtext.c
16
index ead2b1a..d2a2567 100644
17
--- xkb/xkbtext.c
18
+++ xkb/xkbtext.c
19
@@ -47,23 +47,27 @@
20
 
21
 /***====================================================================***/
22
 
23
-#define	BUFFER_SIZE	512
24
-
25
-static char textBuffer[BUFFER_SIZE];
26
-static int tbNext = 0;
27
+#define NUM_BUFFER      8
28
+static struct textBuffer {
29
+    int size;
30
+    char *buffer;
31
+} textBuffer[NUM_BUFFER];
32
+static int textBufferIndex;
33
 
34
 static char *
35
 tbGetBuffer(unsigned size)
36
 {
37
-    char *rtrn;
38
+    struct textBuffer *tb;
39
 
40
-    if (size >= BUFFER_SIZE)
41
-        return NULL;
42
-    if ((BUFFER_SIZE - tbNext) <= size)
43
-        tbNext = 0;
44
-    rtrn = &textBuffer[tbNext];
45
-    tbNext += size;
46
-    return rtrn;
47
+    tb = &textBuffer[textBufferIndex];
48
+    textBufferIndex = (textBufferIndex + 1) % NUM_BUFFER;
49
+
50
+    if (size > tb->size) {
51
+        free(tb->buffer);
52
+        tb->buffer = xnfalloc(size);
53
+        tb->size = size;
54
+    }
55
+    return tb->buffer;
56
 }
57
 
58
 /***====================================================================***/
59
@@ -79,8 +83,6 @@ XkbAtomText(Atom atm, unsigned format)
60
         int len;
61
 
62
         len = strlen(atmstr) + 1;
63
-        if (len > BUFFER_SIZE)
64
-            len = BUFFER_SIZE - 2;
65
         rtrn = tbGetBuffer(len);
66
         strlcpy(rtrn, atmstr, len);
67
     }
68
@@ -128,8 +130,6 @@ XkbVModIndexText(XkbDescPtr xkb, unsigned ndx, unsigned format)
69
     len = strlen(tmp) + 1;
70
     if (format == XkbCFile)
71
         len += 4;
72
-    if (len >= BUFFER_SIZE)
73
-        len = BUFFER_SIZE - 1;
74
     rtrn = tbGetBuffer(len);
75
     if (format == XkbCFile) {
76
         strcpy(rtrn, "vmod_");
77
@@ -140,6 +140,8 @@ XkbVModIndexText(XkbDescPtr xkb, unsigned ndx, unsigned format)
78
     return rtrn;
79
 }
80
 
81
+#define VMOD_BUFFER_SIZE        512
82
+
83
 char *
84
 XkbVModMaskText(XkbDescPtr xkb,
85
                 unsigned modMask, unsigned mask, unsigned format)
86
@@ -147,7 +149,7 @@ XkbVModMaskText(XkbDescPtr xkb,
87
     register int i, bit;
88
     int len;
89
     char *mm, *rtrn;
90
-    char *str, buf[BUFFER_SIZE];
91
+    char *str, buf[VMOD_BUFFER_SIZE];
92
 
93
     if ((modMask == 0) && (mask == 0)) {
94
         rtrn = tbGetBuffer(5);
95
@@ -173,7 +175,7 @@ XkbVModMaskText(XkbDescPtr xkb,
96
                 len = strlen(tmp) + 1 + (str == buf ? 0 : 1);
97
                 if (format == XkbCFile)
98
                     len += 4;
99
-                if ((str - (buf + len)) <= BUFFER_SIZE) {
100
+                if ((str - (buf + len)) <= VMOD_BUFFER_SIZE) {
101
                     if (str != buf) {
102
                         if (format == XkbCFile)
103
                             *str++ = '|';
104
@@ -199,8 +201,6 @@ XkbVModMaskText(XkbDescPtr xkb,
105
         len = 0;
106
     if (str)
107
         len += strlen(str) + (mm == NULL ? 0 : 1);
108
-    if (len >= BUFFER_SIZE)
109
-        len = BUFFER_SIZE - 1;
110
     rtrn = tbGetBuffer(len + 1);
111
     rtrn[0] = '\0';
112
 
113
-- 
114
cgit v0.10.2
115
(-)x11-servers/xorg-server/files/patch-config_Makefile.in (+91 lines)
Line 0 Link Here
1
* generated from patched Makefile.am; revise and regen instead of editing
2
*
3
* Build the devd config backend if activated
4
*
5
--- config/Makefile.in.orig	2017-03-16 05:24:43 UTC
6
+++ config/Makefile.in
7
@@ -89,16 +89,18 @@ PRE_UNINSTALL = :
8
 POST_UNINSTALL = :
9
 build_triplet = @build@
10
 host_triplet = @host@
11
-@NEED_DBUS_TRUE@am__append_1 = $(DBUS_CFLAGS)
12
-@NEED_DBUS_TRUE@am__append_2 = dbus-core.c
13
-@NEED_DBUS_TRUE@am__append_3 = $(DBUS_LIBS)
14
-@CONFIG_UDEV_TRUE@am__append_4 = $(UDEV_CFLAGS)
15
-@CONFIG_UDEV_TRUE@am__append_5 = udev.c
16
-@CONFIG_UDEV_TRUE@am__append_6 = $(UDEV_LIBS)
17
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_7 = $(HAL_CFLAGS)
18
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_8 = hal.c
19
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_9 = $(HAL_LIBS)
20
-@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__append_10 = wscons.c
21
+@CONFIG_DEVD_TRUE@am__append_1 = devd.c
22
+@CONFIG_DEVD_TRUE@am__append_2 = -lusbhid
23
+@NEED_DBUS_TRUE@am__append_3 = $(DBUS_CFLAGS)
24
+@NEED_DBUS_TRUE@am__append_4 = dbus-core.c
25
+@NEED_DBUS_TRUE@am__append_5 = $(DBUS_LIBS)
26
+@CONFIG_UDEV_TRUE@am__append_6 = $(UDEV_CFLAGS)
27
+@CONFIG_UDEV_TRUE@am__append_7 = udev.c
28
+@CONFIG_UDEV_TRUE@am__append_8 = $(UDEV_LIBS)
29
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_9 = $(HAL_CFLAGS)
30
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_10 = hal.c
31
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__append_11 = $(HAL_LIBS)
32
+@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__append_12 = wscons.c
33
 subdir = config
34
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
35
 am__aclocal_m4_deps = $(top_srcdir)/m4/ac_define_dir.m4 \
36
@@ -126,16 +128,18 @@ am__DEPENDENCIES_1 =
37
 @CONFIG_UDEV_TRUE@am__DEPENDENCIES_3 = $(am__DEPENDENCIES_1)
38
 @CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__DEPENDENCIES_4 =  \
39
 @CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@	$(am__DEPENDENCIES_1)
40
-libconfig_la_DEPENDENCIES = $(am__DEPENDENCIES_2) \
41
-	$(am__DEPENDENCIES_3) $(am__DEPENDENCIES_4)
42
-am__libconfig_la_SOURCES_DIST = config.c config-backends.h dbus-core.c \
43
-	udev.c hal.c wscons.c
44
-@NEED_DBUS_TRUE@am__objects_1 = dbus-core.lo
45
-@CONFIG_UDEV_TRUE@am__objects_2 = udev.lo
46
-@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__objects_3 = hal.lo
47
-@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__objects_4 = wscons.lo
48
+libconfig_la_DEPENDENCIES = $(am__DEPENDENCIES_1) \
49
+	$(am__DEPENDENCIES_2) $(am__DEPENDENCIES_3) \
50
+	$(am__DEPENDENCIES_4)
51
+am__libconfig_la_SOURCES_DIST = config.c config-backends.h devd.c \
52
+	dbus-core.c udev.c hal.c wscons.c
53
+@CONFIG_DEVD_TRUE@am__objects_1 = devd.lo
54
+@NEED_DBUS_TRUE@am__objects_2 = dbus-core.lo
55
+@CONFIG_UDEV_TRUE@am__objects_3 = udev.lo
56
+@CONFIG_HAL_TRUE@@CONFIG_UDEV_FALSE@am__objects_4 = hal.lo
57
+@CONFIG_HAL_FALSE@@CONFIG_UDEV_FALSE@@CONFIG_WSCONS_TRUE@am__objects_5 = wscons.lo
58
 am_libconfig_la_OBJECTS = config.lo $(am__objects_1) $(am__objects_2) \
59
-	$(am__objects_3) $(am__objects_4)
60
+	$(am__objects_3) $(am__objects_4) $(am__objects_5)
61
 libconfig_la_OBJECTS = $(am_libconfig_la_OBJECTS)
62
 AM_V_lt = $(am__v_lt_@AM_V@)
63
 am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
64
@@ -586,12 +590,14 @@ target_alias = @target_alias@
65
 top_build_prefix = @top_build_prefix@
66
 top_builddir = @top_builddir@
67
 top_srcdir = @top_srcdir@
68
-AM_CFLAGS = $(DIX_CFLAGS) $(am__append_1) $(am__append_4) \
69
-	$(am__append_7)
70
+AM_CFLAGS = $(DIX_CFLAGS) $(am__append_3) $(am__append_6) \
71
+	$(am__append_9)
72
 noinst_LTLIBRARIES = libconfig.la
73
-libconfig_la_SOURCES = config.c config-backends.h $(am__append_2) \
74
-	$(am__append_5) $(am__append_8) $(am__append_10)
75
-libconfig_la_LIBADD = $(am__append_3) $(am__append_6) $(am__append_9)
76
+libconfig_la_SOURCES = config.c config-backends.h $(am__append_1) \
77
+	$(am__append_4) $(am__append_7) $(am__append_10) \
78
+	$(am__append_12)
79
+libconfig_la_LIBADD = $(am__append_2) $(am__append_5) $(am__append_8) \
80
+	$(am__append_11)
81
 @CONFIG_UDEV_TRUE@@XORG_TRUE@xorgconfddir = $(datadir)/X11/$(XF86CONFIGDIR)
82
 @CONFIG_UDEV_TRUE@@XORG_TRUE@xorgconfd_DATA = 10-quirks.conf
83
 EXTRA_DIST = x11-input.fdi fdi2iclass.py 10-quirks.conf
84
@@ -651,6 +657,7 @@ distclean-compile:
85
 
86
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/config.Plo@am__quote@
87
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dbus-core.Plo@am__quote@
88
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/devd.Plo@am__quote@
89
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hal.Plo@am__quote@
90
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/udev.Plo@am__quote@
91
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/wscons.Plo@am__quote@
(-)x11-servers/xorg-server/files/patch-config_config-backends.h (-6 / +7 lines)
Lines 1-11 Link Here
1
--- config/config-backends.h.orig	2016-07-15 16:17:45 UTC
1
* Define required functions for devd config backend
2
*
3
--- config/config-backends.h.orig	2017-03-15 18:05:25 UTC
2
+++ config/config-backends.h
4
+++ config/config-backends.h
3
@@ -44,3 +44,8 @@ void config_hal_fini(void);
5
@@ -43,4 +43,7 @@ void config_hal_fini(void);
6
 #elif defined(CONFIG_WSCONS)
4
 int config_wscons_init(void);
7
 int config_wscons_init(void);
5
 void config_wscons_fini(void);
8
 void config_wscons_fini(void);
6
 #endif
9
+#elif defined(CONFIG_DEVD)
7
+
8
+#ifdef CONFIG_DEVD
9
+int config_devd_init(void);
10
+int config_devd_init(void);
10
+void config_devd_fini(void);
11
+void config_devd_fini(void);
11
+#endif
12
 #endif
(-)x11-servers/xorg-server/files/patch-config_config.c (-1 / +3 lines)
Lines 1-4 Link Here
1
--- config/config.c.orig	2016-07-19 17:07:29 UTC
1
* Call the devd config backend functions if activated
2
*
3
--- config/config.c.orig	2017-03-15 18:05:25 UTC
2
+++ config/config.c
4
+++ config/config.c
3
@@ -55,6 +55,9 @@ config_init(void)
5
@@ -55,6 +55,9 @@ config_init(void)
4
 #elif defined(CONFIG_WSCONS)
6
 #elif defined(CONFIG_WSCONS)
(-)x11-servers/xorg-server/files/patch-config_devd.c (-348 / +708 lines)
Lines 1-11 Link Here
1
--- config/devd.c.orig	2017-01-19 15:20:42 UTC
1
--- config/devd.c.orig	2017-03-16 05:24:43 UTC
2
+++ config/devd.c
2
+++ config/devd.c
3
@@ -0,0 +1,532 @@
3
@@ -0,0 +1,892 @@
4
+/*
4
+/*
5
+ * Copyright (c) 2012 Baptiste Daroussin
5
+ * Copyright (c) 2012 Baptiste Daroussin
6
+ * Copyright (c) 2013, 2014 Alex Kozlov
6
+ * Copyright (c) 2013, 2014 Alex Kozlov
7
+ * Copyright (c) 2014 Robert Millan
7
+ * Copyright (c) 2014 Robert Millan
8
+ * Copyright (c) 2014 Jean-Sebastien Pedron
8
+ * Copyright (c) 2014 Jean-Sebastien Pedron
9
+ * Copyright (c) 2015 Hans Petter Selasky
10
+ * Copyright (c) 2015-2017 Rozhuk Ivan
11
+ * Copyright (c) 2016, 2017 Vladimir Kondratyev
12
+ * Copyright (c) 2017 Matthew Rezny
9
+ *
13
+ *
10
+ * Permission is hereby granted, free of charge, to any person obtaining a
14
+ * Permission is hereby granted, free of charge, to any person obtaining a
11
+ * copy of this software and associated documentation files (the "Software"),
15
+ * copy of this software and associated documentation files (the "Software"),
Lines 39-46 Link Here
39
+#include <sys/stat.h>
43
+#include <sys/stat.h>
40
+#include <sys/sysctl.h>
44
+#include <sys/sysctl.h>
41
+#include <sys/un.h>
45
+#include <sys/un.h>
46
+#include <sys/mouse.h>
47
+#include <sys/consio.h>
48
+#include <sys/ioctl.h>
49
+#include <dev/usb/usb_ioctl.h>
50
+#include <dev/usb/usbhid.h>
42
+
51
+
43
+#include <ctype.h>
52
+#include <ctype.h>
53
+#include <dirent.h>
44
+#include <errno.h>
54
+#include <errno.h>
45
+#include <fcntl.h>
55
+#include <fcntl.h>
46
+#include <stdlib.h>
56
+#include <stdlib.h>
Lines 47-52 Link Here
47
+#include <stdio.h>
57
+#include <stdio.h>
48
+#include <stdbool.h>
58
+#include <stdbool.h>
49
+#include <unistd.h>
59
+#include <unistd.h>
60
+#include <string.h>
61
+#include <paths.h>
62
+#include <usbhid.h>
50
+
63
+
51
+#include "input.h"
64
+#include "input.h"
52
+#include "inputstr.h"
65
+#include "inputstr.h"
Lines 54-520 Link Here
54
+#include "config-backends.h"
67
+#include "config-backends.h"
55
+#include "os.h"
68
+#include "os.h"
56
+
69
+
57
+#define DEVD_SOCK_PATH "/var/run/devd.pipe"
70
+/* from: <linux/input.h> */
71
+#define	_IOC_READ   IOC_OUT
72
+struct input_id {
73
+	uint16_t bustype;
74
+	uint16_t vendor;
75
+	uint16_t product;
76
+	uint16_t version;
77
+};
58
+
78
+
79
+#define	EVIOCGBIT(ev, len)	_IOC(_IOC_READ, 'E', 0x20 + (ev), (len))
80
+#define	EVIOCGID		_IOR('E', 0x02, struct input_id)
81
+#define	EVIOCGNAME(len)		_IOC(_IOC_READ, 'E', 0x06, (len))
82
+#define	EVIOCGPHYS(len)		_IOC(_IOC_READ, 'E', 0x07, (len))
83
+
84
+#define	EV_KEY			0x01
85
+#define	EV_REL			0x02
86
+#define	EV_ABS			0x03
87
+#define	BTN_MISC		0x100
88
+#define	BTN_LEFT		0x110
89
+#define	BTN_RIGHT		0x111
90
+#define	BTN_MIDDLE		0x112
91
+#define	BTN_JOYSTICK		0x120
92
+#define	BTN_TOOL_PEN		0x140
93
+#define	BTN_TOOL_FINGER		0x145
94
+#define	BTN_TOUCH		0x14a
95
+#define	BTN_STYLUS		0x14b
96
+#define	BTN_STYLUS2		0x14c
97
+#define	KEY_MAX			0x2ff
98
+#define	KEY_CNT			(KEY_MAX + 1)
99
+#define	REL_X			0x00
100
+#define	REL_Y			0x01
101
+#define	REL_MAX			0x0f
102
+#define	REL_CNT			(REL_MAX + 1)
103
+#define	ABS_X			0x00
104
+#define	ABS_Y			0x01
105
+#define	ABS_PRESSURE		0x18
106
+#define	ABS_MT_SLOT		0x2f
107
+#define	ABS_MAX			0x3f
108
+#define	ABS_CNT			(ABS_MAX + 1)
109
+
110
+#define	ULONG_BITS		(sizeof(unsigned long) * 8)
111
+#define	ULONG_CNT(__x)		(((__x) + ULONG_BITS - 1) / ULONG_BITS)
112
+#define ULONG_IS_BIT_SET(__x, __bit) (((const unsigned long*)(__x))[(__bit) / ULONG_BITS] & (1UL << (__bit % ULONG_BITS)))
113
+
114
+/* from: <linux/joystick.h> */
115
+#define JSIOCGNAME(len)		_IOC(_IOC_READ, 'j', 0x13, len)		/* get identifier string */
116
+
117
+/* WebCamD specific. */
118
+#define WEBCAMD_IOCTL_GET_USB_VENDOR_ID _IOR('q', 250, unsigned short)
119
+#define WEBCAMD_IOCTL_GET_USB_PRODUCT_ID _IOR('q', 251, unsigned short)
120
+#define WEBCAMD_IOCTL_GET_USB_SPEED	_IOR('q', 252, unsigned int)
121
+
122
+#ifdef COMPAT_32BIT
123
+	#define hid_pass_ptr(ptr)	((uint64_t)(uintptr_t)(ptr))
124
+#else
125
+	#define hid_pass_ptr(ptr)	(ptr)
126
+#endif
127
+
128
+#define _PATH_DEV_LEN		(sizeof(_PATH_DEV) - 1)
129
+#define DEVD_PATH_DEV		"devd:" _PATH_DEV
130
+#define DEVD_PATH_DEV_LEN	(sizeof(DEVD_PATH_DEV) - 1)
131
+#define DEVD_PATH_LEN		(DEVD_PATH_DEV_LEN - _PATH_DEV_LEN)
132
+
133
+#define DEVD_SOCK_PATH		_PATH_VARRUN "devd.pipe"
134
+
59
+#define DEVD_EVENT_ADD		'+'
135
+#define DEVD_EVENT_ADD		'+'
60
+#define DEVD_EVENT_REMOVE	'-'
136
+#define DEVD_EVENT_REMOVE	'-'
137
+#define DEVD_EVENT_NOTIFY	'!'
61
+
138
+
62
+#define RECONNECT_DELAY		5 * 1000
139
+#define RECONNECT_DELAY	(5 * 1000)
63
+
140
+
64
+static int sock_devd;
141
+#define is_meuqual(__v1, __v1sz, __v2, __v2sz)				\
65
+static bool is_console_kbd = false;
142
+	((__v1sz) == (__v2sz) && NULL != (__v1) && NULL != (__v2) &&	\
66
+static bool is_kbdmux = false;
143
+	 0 == memcmp((__v1), (__v2), (__v1sz)))
144
+
145
+#define is_meuqual_cstr(__cstr, __v, __vsz)				\
146
+	is_meuqual(__cstr, (sizeof(__cstr) - 1), __v, __vsz)
147
+
148
+#define is_de_euqual_cstr(__de, __cstr)					\
149
+	(NULL != (__de) &&						\
150
+	 is_meuqual((__de)->d_name, (__de)->d_namlen, __cstr, (sizeof(__cstr) - 1)))
151
+
152
+#define devd_get_val_cstr(__cstr, __buf, __bufsz, __valsz)		\
153
+	devd_get_val((__buf), (__bufsz), __cstr, (sizeof(__cstr) - 1),	\
154
+	(__valsz))
155
+
156
+static int devd_skt = 0;
157
+static char devd_buf[4096];
158
+static size_t devd_buf_used = 0;
159
+static int is_kbdmux = 0;
160
+static int evdev_support = 0;
67
+static OsTimerPtr rtimer = NULL;
161
+static OsTimerPtr rtimer = NULL;
68
+
162
+
69
+struct hw_type {
163
+/* Input devices. */
70
+	const char *driver;
164
+typedef struct hw_type_s {
71
+	int flag;
165
+	const char	*dev_name;
72
+	const char *xdriver;
166
+	size_t		dev_name_size;
167
+	size_t		path_offset;
168
+	int		is_hybrid; /* has both evdev and traditional interfaces */
169
+	int		flags;
170
+	const char	*xdriver; 
171
+} hw_type_t, *hw_type_p;
172
+
173
+/* xdriver can be set via config "InputClass" section.
174
+ * Do not set xdriver name if device have more than one
175
+ * xf86-input-* drivers.
176
+ * "input/event" can be hadled by: xf86-input-libinput,
177
+ * xf86-input-evdev and xf86-input-wacom, let user choose.
178
+ */
179
+static hw_type_t hw_types[] = {
180
+	{ "uhid",	4, 0, 0, 0, NULL },
181
+	{ "ukbd",	4, 0, 1, ATTR_KEY | ATTR_KEYBOARD, "kbd" },
182
+	{ "atkbd",	5, 0, 1, ATTR_KEY | ATTR_KEYBOARD, "kbd" },
183
+	{ "kbdmux",	6, 0, 1, ATTR_KEY | ATTR_KEYBOARD, "kbd" },
184
+	{ "sysmouse",	8, 0, 1, ATTR_POINTER, "mouse" },
185
+	{ "ums",	3, 0, 1, ATTR_POINTER, "mouse" },
186
+	{ "psm",	3, 0, 1, ATTR_POINTER, "mouse" },
187
+	{ "vboxguest",	9, 0, 0, ATTR_POINTER, "vboxmouse" },
188
+	{ "joy",	3, 0, 0, ATTR_JOYSTICK, NULL },
189
+	{ "atp",	3, 0, 0, ATTR_TOUCHPAD, NULL },
190
+	{ "uep",	3, 0, 0, ATTR_TOUCHSCREEN, NULL },
191
+	{ "input/event",5, 6, 0, 0, NULL },
192
+	{ "input/js",	2, 6, 0, ATTR_JOYSTICK, NULL },
193
+	{ NULL,		0, 0, 0, NULL },
73
+};
194
+};
74
+
195
+
75
+static struct hw_type hw_types[] = {
196
+/* Input devices paths. */
76
+	{ "ukbd", ATTR_KEYBOARD, "kbd" },
197
+static hw_type_t hw_type_path[] = {
77
+	{ "atkbd", ATTR_KEYBOARD, "kbd" },
198
+	{ "input/",	0, 6, 0, NULL },
78
+	{ "kbdmux", ATTR_KEYBOARD, "kbd" },
199
+	{ NULL,		0, 0, 0, NULL },
79
+	{ "sysmouse", ATTR_POINTER, "mouse" },
80
+	{ "ums", ATTR_POINTER, "mouse" },
81
+	{ "psm", ATTR_POINTER, "mouse" },
82
+	{ "vboxguest", ATTR_POINTER, "vboxmouse" },
83
+	{ "joy", ATTR_JOYSTICK, NULL },
84
+	{ "atp", ATTR_TOUCHPAD, NULL },
85
+	{ "uep", ATTR_TOUCHSCREEN, NULL },
86
+	{ NULL, -1, NULL },
87
+};
200
+};
88
+
201
+
89
+static bool
202
+static size_t
90
+sysctl_exists(const struct hw_type *device, int unit,
203
+bits_calc(const unsigned long *bits, size_t off_start, size_t off_stop)
91
+	char *devname, size_t devname_len)
92
+{
204
+{
93
+	char sysctlname[PATH_MAX];
205
+	size_t count = 0;
94
+	size_t len;
95
+	int ret;
96
+
206
+
97
+	if (device == NULL || device->driver == NULL)
207
+	for (size_t i = off_start; i < off_stop; ++i) {
98
+		return false;
208
+		if (ULONG_IS_BIT_SET(bits, i)) {
209
+			++count;
210
+		}
211
+	}
212
+	return count;
213
+}
99
+
214
+
100
+	/* Check if a sysctl exists. */
215
+static hw_type_p
101
+	snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%i.%%desc",
216
+get_dev_type_by_name(const char *dev_name, size_t dev_name_size)
102
+	    device->driver, unit);
217
+{
103
+	ret = sysctlbyname(sysctlname, NULL, &len, NULL, 0);
218
+	if (!dev_name || !dev_name_size)
219
+		return NULL;
104
+
220
+
105
+	if (ret == 0 && len > 0) {
221
+	for (size_t i = 0; hw_types[i].dev_name; ++i) {
106
+		snprintf(devname, devname_len, "%s%i", device->driver, unit);
222
+		if (dev_name_size >= (hw_types[i].dev_name_size + hw_types[i].path_offset) &&
107
+		return true;
223
+		    !memcmp(dev_name, hw_types[i].dev_name, (hw_types[i].path_offset + hw_types[i].dev_name_size))) {
224
+			return &hw_types[i];
225
+		}
108
+	}
226
+	}
227
+	return NULL;
228
+}
109
+
229
+
110
+	return false;
230
+static hw_type_p
231
+get_dev_type_by_path(const char *dev_name, size_t dev_name_size, hw_type_p hw_type_cust)
232
+{
233
+	if (!dev_name || !dev_name_size || !hw_type_cust)
234
+		return NULL;
235
+
236
+	for (size_t i = 0; hw_type_path[i].dev_name; ++i) {
237
+		if (dev_name_size <= hw_type_path[i].path_offset ||
238
+		    memcmp(dev_name, hw_type_path[i].dev_name, hw_type_path[i].path_offset))
239
+			continue;
240
+		/* Path in white list. */
241
+		hw_type_cust->dev_name = dev_name;
242
+		hw_type_cust->flags = hw_type_path[i].flags;
243
+		hw_type_cust->xdriver = hw_type_path[i].xdriver;
244
+		hw_type_cust->path_offset = hw_type_path[i].path_offset;
245
+		size_t name_end = hw_type_cust->path_offset;
246
+		while (name_end < dev_name_size && !isdigit(dev_name[name_end]))
247
+			++name_end;
248
+		hw_type_cust->dev_name_size = (name_end - hw_type_cust->path_offset);
249
+		return hw_type_cust;
250
+	}
251
+	return NULL;
111
+}
252
+}
112
+
253
+
113
+static bool
254
+static int
114
+devpath_exists(const struct hw_type *device,
255
+is_kbdmux_enabled(void)
115
+	char *devname, size_t devname_len)
116
+{
256
+{
117
+	char *devpath;
257
+	/* Xorg uses /dev/ttyv0 as a console device */
118
+	struct stat st;
258
+	/* const char device[]="/dev/console"; */
119
+	int ret;
259
+	static const char *device = _PATH_TTY "v0";
120
+
260
+
121
+	if (device == NULL || device->driver == NULL)
261
+	int fd = open(device, O_RDONLY);
122
+		return false;
262
+	if (fd < 0)
263
+		return 0;
123
+
264
+
124
+	/* Check if /dev/$driver exists. */
265
+	keyboard_info_t info;
125
+	asprintf(&devpath, "/dev/%s", device->driver);
266
+	int ret = (ioctl(fd, KDGKBINFO, &info) == -1 ||
126
+	if (devpath == NULL)
267
+	           memcmp(info.kb_name, "kbdmux", 6)) ? 0 : 1;
127
+		return false;
268
+	close(fd);
269
+	return ret;
270
+}
128
+
271
+
129
+	ret = stat(devpath, &st);
272
+/* Derived from EvdevProbe() function of xf86-input-evdev driver */
130
+	free(devpath);
273
+static int
274
+get_evdev_flags(int fd)
275
+{
276
+	if (fd<0)
277
+		return 0;
131
+
278
+
132
+	if (ret == 0) {
279
+	unsigned long key_bits[ULONG_CNT(KEY_CNT)], rel_bits[ULONG_CNT(REL_CNT)], abs_bits[ULONG_CNT(ABS_CNT)];
133
+		strncpy(devname, device->driver, devname_len);
280
+	size_t has_keys = 0, has_buttons = 0, has_lmr = 0, has_rel_axes = 0, has_abs_axes = 0, has_mt = 0;
134
+		return true;
281
+	if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bits)), key_bits) != -1) {
282
+		has_keys = bits_calc(key_bits, 0, BTN_MISC);
283
+		has_buttons = bits_calc(key_bits, BTN_MISC, BTN_JOYSTICK);
284
+		has_lmr = bits_calc(key_bits, BTN_LEFT, BTN_MIDDLE + 1);
135
+	}
285
+	}
286
+	if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof(rel_bits)), rel_bits) != -1) {
287
+		has_rel_axes = bits_calc(rel_bits, 0, REL_CNT);
288
+	}
289
+	if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), abs_bits) != -1) {
290
+		has_abs_axes = bits_calc(abs_bits, 0, ABS_CNT);
291
+		has_mt = bits_calc(abs_bits, ABS_MT_SLOT, ABS_CNT);
292
+	}
136
+
293
+
137
+	return false;
294
+	int flags = 0;
295
+	if (has_abs_axes) {
296
+		if (has_mt) {
297
+			if (!has_buttons) {
298
+				/*
299
+				 * XXX: I'm not sure that joystick detection is
300
+				 * done right. xf86-input-evdev does not support them.
301
+				 */
302
+				if (ULONG_IS_BIT_SET(key_bits, BTN_JOYSTICK))
303
+					flags = ATTR_JOYSTICK;
304
+				else
305
+					++has_buttons;
306
+			}
307
+		}
308
+		if (!flags && ULONG_IS_BIT_SET(abs_bits, ABS_X) && ULONG_IS_BIT_SET(abs_bits, ABS_Y)) {
309
+			if (ULONG_IS_BIT_SET(key_bits, BTN_TOOL_PEN) ||
310
+			    ULONG_IS_BIT_SET(key_bits, BTN_STYLUS) ||
311
+			    ULONG_IS_BIT_SET(key_bits, BTN_STYLUS2))
312
+				flags = ATTR_TABLET;
313
+			else if (ULONG_IS_BIT_SET(abs_bits, ABS_PRESSURE) ||
314
+			         ULONG_IS_BIT_SET(key_bits, BTN_TOUCH)) {
315
+				if (has_lmr || ULONG_IS_BIT_SET(key_bits, BTN_TOOL_FINGER))
316
+					flags = ATTR_TOUCHPAD;
317
+				else
318
+					flags = ATTR_TOUCHSCREEN;
319
+			} else if (!(ULONG_IS_BIT_SET(rel_bits, REL_X) &&
320
+			             ULONG_IS_BIT_SET(rel_bits, REL_Y)) &&
321
+			            has_lmr) /* some touchscreens use BTN_LEFT rather than BTN_TOUCH */
322
+				flags = ATTR_TOUCHSCREEN;
323
+		}
324
+	}
325
+	if (!flags) {
326
+		if (has_keys)
327
+			flags = ATTR_KEY | ATTR_KEYBOARD;
328
+		else if (has_rel_axes || has_abs_axes || has_buttons)
329
+			flags = ATTR_POINTER;
330
+	}
331
+	return flags;
138
+}
332
+}
139
+
333
+
334
+/* From: sys/dev/usb/usb_hid.c */
335
+static int
336
+hid_is_collection(report_desc_t s, uint32_t usage)
337
+{
338
+	struct hid_data* hd = hid_start_parse(s, ~0, -1);
339
+	if (!hd)
340
+		return 0;
341
+
342
+	struct hid_item hi;
343
+	int rc;
344
+	while ((rc = hid_get_item(hd, &hi))) {
345
+		 if (hi.kind == hid_collection && hi.usage == usage)
346
+			break;
347
+	}
348
+	hid_end_parse(hd);
349
+	return rc;
350
+}
351
+
352
+static int
353
+hid_is_mouse(report_desc_t s)
354
+{
355
+	struct hid_data* hd = hid_start_parse(s, (1 << hid_input), -1);
356
+	if (!hd)
357
+		return 0;
358
+
359
+	struct hid_item hi;
360
+	int found = 0, mdepth = 0;
361
+	while (hid_get_item(hd, &hi)) {
362
+		switch (hi.kind) {
363
+		case hid_collection:
364
+			if (mdepth != 0)
365
+				++mdepth;
366
+			else if (hi.collection == 1 &&
367
+			         hi.usage == HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE))
368
+				++mdepth;
369
+			break;
370
+		case hid_endcollection:
371
+			if (mdepth)
372
+				--mdepth;
373
+			break;
374
+		case hid_input:
375
+			if (!mdepth)
376
+				break;
377
+			if (hi.usage == HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X) &&
378
+			    (hi.flags & (HIO_CONST|HIO_RELATIVE)) == HIO_RELATIVE)
379
+				++found;
380
+			if (hi.usage == HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y) &&
381
+			    (hi.flags & (HIO_CONST|HIO_RELATIVE)) == HIO_RELATIVE)
382
+				++found;
383
+			break;
384
+		default:
385
+			break;
386
+		}
387
+	}
388
+	hid_end_parse(hd);
389
+	return found;
390
+}
391
+
140
+static char *
392
+static char *
141
+sysctl_get_str(const char *sysctlname)
393
+sysctl_get_str(const char *sysctlname, size_t *size_ret)
142
+{
394
+{
143
+	char *dest = NULL;
395
+	if (!sysctlname)
144
+	size_t len;
396
+		return NULL;
145
+
397
+
146
+	if (sysctlname == NULL)
398
+	size_t len = 0;
399
+	if (sysctlbyname(sysctlname, NULL, &len, NULL, 0) || !len)
147
+		return NULL;
400
+		return NULL;
148
+
401
+
149
+	if (sysctlbyname(sysctlname, NULL, &len, NULL, 0) == 0) {
402
+	char* dest = malloc(len + 1);
150
+		dest = malloc(len + 1);
403
+	if (!dest)
151
+		if (dest) {
404
+		return NULL;
152
+			if (sysctlbyname(sysctlname, dest, &len, NULL, 0) == 0)
405
+
153
+				dest[len] = '\0';
406
+	if (sysctlbyname(sysctlname, dest, &len, NULL, 0)) {
154
+			else {
407
+		free(dest);
155
+				free(dest);
408
+		return NULL;
156
+				dest = NULL;
157
+			}
158
+		}
159
+	}
409
+	}
160
+
410
+	dest[len] = 0;
411
+	if (size_ret)
412
+		*size_ret = len;
161
+	return dest;
413
+	return dest;
162
+}
414
+}
163
+
415
+
416
+static char *
417
+devd_get_val(char *buf, size_t buf_size, const char *val_name, size_t val_name_size, size_t *val_size)
418
+{
419
+	if (!buf || !buf_size || !val_name || !val_name_size)
420
+		return NULL;
421
+
422
+	char *ret = buf, *buf_end = (buf + buf_size);
423
+	while (ret && ret < buf_end) {
424
+		ret = memmem(ret, (buf_end - ret), val_name, val_name_size);
425
+		if (!ret)
426
+			return NULL;
427
+		/* Found. */
428
+		/* Check: space before or buf+1. */
429
+		if ((buf + 1) < ret && ret[-1] != ' ') {
430
+			ret += val_name_size;
431
+			continue;
432
+		}
433
+		/* Check: = after name and size for value. */
434
+		ret += val_name_size;
435
+		if ((ret + 1) >= buf_end)
436
+			return NULL;
437
+		if (ret[0] != '=')
438
+			continue;
439
+		++ret;
440
+		break;
441
+	}
442
+	if (!ret || !val_size)
443
+		return ret;
444
+	/* Calc value data size. */
445
+	char* ptr = memchr(ret, ' ', (buf_end - ret));
446
+	if (!ptr) /* End of string/last value. */
447
+		ptr = buf_end;
448
+	*val_size = (ptr - ret);
449
+	return ret;
450
+}
451
+
164
+static void
452
+static void
165
+device_added(const char *devname)
453
+device_added(const char *dev_name, size_t dev_name_size, int allow_no_device)
166
+{
454
+{
167
+	char path[PATH_MAX];
455
+	if (!dev_name || !dev_name_size || dev_name_size > PATH_MAX)
168
+	char sysctlname[PATH_MAX];
456
+		return;
169
+	char *vendor;
170
+	char *product = NULL;
171
+	char *config_info = NULL;
172
+	char *walk;
173
+	InputOption *options = NULL;
174
+	InputAttributes attrs = { };
175
+	DeviceIntPtr dev = NULL;
176
+	int i;
177
+	int fd;
178
+
457
+
179
+	for (i = 0; hw_types[i].driver != NULL; i++) {
458
+	char config_info[PATH_MAX + 32];
180
+		size_t len;
459
+	/* Make dev_name null ended string. */
460
+	snprintf(config_info, sizeof(config_info), DEVD_PATH_DEV"%.*s", (int)dev_name_size, dev_name);
461
+	/* Set / update pointers to dev_name and dev_path. */
462
+	char* dev_path = (config_info + DEVD_PATH_LEN); /* Skip: "devd:" */
463
+	dev_name = (dev_path + _PATH_DEV_LEN); /* Skip: "/dev/" */
181
+
464
+
182
+		len = strlen(hw_types[i].driver);
465
+	/* Is known input device or path? */
183
+		if (strcmp(devname, hw_types[i].driver) == 0 ||
466
+	hw_type_t *hwtype = get_dev_type_by_name(dev_name, dev_name_size);
184
+			(strncmp(devname, hw_types[i].driver, len) == 0 &&
467
+	if (!hwtype) {
185
+				isnumber(*(devname + len)))) {
468
+		hw_type_t hwtype_cust;
186
+			attrs.flags |= hw_types[i].flag;
469
+		hwtype = get_dev_type_by_path(dev_name, dev_name_size, &hwtype_cust);
187
+			break;
188
+		}
189
+	}
470
+	}
471
+	if (!hwtype) /* Not found in white list. */
472
+		return;
190
+
473
+
191
+	if (hw_types[i].driver == NULL || hw_types[i].xdriver == NULL) {
474
+	/* Skip legacy interfaces if EVDEV_SUPPORT is compiled into kernel */
192
+		LogMessage(X_INFO, "config/devd: ignoring device %s\n",
475
+	if (evdev_support && hwtype->is_hybrid) {
193
+				devname);
476
+		LogMessage(X_INFO, "config/devd: EVDEV_SUPPORT is enabled, ignoring device %s\n", dev_name);
194
+		return;
477
+		return;
195
+	}
478
+	}
196
+
197
+	/* Skip keyboard devices if kbdmux is enabled */
479
+	/* Skip keyboard devices if kbdmux is enabled */
198
+	if (is_kbdmux && is_console_kbd && hw_types[i].flag & ATTR_KEYBOARD) {
480
+	if (is_kbdmux && !allow_no_device && (hwtype->flags & ATTR_KEYBOARD)) {
199
+		LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n",
481
+		LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n", dev_name);
200
+				devname);
201
+		return;
482
+		return;
202
+	}
483
+	}
203
+
484
+	/* Skip duplicate devices. */
204
+	snprintf(path, sizeof(path), "/dev/%s", devname);
485
+	if (device_is_duplicate(config_info)) {
205
+
486
+		LogMessage(X_WARNING, "config/devd: device %s already added. ignoring\n", dev_path);
206
+	options = input_option_new(NULL, "_source", "server/devd");
207
+	if (!options)
208
+		return;
487
+		return;
209
+
210
+	snprintf(sysctlname, sizeof(sysctlname), "dev.%s.%s.%%desc",
211
+	    hw_types[i].driver, devname + strlen(hw_types[i].driver));
212
+	vendor = sysctl_get_str(sysctlname);
213
+	if (vendor == NULL) {
214
+		options = input_option_new(options, "name", devname);
215
+	}
488
+	}
216
+	else {
217
+		if ((walk = strchr(vendor, ' ')) != NULL) {
218
+			walk[0] = '\0';
219
+			walk++;
220
+			product = walk;
221
+			if ((walk = strchr(product, ',')) != NULL)
222
+				walk[0] = '\0';
223
+		}
224
+
489
+
225
+		attrs.vendor = strdup(vendor);
490
+	/* Init and set attributes. */
226
+		if (product) {
491
+	char pnp_usb_id[PATH_MAX], product[PATH_MAX], vendor[PATH_MAX];
227
+			attrs.product = strdup(product);
492
+	InputAttributes attrs;
228
+			options = input_option_new(options, "name", product);
493
+	memset(&attrs, 0, sizeof(attrs));
229
+		}
494
+	attrs.device = dev_path;
230
+		else
495
+	attrs.flags = hwtype->flags;
231
+			options = input_option_new(options, "name", "(unnamed)");
232
+
496
+
233
+		free(vendor);
497
+	/* Try to open device. */
234
+	}
498
+	int fd = open(dev_path, O_RDONLY);
235
+
499
+	if (fd < 0) {
236
+	/* XXX implement usb_id */
500
+		if (!(hwtype->flags & (ATTR_KEY | ATTR_KEYBOARD))) {
237
+	attrs.usb_id = NULL;
238
+	attrs.device = strdup(path);
239
+	options = input_option_new(options, "driver", hw_types[i].xdriver);
240
+
241
+	fd = open(path, O_RDONLY);
242
+	if (fd > 0) {
243
+		close(fd);
244
+		options = input_option_new(options, "device", path);
245
+	}
246
+	else {
247
+		if (attrs.flags & ~ATTR_KEYBOARD) {
248
+			LogMessage(X_INFO, "config/devd: device %s already opened\n",
249
+					 path);
250
+
251
+			/*
501
+			/*
252
+			 * Fail if cannot open device, it breaks AllowMouseOpenFail,
502
+			 * Fail if cannot open device, it breaks AllowMouseOpenFail,
253
+			 * but it should not matter when config/devd enabled
503
+			 * but it should not matter when config/devd is enabled
254
+			 */
504
+			 */
255
+			goto unwind;
505
+			LogMessage(X_WARNING, "config/devd: device %s already opened\n", dev_path);
506
+			return;
256
+		}
507
+		}
257
+
508
+		if (!allow_no_device) {
258
+		if (is_console_kbd) {
259
+			/*
509
+			/*
260
+			 * There can be only one keyboard attached to console and
510
+			 * There can be only one keyboard attached to console and
261
+			 * it is already added.
511
+			 * it is already added.
262
+			 */
512
+			 */
263
+			LogMessage(X_WARNING, "config/devd: console keyboard is "
513
+			LogMessage(X_WARNING, "config/devd: console keyboard is already added, ignoring %s\n", dev_path);
264
+					"already added, ignoring %s (%s)\n",
514
+			return;
265
+					attrs.product, path);
266
+			goto unwind;
267
+		}
515
+		}
268
+		else
516
+	} else {
269
+			/*
517
+		/* Try to get device info via ioctl(). */
270
+			 * Don't pass "device" option if the keyboard is already
518
+		keyboard_info_t kbdi;
271
+			 * attached to the console (ie. open() fails).
519
+		mousehw_t mshw;
272
+			 * This would activate a special logic in xf86-input-keyboard.
520
+		struct input_id iid;
273
+			 * Prevent any other attached to console keyboards being
521
+		report_desc_t rep_desc;
274
+			 * processed. There can be only one such device.
275
+			 */
276
+			is_console_kbd = true;
277
+	}
278
+
522
+
279
+	if (asprintf(&config_info, "devd:%s", devname) == -1) {
523
+		if (ioctl(fd, KDGKBINFO, &kbdi) != -1) { /* Is this keyboard? */
280
+		config_info = NULL;
524
+			memcpy(product, kbdi.kb_name, sizeof(kbdi.kb_name));
281
+		goto unwind;
525
+			attrs.product = product;
526
+			attrs.flags = ATTR_KEY | ATTR_KEYBOARD;
527
+			LogMessage(X_INFO, "config/devd: detected keyboard: %s, kb_index=%i, kb_unit=%i, kb_type=%i, kb_config=%i\n",
528
+			           kbdi.kb_name, kbdi.kb_index, kbdi.kb_unit, kbdi.kb_type, kbdi.kb_config);
529
+		} else if (ioctl(fd, MOUSE_GETHWINFO, &mshw) != -1) { /* Is this mouse? */
530
+			/* FreeBSD mouse drivers does not return real vid+pid. */
531
+			/* construct USB ID in lowercase hex - "0000:ffff" */
532
+			if (mshw.iftype != MOUSE_IF_USB && mshw.model > 0) {
533
+				snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%04x:%04x", mshw.hwid, mshw.model);
534
+				attrs.usb_id = pnp_usb_id;
535
+			}
536
+			if (mshw.type == MOUSE_PAD)
537
+				attrs.flags = ATTR_TOUCHPAD;
538
+			else
539
+				attrs.flags = ATTR_POINTER;
540
+			LogMessage(X_INFO, "config/devd: detected mouse: hwid=%04x, model=%04x, type=%04x, iftype=%04x, buttons=%d\n",
541
+			           mshw.hwid, mshw.model, mshw.type, mshw.iftype, mshw.buttons);
542
+		} else if (ioctl(fd, JSIOCGNAME((sizeof(product) - 1)), product) != -1) { /* Is this joystick? */
543
+			attrs.product = product;
544
+			attrs.flags = ATTR_JOYSTICK;
545
+			LogMessage(X_INFO, "config/devd: detected joystick: %s\n", product);
546
+		} else if (ioctl(fd, EVIOCGID, &iid) != -1 &&
547
+		           ioctl(fd, EVIOCGNAME((sizeof(product) - 1)), product) != -1) { /* Is this event? */
548
+			/* construct USB ID in lowercase hex - "0000:ffff" */
549
+			snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%04x:%04x", iid.vendor, iid.product);
550
+			attrs.usb_id = pnp_usb_id;
551
+			attrs.product = product;
552
+			/* Detect device type. */
553
+			attrs.flags = get_evdev_flags(fd);
554
+			/* Skip keyboard devices if kbdmux is enabled and EVDEV_SUPPORT is not compiled into kernel*/
555
+			if (is_kbdmux && !evdev_support && (attrs.flags & ATTR_KEYBOARD)) {
556
+				close(fd);
557
+				LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n", dev_name);
558
+				return;
559
+			}
560
+			LogMessage(X_INFO, "config/devd: detected event input: %s, bustype=%04x, vendor=%04x, product=%04x, version=%04x\n",
561
+			           product, iid.bustype, iid.vendor, iid.product, iid.version);
562
+		} else if ((rep_desc = hid_get_report_desc(fd))) { /* Is USB HID? */
563
+			if (hid_is_mouse(rep_desc)) {
564
+				attrs.flags = ATTR_POINTER;
565
+				LogMessage(X_INFO, "config/devd: detected USB HID mouse\n");
566
+			} else if (hid_is_collection(rep_desc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_KEYBOARD))) {
567
+				/* Skip keyboard devices if kbdmux is enabled */
568
+				if (is_kbdmux) {
569
+					hid_dispose_report_desc(rep_desc);
570
+					close(fd);
571
+					LogMessage(X_INFO, "config/devd: kbdmux is enabled, ignoring device %s\n", dev_name);
572
+					return;
573
+				}
574
+				attrs.flags = ATTR_KEY | ATTR_KEYBOARD;
575
+				LogMessage(X_INFO, "config/devd: detected USB HID keyboard\n");
576
+			} else if (hid_is_collection(rep_desc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_JOYSTICK)) ||
577
+			           hid_is_collection(rep_desc, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_GAME_PAD))) {
578
+				attrs.flags = ATTR_JOYSTICK;
579
+				LogMessage(X_INFO, "config/devd: detected USB HID joystick\n");
580
+			} else
581
+				LogMessage(X_INFO, "config/devd: detected USB HID of unknown type\n");
582
+			hid_dispose_report_desc(rep_desc);
583
+		}
584
+
585
+		if (!attrs.usb_id) { /* Is this webcamd device? */
586
+			unsigned short vid, pid;
587
+			if (ioctl(fd, WEBCAMD_IOCTL_GET_USB_VENDOR_ID, &vid) != -1 &&
588
+			    ioctl(fd, WEBCAMD_IOCTL_GET_USB_PRODUCT_ID, &pid) != -1) {
589
+				snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%04x:%04x", vid, pid);
590
+				attrs.usb_id = pnp_usb_id;
591
+				LogMessage(X_INFO, "config/devd: webcamd device: %s\n", pnp_usb_id);
592
+			}
593
+		}
282
+	}
594
+	}
595
+	close(fd);
283
+
596
+
284
+	if (device_is_duplicate(config_info)) {
597
+	/* Try to get device info via sysctl(). */
285
+		LogMessage(X_WARNING, "config/devd: device %s (%s) already added. "
598
+	if (!attrs.usb_id && !attrs.pnp_id) {
286
+				"ignoring\n", attrs.product, path);
599
+		char sysctlname[PATH_MAX];
287
+		goto unwind;
600
+		snprintf(sysctlname, sizeof(sysctlname), "dev.%.*s.%s.%%pnpinfo",
601
+		         (int)hwtype->dev_name_size,
602
+		         (hwtype->dev_name + hwtype->path_offset),
603
+		         (dev_name + hwtype->path_offset + hwtype->dev_name_size));
604
+		size_t sdata_size;
605
+		char* sdata = sysctl_get_str(sysctlname, &sdata_size);
606
+		if (sdata) {
607
+			size_t pid_size, vid_size;
608
+			char* ptr_vid = devd_get_val_cstr("vendor", sdata, sdata_size, &vid_size);
609
+			char* ptr_pid = devd_get_val_cstr("product", sdata, sdata_size, &pid_size);
610
+			if (ptr_vid && ptr_pid) { /* usb_id */
611
+				ptr_vid[vid_size] = 0;
612
+				ptr_pid[pid_size] = 0;
613
+				snprintf(pnp_usb_id, sizeof(pnp_usb_id), "%s:%s", ptr_vid, ptr_pid);
614
+				attrs.usb_id = pnp_usb_id;
615
+				LogMessage(X_INFO, "config/devd: [sysctl] usb_id: %s\n", pnp_usb_id);
616
+			} else { /* pnp_id */
617
+				strlcpy(pnp_usb_id, sdata, sizeof(pnp_usb_id));
618
+				attrs.pnp_id = pnp_usb_id;
619
+			}
620
+			free(sdata);
621
+		}
288
+	}
622
+	}
623
+	if (!attrs.vendor || !attrs.product) {
624
+		char sysctlname[PATH_MAX];
625
+		snprintf(sysctlname, sizeof(sysctlname), "dev.%.*s.%s.%%desc",
626
+		         (int)hwtype->dev_name_size,
627
+		         (hwtype->dev_name + hwtype->path_offset),
628
+		         (dev_name + hwtype->path_offset + hwtype->dev_name_size));
629
+		size_t sdata_size;
630
+		char* sdata = sysctl_get_str(sysctlname, &sdata_size);
631
+		if (sdata) {
632
+			/* Vendor. */
633
+			char* ptr_pid = memchr(sdata, ' ', sdata_size);
634
+			if (ptr_pid)
635
+				ptr_pid[0] = 0;
636
+			strlcpy(vendor, sdata, sizeof(vendor));
637
+			attrs.vendor = vendor;
638
+			/* Product. */
639
+			if (!attrs.product && ptr_pid) {
640
+				++ptr_pid;
641
+				char* ptr_vid = memchr(ptr_pid, ',', (sdata_size - (ptr_pid - sdata)));
642
+				if (ptr_vid)
643
+					ptr_vid[0] = 0;
644
+				strlcpy(product, ptr_pid, sizeof(product));
645
+				attrs.product = product;
646
+			} else
647
+				product[0] = 0;
648
+			free(sdata);
649
+			LogMessage(X_INFO, "config/devd: [sysctl] vendor: %s, product: %s\n", vendor, product);
650
+		}
651
+	}
289
+
652
+
290
+	options = input_option_new(options, "config_info", config_info);
653
+	/* Init options. */
291
+	LogMessage(X_INFO, "config/devd: adding input device %s (%s)\n",
654
+	InputOption *option = NULL, *options = NULL;
292
+			attrs.product, path);
655
+	if ((option = input_option_new(options, "_source", "server/devd")))
293
+
656
+		options = option;
294
+	NewInputDeviceRequest(options, &attrs, &dev);
657
+	if (option && (option = input_option_new(options, "config_info", config_info)))
295
+
658
+		options = option;
296
+unwind:
659
+	if (option && (option = input_option_new(options, "name", (attrs.product ? attrs.product : dev_name))))
297
+	free(config_info);
660
+		options = option;
298
+	input_option_free_list(&options);
661
+	if (option && hwtype->xdriver && (option = input_option_new(options, "driver", hwtype->xdriver)))
299
+	free(attrs.usb_id);
662
+		options = option;
300
+	free(attrs.product);
663
+	/*
301
+	free(attrs.device);
664
+	 * Don't pass "device" option if the keyboard is already attached to the console (ie. open() failed)
302
+	free(attrs.vendor);
665
+	 * This would activate a special logic in xf86-input-keyboard. Prevent any other attached to console
666
+	 * keyboards being processed. There can be only one such device.
667
+	 */
668
+	if (option && fd >= 0 && (option = input_option_new(options, "device", dev_path)))
669
+		options = option;
670
+	/* Most drivers just use "device" but evdev also uses "path" so populate both */
671
+	if (option && (option = input_option_new(options, "path", dev_path)))
672
+		options = option;
673
+	if (option) {
674
+		LogMessage(X_INFO, "config/devd: adding input device %s\n", dev_path);
675
+		DeviceIntPtr dev_iptr = NULL;
676
+		int rc;
677
+		if ((rc = NewInputDeviceRequest(options, &attrs, &dev_iptr)) != Success)
678
+			LogMessage(X_ERROR, "config/devd: error %d adding device %s\n", rc, dev_path);
679
+	} else
680
+		LogMessage(X_ERROR, "config/devd: error adding device %s\n", dev_path);
681
+	if (options)
682
+		input_option_free_list(&options);
683
+	return;
303
+}
684
+}
304
+
685
+
305
+static void
686
+static void
306
+device_removed(char *devname)
687
+device_removed(const char *dev_name, size_t dev_name_size)
307
+{
688
+{
308
+	char *config_info;
309
+
689
+
310
+	if (asprintf(&config_info, "devd:%s", devname) == -1)
690
+	if (!dev_name || !dev_name_size || dev_name_size > PATH_MAX)
311
+		return;
691
+		return;
312
+
692
+
693
+	hw_type_t hwtype_cust;
694
+	if (!get_dev_type_by_name(dev_name, dev_name_size) &&
695
+	    !get_dev_type_by_path(dev_name, dev_name_size, &hwtype_cust))
696
+		return;	/* Device not in list - unknown. */
697
+
698
+	char config_info[PATH_MAX + 32];
699
+	snprintf(config_info, sizeof(config_info), DEVD_PATH_DEV"%.*s", (int)dev_name_size, dev_name);
700
+	if (device_is_duplicate(config_info))
701
+		LogMessage(X_INFO, "config/devd: removing input device %s\n", (config_info + DEVD_PATH_LEN));
702
+	else
703
+		LogMessage(X_INFO, "config/devd: removing nonexistent device %s\n", (config_info + DEVD_PATH_LEN));
313
+	remove_devices("devd", config_info);
704
+	remove_devices("devd", config_info);
314
+
705
+	return;
315
+	free(config_info);
316
+}
706
+}
317
+
707
+
318
+static bool is_kbdmux_enabled(void)
708
+static void socket_handler(int fd, int ready, void *data);
319
+{
320
+	/* Xorg uses /dev/ttyv0 as a console device */
321
+	/* const char device[]="/dev/console"; */
322
+	const char device[]="/dev/ttyv0";
323
+	keyboard_info_t info;
324
+	int fd;
325
+
709
+
326
+	fd = open(device, O_RDONLY);
327
+
328
+	if (fd < 0)
329
+		return false;
330
+
331
+	if (ioctl(fd, KDGKBINFO, &info) == -1) {
332
+		close(fd);
333
+		return false;
334
+	}
335
+
336
+	close(fd);
337
+
338
+	if (!strncmp(info.kb_name, "kbdmux", 6))
339
+		return true;
340
+
341
+	return false;
342
+}
343
+
344
+static void
345
+disconnect_devd(int sock)
346
+{
347
+	if (sock >= 0) {
348
+		RemoveGeneralSocket(sock);
349
+		close(sock);
350
+	}
351
+}
352
+
353
+static int
710
+static int
354
+connect_devd(void)
711
+connect_devd(void)
355
+{
712
+{
356
+	struct sockaddr_un devd;
713
+	int sock = socket(AF_UNIX, SOCK_STREAM, 0);
357
+	int sock;
358
+
359
+	sock = socket(AF_UNIX, SOCK_STREAM, 0);
360
+	if (sock < 0) {
714
+	if (sock < 0) {
361
+		LogMessage(X_ERROR, "config/devd: fail opening stream socket\n");
715
+		LogMessage(X_ERROR, "config/devd: failed opening stream socket: %s\n", strerror(errno));
362
+		return -1;
716
+		return -1;
363
+	}
717
+	}
364
+
718
+
719
+	struct sockaddr_un devd;
365
+	devd.sun_family = AF_UNIX;
720
+	devd.sun_family = AF_UNIX;
366
+	strlcpy(devd.sun_path, DEVD_SOCK_PATH, sizeof(devd.sun_path));
721
+	memcpy(devd.sun_path, DEVD_SOCK_PATH, sizeof(DEVD_SOCK_PATH));
367
+
722
+	if (connect(sock, (struct sockaddr*)&devd, sizeof(devd)) < 0) {
368
+	if (connect(sock, (struct sockaddr *) &devd, sizeof(devd)) < 0) {
723
+		int error = errno;
369
+		close(sock);
724
+		close(sock);
370
+		LogMessage(X_ERROR, "config/devd: fail to connect to devd\n");
725
+		LogMessage(X_ERROR, "config/devd: failed to connect to devd: %s)\n", strerror(error));
371
+		return -1;
726
+		return -1;
372
+	}
727
+	}
373
+
728
+
374
+	AddGeneralSocket(sock);
729
+	SetNotifyFd(sock, socket_handler, X_NOTIFY_READ, NULL);
730
+	return sock;
731
+}
375
+
732
+
376
+	return	sock;
733
+static void
734
+disconnect_devd(int sock)
735
+{
736
+	if (sock < 0)
737
+		return;
738
+	RemoveNotifyFd(sock);
739
+	close(sock);
740
+	return;
377
+}
741
+}
378
+
742
+
379
+static CARD32
743
+static CARD32
380
+reconnect_handler(OsTimerPtr timer, CARD32 time, void *arg)
744
+reconnect_handler(OsTimerPtr timer, CARD32 time, void *arg)
381
+{
745
+{
382
+	int newsock;
746
+	devd_buf_used = 0;
383
+
747
+	devd_skt = connect_devd();
384
+	if ((newsock = connect_devd()) > 0) {
748
+	if (devd_skt < 0) /* Try again after RECONNECT_DELAY */
385
+		sock_devd = newsock;
749
+		return RECONNECT_DELAY;
386
+		TimerFree(rtimer);
750
+	TimerFree(rtimer);
387
+		rtimer = NULL;
751
+	rtimer = NULL;
388
+		LogMessage(X_INFO, "config/devd: reopening devd socket\n");
752
+	LogMessage(X_INFO, "config/devd: reopened devd socket\n");
389
+		return 0;
753
+	return 0;
390
+	}
391
+
392
+	/* Try again after RECONNECT_DELAY */
393
+	return RECONNECT_DELAY;
394
+}
754
+}
395
+
755
+
396
+static ssize_t
756
+static void
397
+socket_getline(int fd, char **out)
757
+socket_handler(int fd, int ready, void *data)
398
+{
758
+{
399
+	char *buf, *newbuf;
759
+	/* Read new data. */
400
+	ssize_t ret, cap, sz = 0;
760
+	while (1) {
401
+	char c;
761
+		ssize_t ios = recv(devd_skt, (devd_buf + devd_buf_used), (sizeof(devd_buf) - devd_buf_used), MSG_DONTWAIT);
402
+
762
+		if (ios > 0) { /* Read OK. */
403
+	cap = 1024;
763
+			devd_buf_used += ios;
404
+	buf = malloc(cap * sizeof(char));
764
+			continue; /* Try to read more. */
405
+	if (!buf)
406
+		return -1;
407
+
408
+	for (;;) {
409
+		ret = read(sock_devd, &c, 1);
410
+		if (ret < 0) {
411
+			if (errno == EINTR)
412
+				continue;
413
+			free(buf);
414
+			return -1;
415
+		/* EOF - devd socket is lost */
416
+		} else if (ret == 0) {
417
+			disconnect_devd(sock_devd);
418
+			rtimer = TimerSet(NULL, 0, 1, reconnect_handler, NULL);
419
+			LogMessage(X_WARNING, "config/devd: devd socket is lost\n");
420
+			free(buf);
421
+			return -1;
422
+		}
765
+		}
423
+		if (c == '\n')
766
+		/* Something wrong. */
424
+			break;
767
+		int error = errno;
425
+
768
+		if (error == EAGAIN)
426
+		if (sz + 1 >= cap) {
769
+			break; /* All available data read. */
427
+			cap *= 2;
770
+		if (error == EINTR)
428
+			newbuf = realloc(buf, cap * sizeof(char));
771
+			continue;
429
+			if (!newbuf) {
772
+		if (devd_buf_used >= sizeof(devd_buf)) {
430
+				free(buf);
773
+			devd_buf_used = 0; /* Message too long, reset buf. */
431
+				return -1;
774
+			continue;
432
+			}
433
+			buf = newbuf;
434
+		}
775
+		}
435
+		buf[sz] = c;
776
+		/* devd socket is lost */
436
+		sz++;
777
+		disconnect_devd(devd_skt);
778
+		rtimer = TimerSet(NULL, 0, 1, reconnect_handler, NULL);
779
+		LogMessage(X_WARNING, "config/devd: devd socket read error: %s\n", strerror(error));
780
+		return;
437
+	}
781
+	}
438
+
782
+
439
+	buf[sz] = '\0';
783
+	/* Process data. */
440
+	if (sz >= 0)
784
+	char *ptr, *line = (devd_buf + 1);
441
+		*out = buf;
785
+	size_t line_size = 0;
442
+	else
786
+	while((ptr = memchr(line, '\n', (devd_buf_used - line_size)))) {
443
+		free(buf);
787
+		line_size = (ptr - line);
788
+		do {
789
+			if (*(line - 1) != DEVD_EVENT_NOTIFY)
790
+				break; /* Handle only notify. */
791
+			/* Check: is system=DEVFS. */
792
+			size_t val_size;
793
+			char* val = devd_get_val_cstr("system", line, line_size, &val_size);
794
+			if (!is_meuqual_cstr("DEVFS", val, val_size))
795
+				break;
796
+			/* Check: is subsystem=CDEV. */
797
+			val = devd_get_val_cstr("subsystem", line, line_size, &val_size);
798
+			if (!is_meuqual_cstr("CDEV", val, val_size))
799
+				break;
800
+			/* Get device name. */
801
+			size_t cdev_size;
802
+			char* cdev = devd_get_val_cstr("cdev", line, line_size, &cdev_size);
803
+			if (!cdev)
804
+				break;
805
+			/* Get event type. */
806
+			val = devd_get_val_cstr("type", line, line_size, &val_size);
807
+			if (is_meuqual_cstr("CREATE", val, val_size)) {
808
+				device_added(cdev, cdev_size, 0);
809
+			} else if (is_meuqual_cstr("DESTROY", val, val_size)) {
810
+				device_removed(cdev, cdev_size);
811
+			}
812
+		} while(0);
444
+
813
+
445
+	/* Number of bytes in the line, not counting the line break */
814
+		line += (line_size + 2); /* Skip '\n' and event type byte. */
446
+	return sz;
815
+		line_size = (line - devd_buf);
447
+}
816
+		if (devd_buf_used <= line_size) {
448
+
817
+			devd_buf_used = 0;
449
+static void
450
+wakeup_handler(void *data, int err, void *read_mask)
451
+{
452
+	char *line = NULL;
453
+	char *walk;
454
+
455
+	if (err < 0)
456
+		return;
457
+
458
+	if (FD_ISSET(sock_devd, (fd_set *) read_mask)) {
459
+		if (socket_getline(sock_devd, &line) < 0)
460
+			return;
818
+			return;
461
+
462
+		walk = strchr(line + 1, ' ');
463
+		if (walk != NULL)
464
+			walk[0] = '\0';
465
+
466
+		switch (*line) {
467
+		case DEVD_EVENT_ADD:
468
+			device_added(line + 1);
469
+			break;
470
+		case DEVD_EVENT_REMOVE:
471
+			device_removed(line + 1);
472
+			break;
473
+		default:
474
+			break;
475
+		}
819
+		}
476
+		free(line);
477
+	}
820
+	}
821
+	/* Save line without end marker. */
822
+	if (line_size) {
823
+		devd_buf_used -= (line_size - 1);
824
+		memmove(devd_buf, (line - 1), devd_buf_used);
825
+	}
826
+	return;
478
+}
827
+}
479
+
828
+
480
+static void
481
+block_handler(void *data, struct timeval **tv, void *read_mask)
482
+{
483
+}
484
+
485
+int
829
+int
486
+config_devd_init(void)
830
+config_devd_init(void)
487
+{
831
+{
488
+	char devicename[1024];
489
+	int i, j;
490
+
491
+	LogMessage(X_INFO, "config/devd: probing input devices...\n");
832
+	LogMessage(X_INFO, "config/devd: probing input devices...\n");
492
+
833
+
834
+	/* Check if kernel is compiled with evdev support in hybrid drivers */
835
+	evdev_support = feature_present("evdev_support");
836
+
493
+	/*
837
+	/*
494
+	 * Add fake keyboard and give up on keyboards management
838
+	 * Add fake keyboard and give up on keyboards management
495
+	 * if kbdmux is enabled
839
+	 * if kbdmux is enabled and not exported through evdev
496
+	 */
840
+	 */
497
+	if ((is_kbdmux = is_kbdmux_enabled()) == true)
841
+	is_kbdmux = is_kbdmux_enabled();
498
+		device_added("kbdmux");
842
+	if (is_kbdmux && !evdev_support)
843
+		device_added("kbdmux0", 7, 1);
499
+
844
+
500
+	for (i = 0; hw_types[i].driver != NULL; i++) {
845
+	/* Scan /dev/ for devices. */
501
+		/* First scan the sysctl to determine the hardware */
846
+	struct dirent** namelist;
502
+		for (j = 0; j < 16; j++) {
847
+	size_t dir_cnt = scandir(_PATH_DEV, &namelist, 0, alphasort);
503
+			if (sysctl_exists(&hw_types[i], j,
848
+	for (size_t i = 0; i < dir_cnt; ++i) {
504
+					devicename, sizeof(devicename)) != 0)
849
+		struct dirent* de = namelist[i];
505
+				device_added(devicename);
850
+		if (is_de_euqual_cstr(de, ".") ||
851
+		    is_de_euqual_cstr(de, "..")) {
852
+			free(de);
853
+			continue;
506
+		}
854
+		}
507
+
855
+		if (de->d_type != DT_DIR) {
508
+		if (devpath_exists(&hw_types[i], devicename, sizeof(devicename)) != 0)
856
+			device_added(de->d_name, de->d_namlen, 0);
509
+			device_added(devicename);
857
+		} else { /* Sub folder. */
858
+			char devicename[PATH_MAX];
859
+			snprintf(devicename, sizeof(devicename), _PATH_DEV "%s", de->d_name);
860
+			struct dirent** snamelist;
861
+			size_t sdir_cnt = scandir(devicename, &snamelist, 0, alphasort);
862
+			for (size_t j = 0; j < sdir_cnt; ++j) {
863
+				struct dirent* sde = snamelist[j];
864
+				if (!is_de_euqual_cstr(sde, ".") &&
865
+				    !is_de_euqual_cstr(sde, "..") &&
866
+				    sde->d_type != DT_DIR) {
867
+					size_t tm = snprintf(devicename, sizeof(devicename), "%s/%s", de->d_name, sde->d_name);
868
+					device_added(devicename, tm, 0);
869
+				}
870
+				free(sde);
871
+			}
872
+			free(snamelist);
873
+		}
874
+		free(de);
510
+	}
875
+	}
876
+	free(namelist);
511
+
877
+
512
+	if ((sock_devd = connect_devd()) < 0)
878
+	devd_buf_used = 0;
513
+		return 0;
879
+	devd_skt = connect_devd();
514
+
880
+	return (devd_skt < 0) ? 0 : 1;
515
+	RegisterBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
516
+
517
+	return 1;
518
+}
881
+}
519
+
882
+
520
+void
883
+void
Lines 527-535 Link Here
527
+		rtimer = NULL;
890
+		rtimer = NULL;
528
+	}
891
+	}
529
+
892
+
530
+	disconnect_devd(sock_devd);
893
+	disconnect_devd(devd_skt);
531
+
894
+	return;
532
+	RemoveBlockAndWakeupHandlers(block_handler, wakeup_handler, NULL);
533
+
534
+	is_console_kbd = false;
535
+}
895
+}
(-)x11-servers/xorg-server/files/patch-config_udev.c (+56 lines)
Line 0 Link Here
1
* Don't pass the device parameter when using kbdmux to prevent conflict
2
*
3
* Specify a driver to use for basic devices (keyboard and mouse), otherwise none attaches
4
*
5
--- config/udev.c.orig	2017-03-15 18:05:25 UTC
6
+++ config/udev.c
7
@@ -29,6 +29,7 @@
8
 
9
 #include <libudev.h>
10
 #include <ctype.h>
11
+#include <fcntl.h>
12
 #include <unistd.h>
13
 
14
 #include "input.h"
15
@@ -188,7 +189,21 @@ device_added(struct udev_device *udev_de
16
         attrs.product = strdup(name);
17
     input_options = input_option_new(input_options, "name", name);
18
     input_options = input_option_new(input_options, "path", path);
19
-    input_options = input_option_new(input_options, "device", path);
20
+    if(strstr(path, "kbdmux") != NULL) {
21
+        /*
22
+         * Don't pass "device" option if the keyboard is already attached
23
+         * to the console (ie. open() fails). This would activate a special
24
+         * logic in xf86-input-keyboard. Prevent any other attached to console
25
+         * keyboards being processed. There can be only one such device.
26
+         */
27
+        int fd = open(path, O_RDONLY);
28
+        if (fd > -1) {
29
+            close(fd);
30
+            input_options = input_option_new(input_options, "device", path);
31
+        }
32
+    }
33
+    else
34
+        input_options = input_option_new(input_options, "device", path);
35
     input_options = input_option_new(input_options, "major", itoa(major(devnum)));
36
     input_options = input_option_new(input_options, "minor", itoa(minor(devnum)));
37
     if (path)
38
@@ -272,6 +287,18 @@ device_added(struct udev_device *udev_de
39
         }
40
     }
41
 
42
+    if (attrs.flags & (ATTR_KEY | ATTR_KEYBOARD)) {
43
+        if (!feature_present("evdev_support"))
44
+            input_options = input_option_new(input_options, "driver", "kbd");
45
+    } else if (attrs.flags & ATTR_POINTER) {
46
+        if (strstr(path, "vbox"))
47
+            input_options = input_option_new(input_options, "driver", "vboxmouse");
48
+        else {
49
+            if (!feature_present("evdev_support"))
50
+                input_options = input_option_new(input_options, "driver", "mouse");
51
+        }
52
+    }
53
+
54
     input_options = input_option_new(input_options, "config_info", config_info);
55
 
56
     /* Default setting needed for non-seat0 seats */
(-)x11-servers/xorg-server/files/patch-configure (-14 / +152 lines)
Lines 1-6 Link Here
1
--- configure.orig	2016-07-19 17:27:31 UTC
1
* generated from patched configure.ac; revise and regen instead of editing
2
*
3
* Plumb the devd config backend into configure
4
*
5
* define USE_DEV_IO for ARM platforms
6
*
7
* Only run pkg-config for udev if it is not disabled to prevent over-linking
8
*
9
* Automatically use systemd/logind only on Linux
10
*
11
--- configure.orig	2017-03-15 18:05:39 UTC
2
+++ configure
12
+++ configure
3
@@ -23168,9 +23168,14 @@ $as_echo "#define USE_ALPHA_PIO 1" >>con
13
@@ -1032,6 +1032,8 @@ CONFIG_UDEV_FALSE
14
 CONFIG_UDEV_TRUE
15
 UDEV_LIBS
16
 UDEV_CFLAGS
17
+CONFIG_DEVD_FALSE
18
+CONFIG_DEVD_TRUE
19
 HAVE_SYSTEMD_DAEMON_FALSE
20
 HAVE_SYSTEMD_DAEMON_TRUE
21
 SYSTEMD_DAEMON_LIBS
22
@@ -1367,6 +1369,7 @@ enable_tslib
23
 enable_dbe
24
 enable_xf86bigfont
25
 enable_dpms
26
+enable_config_devd
27
 enable_config_udev
28
 enable_config_udev_kms
29
 enable_config_hal
30
@@ -2191,6 +2194,7 @@ Optional Features:
31
   --disable-dbe           Build DBE extension (default: enabled)
32
   --enable-xf86bigfont    Build XF86 Big Font extension (default: disabled)
33
   --disable-dpms          Build DPMS extension (default: enabled)
34
+  --enable-config-devd    Build devd support (default: auto)
35
   --enable-config-udev    Build udev support (default: auto)
36
   --enable-config-udev-kms
37
                           Build udev kms support (default: auto)
38
@@ -23280,9 +23284,13 @@ $as_echo "#define USE_ALPHA_PIO 1" >>con
4
 	esac
39
 	esac
5
 	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
40
 	GLX_ARCH_DEFINES="-D__GLX_ALIGN64 -mieee"
6
 	;;
41
 	;;
Lines 9-27 Link Here
9
 	ARM_VIDEO=yes
44
 	ARM_VIDEO=yes
10
 	DEFAULT_INT10="stub"
45
 	DEFAULT_INT10="stub"
11
+	case $host_os in
46
+	case $host_os in
12
+		*freebsd*)
47
+		*freebsd*)	$as_echo "#define USE_DEV_IO 1" >>confdefs.h
13
+			$as_echo "#define USE_DEV_IO 1" >>confdefs.h
48
+ ;;
14
+		 ;;
15
+	esac
49
+	esac
16
 	;;
50
 	;;
17
   i*86)
51
   i*86)
18
 	I386_VIDEO=yes
52
 	I386_VIDEO=yes
19
@@ -26057,7 +26062,7 @@ fi
53
@@ -24053,6 +24061,13 @@ else
20
 case "x$XTRANS_SEND_FDS" in
54
   DPMSExtension=yes
21
 xauto)
55
 fi
22
 	case "$host_os" in
56
 
23
-	linux*|solaris*)
57
+# Check whether --enable-config-devd was given.
24
+	linux*|solaris*|freebsd*|dragonfly*|openbsd*)
58
+if test "${enable_config_devd+set}" = set; then :
25
 		XTRANS_SEND_FDS=yes
59
+  enableval=$enable_config_devd; CONFIG_DEVD=$enableval
26
 		;;
60
+else
27
 	*)
61
+  CONFIG_DEVD=auto
62
+fi
63
+
64
 # Check whether --enable-config-udev was given.
65
 if test "${enable_config_udev+set}" = set; then :
66
   enableval=$enable_config_udev; CONFIG_UDEV=$enableval
67
@@ -25813,6 +25828,31 @@ if test "x$CONFIG_UDEV" = xyes && test "
68
 	as_fn_error $? "Hotplugging through both libudev and hal not allowed" "$LINENO" 5
69
 fi
70
 
71
+if test "x$CONFIG_DEVD" = xauto; then
72
+	case $host_os in
73
+		*freebsd*)
74
+			CONFIG_DEVD=yes
75
+			;;
76
+		*)
77
+			CONFIG_DEVD=no
78
+			;;
79
+	esac
80
+fi
81
+ if test "x$CONFIG_DEVD" = xyes; then
82
+  CONFIG_DEVD_TRUE=
83
+  CONFIG_DEVD_FALSE='#'
84
+else
85
+  CONFIG_DEVD_TRUE='#'
86
+  CONFIG_DEVD_FALSE=
87
+fi
88
+
89
+if test "x$CONFIG_DEVD" = xyes; then
90
+
91
+$as_echo "#define CONFIG_DEVD 1" >>confdefs.h
92
+
93
+fi
94
+
95
+if test "x$CONFIG_UDEV" != xno; then
96
 
97
 pkg_failed=no
98
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for UDEV" >&5
99
@@ -25884,11 +25924,12 @@ else
100
 $as_echo "yes" >&6; }
101
 	HAVE_LIBUDEV=yes
102
 fi
103
-if test "x$CONFIG_UDEV" = xauto; then
104
-	CONFIG_UDEV="$HAVE_LIBUDEV"
105
+	if test "x$CONFIG_UDEV" = xauto; then
106
+		CONFIG_UDEV="$HAVE_LIBUDEV"
107
 
108
 $as_echo "#define HAVE_LIBUDEV 1" >>confdefs.h
109
 
110
+	fi
111
 fi
112
  if test "x$CONFIG_UDEV" = xyes; then
113
   CONFIG_UDEV_TRUE=
114
@@ -26132,7 +26173,14 @@ fi
115
 
116
 if test "x$SYSTEMD_LOGIND" = xauto; then
117
         if test "x$HAVE_DBUS" = xyes -a "x$CONFIG_UDEV" = xyes ; then
118
-                SYSTEMD_LOGIND=yes
119
+            case $host_os in
120
+                *linux*)
121
+                        SYSTEMD_LOGIND=yes
122
+                        ;;
123
+                *)
124
+                        SYSTEMD_LOGIND=no
125
+                        ;;
126
+            esac
127
         else
128
                 SYSTEMD_LOGIND=no
129
         fi
130
@@ -32849,17 +32897,17 @@ DIX_CFLAGS="-DHAVE_DIX_CONFIG_H $XSERVER
131
 ac_config_commands="$ac_config_commands sdksyms"
132
 
133
 
134
-if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno; then
135
+if test "x$CONFIG_HAL" = xno && test "x$CONFIG_UDEV" = xno && test "x$CONFIG_DEVD" = xno; then
136
     { $as_echo "$as_me:${as_lineno-$LINENO}: WARNING:
137
-             ***********************************************
138
-             Neither HAL nor udev backend will be enabled.
139
+             *****************************************************
140
+             Neither HAL, devd, nor udev backend will be enabled.
141
              Input device hotplugging will not be available!
142
-             ***********************************************" >&5
143
+             *****************************************************" >&5
144
 $as_echo "$as_me: WARNING:
145
-             ***********************************************
146
-             Neither HAL nor udev backend will be enabled.
147
+             *****************************************************
148
+             Neither HAL, devd, nor udev backend will be enabled.
149
              Input device hotplugging will not be available!
150
-             ***********************************************" >&2;}
151
+             *****************************************************" >&2;}
152
 fi
153
 
154
 ac_config_files="$ac_config_files Makefile glx/Makefile include/Makefile composite/Makefile damageext/Makefile dbe/Makefile dix/Makefile doc/Makefile doc/dtrace/Makefile man/Makefile fb/Makefile glamor/Makefile record/Makefile config/Makefile mi/Makefile miext/Makefile miext/sync/Makefile miext/damage/Makefile miext/shadow/Makefile miext/rootless/Makefile os/Makefile pseudoramiX/Makefile randr/Makefile render/Makefile xkb/Makefile Xext/Makefile Xi/Makefile xfixes/Makefile exa/Makefile dri3/Makefile present/Makefile hw/Makefile hw/xfree86/Makefile hw/xfree86/Xorg.sh hw/xfree86/common/Makefile hw/xfree86/common/xf86Build.h hw/xfree86/ddc/Makefile hw/xfree86/dixmods/Makefile hw/xfree86/doc/Makefile hw/xfree86/dri/Makefile hw/xfree86/dri2/Makefile hw/xfree86/dri2/pci_ids/Makefile hw/xfree86/drivers/Makefile hw/xfree86/drivers/modesetting/Makefile hw/xfree86/exa/Makefile hw/xfree86/exa/man/Makefile hw/xfree86/fbdevhw/Makefile hw/xfree86/fbdevhw/man/Makefile hw/xfree86/glamor_egl/Makefile hw/xfree86/i2c/Makefile hw/xfree86/int10/Makefile hw/xfree86/loader/Makefile hw/xfree86/man/Makefile hw/xfree86/modes/Makefile hw/xfree86/os-support/Makefile hw/xfree86/os-support/bsd/Makefile hw/xfree86/os-support/bus/Makefile hw/xfree86/os-support/hurd/Makefile hw/xfree86/os-support/misc/Makefile hw/xfree86/os-support/linux/Makefile hw/xfree86/os-support/solaris/Makefile hw/xfree86/os-support/stub/Makefile hw/xfree86/parser/Makefile hw/xfree86/ramdac/Makefile hw/xfree86/shadowfb/Makefile hw/xfree86/vbe/Makefile hw/xfree86/vgahw/Makefile hw/xfree86/x86emu/Makefile hw/xfree86/utils/Makefile hw/xfree86/utils/man/Makefile hw/xfree86/utils/cvt/Makefile hw/xfree86/utils/gtf/Makefile hw/dmx/config/Makefile hw/dmx/config/man/Makefile hw/dmx/doc/Makefile hw/dmx/doxygen/doxygen.conf hw/dmx/doxygen/Makefile hw/dmx/examples/Makefile hw/dmx/input/Makefile hw/dmx/glxProxy/Makefile hw/dmx/Makefile hw/dmx/man/Makefile hw/vfb/Makefile hw/vfb/man/Makefile hw/xnest/Makefile hw/xnest/man/Makefile hw/xwin/Makefile hw/xwin/dri/Makefile hw/xwin/glx/Makefile hw/xwin/man/Makefile hw/xwin/winclipboard/Makefile hw/xquartz/Makefile hw/xquartz/GL/Makefile hw/xquartz/bundle/Makefile hw/xquartz/man/Makefile hw/xquartz/mach-startup/Makefile hw/xquartz/pbproxy/Makefile hw/xquartz/xpr/Makefile hw/kdrive/Makefile hw/kdrive/ephyr/Makefile hw/kdrive/ephyr/man/Makefile hw/kdrive/fake/Makefile hw/kdrive/fbdev/Makefile hw/kdrive/linux/Makefile hw/kdrive/src/Makefile hw/xwayland/Makefile test/Makefile test/xi1/Makefile test/xi2/Makefile xserver.ent xorg-server.pc"
155
@@ -33122,6 +33170,10 @@ if test -z "${HAVE_SYSTEMD_DAEMON_TRUE}"
156
   as_fn_error $? "conditional \"HAVE_SYSTEMD_DAEMON\" was never defined.
157
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
158
 fi
159
+if test -z "${CONFIG_DEVD_TRUE}" && test -z "${CONFIG_DEVD_FALSE}"; then
160
+  as_fn_error $? "conditional \"CONFIG_DEVD\" was never defined.
161
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
162
+fi
163
 if test -z "${CONFIG_UDEV_TRUE}" && test -z "${CONFIG_UDEV_FALSE}"; then
164
   as_fn_error $? "conditional \"CONFIG_UDEV\" was never defined.
165
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
(-)x11-servers/xorg-server/files/patch-glamor_glamor__dash.c (-27 lines)
Lines 1-27 Link Here
1
From: Eric Anholt <eric@anholt.net>
2
Date: Wed Mar 15 17:51:46 2017 -0700
3
Subject: [PATCH]glamor: Fix dashed line rendering.
4
Patch-mainline: fe0b297420fc1de8a7fab28457d0864b3182e967
5
References: boo#1021803
6
Signed-off-by: Max Staudt <mstaudt@suse.de>
7
8
We were binding the screen pixmap as the dash and sampling its alpha,
9
which is usually just 1.0 (no dashing at all).
10
11
Please cherry-pick this to active stable branches.
12
13
Signed-off-by: Eric Anholt <eric@anholt.net>
14
Reviewed-by: Keith Packard <keithp@keithp.com>
15
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
16
17
--- glamor/glamor_dash.c.orig	2016-07-18 19:08:16 UTC
18
+++ glamor/glamor_dash.c
19
@@ -146,7 +146,7 @@ glamor_dash_setup(DrawablePtr drawable, GCPtr gc)
20
         goto bail;
21
 
22
     dash_pixmap = glamor_get_dash_pixmap(gc);
23
-    dash_priv = glamor_get_pixmap_private(pixmap);
24
+    dash_priv = glamor_get_pixmap_private(dash_pixmap);
25
 
26
     if (!GLAMOR_PIXMAP_PRIV_HAS_FBO(dash_priv))
27
         goto bail;
(-)x11-servers/xorg-server/files/patch-hw_xfree86_Makefile.in (+14 lines)
Line 0 Link Here
1
* Don't overwrite Xorg binary with Xorg.sh when SUID_WRAPPER_DIR == bindir
2
* Instead, relink bin/X to Xorg.wrap rather than to Xorg (which isn't Xorg.sh)
3
*
4
--- hw/xfree86/Makefile.in.orig	2017-03-16 05:24:43 UTC
5
+++ hw/xfree86/Makefile.in
6
@@ -1149,7 +1149,7 @@ install-exec-hook:
7
 @INSTALL_SETUID_TRUE@	chmod u+s $(DESTDIR)$(bindir)/Xorg
8
 @SUID_WRAPPER_TRUE@	$(MKDIR_P) $(DESTDIR)$(SUID_WRAPPER_DIR)
9
 @SUID_WRAPPER_TRUE@	mv $(DESTDIR)$(bindir)/Xorg $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg
10
-@SUID_WRAPPER_TRUE@	${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg
11
+@SUID_WRAPPER_TRUE@	(test ! -f $(DESTDIR)$(bindir)/Xorg && ${INSTALL} -m 755 Xorg.sh $(DESTDIR)$(bindir)/Xorg || cd $(DESTDIR)$(bindir) && rm -f X && $(LN_S) Xorg.wrap$(EXEEXT) X)
12
 @SUID_WRAPPER_TRUE@	-chown root $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap && chmod u+s $(DESTDIR)$(SUID_WRAPPER_DIR)/Xorg.wrap
13
 
14
 uninstall-local:
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86AutoConfig.c (-1 / +5 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/common/xf86AutoConfig.c.orig	2017-01-11 20:00:58 UTC
1
* Try using modesetting driver before falling back to scfb or vesa
2
*
3
* Use our scfb driver as fallback instead of Linux's fbdev
4
*
5
--- hw/xfree86/common/xf86AutoConfig.c.orig	2017-03-15 18:05:25 UTC
2
+++ hw/xfree86/common/xf86AutoConfig.c
6
+++ hw/xfree86/common/xf86AutoConfig.c
3
@@ -276,7 +276,7 @@ listPossibleVideoDrivers(char *matches[]
7
@@ -276,7 +276,7 @@ listPossibleVideoDrivers(char *matches[]
4
         i += xf86PciMatchDriver(&matches[i], nmatches - i);
8
         i += xf86PciMatchDriver(&matches[i], nmatches - i);
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86Config.c (-3 / +5 lines)
Lines 1-12 Link Here
1
--- hw/xfree86/common/xf86Config.c.orig	2016-07-19 17:14:30 UTC
1
* Select the devd config backend if it is activated
2
*
3
--- hw/xfree86/common/xf86Config.c.orig	2017-03-15 18:05:25 UTC
2
+++ hw/xfree86/common/xf86Config.c
4
+++ hw/xfree86/common/xf86Config.c
3
@@ -1410,13 +1410,16 @@ checkCoreInputDevices(serverLayoutPtr se
5
@@ -1375,13 +1375,16 @@ checkCoreInputDevices(serverLayoutPtr se
4
     }
6
     }
5
 
7
 
6
     if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
8
     if (!xf86Info.forceInputDevices && !(foundPointer && foundKeyboard)) {
7
-#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
9
-#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS)
8
+#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) || \
10
+#if defined(CONFIG_HAL) || defined(CONFIG_UDEV) || defined(CONFIG_WSCONS) || \
9
+		defined(CONFIG_DEVD)
11
+	defined(CONFIG_DEVD)
10
         const char *config_backend;
12
         const char *config_backend;
11
 
13
 
12
 #if defined(CONFIG_HAL)
14
 #if defined(CONFIG_HAL)
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86Globals.c (-1 / +3 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/common/xf86Globals.c.orig	2016-07-19 17:07:29 UTC
1
* Include devd in the set of config backends
2
*
3
--- hw/xfree86/common/xf86Globals.c.orig	2017-03-15 18:05:25 UTC
2
+++ hw/xfree86/common/xf86Globals.c
4
+++ hw/xfree86/common/xf86Globals.c
3
@@ -122,7 +122,8 @@ xf86InfoRec xf86Info = {
5
@@ -122,7 +122,8 @@ xf86InfoRec xf86Info = {
4
     .pmFlag = TRUE,
6
     .pmFlag = TRUE,
(-)x11-servers/xorg-server/files/patch-hw_xfree86_common_xf86Xinput.c (-3 / +5 lines)
Lines 1-6 Link Here
1
--- hw/xfree86/common/xf86Xinput.c.orig	2016-07-19 17:07:29 UTC
1
* Recognize devd backend as a source of auto-configured devices
2
*
3
--- hw/xfree86/common/xf86Xinput.c.orig	2017-03-15 18:05:25 UTC
2
+++ hw/xfree86/common/xf86Xinput.c
4
+++ hw/xfree86/common/xf86Xinput.c
3
@@ -841,7 +841,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, D
5
@@ -871,7 +871,7 @@ xf86NewInputDevice(InputInfoPtr pInfo, D
4
 {
6
 {
5
     InputDriverPtr drv = NULL;
7
     InputDriverPtr drv = NULL;
6
     DeviceIntPtr dev = NULL;
8
     DeviceIntPtr dev = NULL;
Lines 9-15 Link Here
9
     int rval;
11
     int rval;
10
     char *path = NULL;
12
     char *path = NULL;
11
 
13
 
12
@@ -996,6 +996,7 @@ NewInputDeviceRequest(InputOption *optio
14
@@ -1034,6 +1034,7 @@ NewInputDeviceRequest(InputOption *optio
13
         if (strcmp(key, "_source") == 0 &&
15
         if (strcmp(key, "_source") == 0 &&
14
             (strcmp(value, "server/hal") == 0 ||
16
             (strcmp(value, "server/hal") == 0 ||
15
              strcmp(value, "server/udev") == 0 ||
17
              strcmp(value, "server/udev") == 0 ||
(-)x11-servers/xorg-server/files/patch-hw_xfree86_os-support_bsd_bsd__init.c (-2 / +55 lines)
Lines 1-6 Link Here
1
--- hw/xfree86/os-support/bsd/bsd_init.c.orig	2016-07-19 17:07:29 UTC
1
--- hw/xfree86/os-support/bsd/bsd_init.c.orig	2017-03-15 18:05:25 UTC
2
+++ hw/xfree86/os-support/bsd/bsd_init.c
2
+++ hw/xfree86/os-support/bsd/bsd_init.c
3
@@ -230,6 +230,9 @@ xf86OpenConsole()
3
@@ -48,6 +48,8 @@ static int devConsoleFd = -1;
4
 #if defined (SYSCONS_SUPPORT) || defined (PCVT_SUPPORT)
5
 static int VTnum = -1;
6
 static int initialVT = -1;
7
+static struct termios tty_attr;	/* tty state to restore */
8
+static int tty_mode;		/* kbd mode to restore */
9
 #endif
10
 
11
 #ifdef PCCONS_SUPPORT
12
@@ -230,6 +232,9 @@ xf86OpenConsole()
4
              * Add cases for other *BSD that behave the same.
13
              * Add cases for other *BSD that behave the same.
5
              */
14
              */
6
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
15
 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
Lines 10-12 Link Here
10
             uname(&uts);
19
             uname(&uts);
11
             i = atof(uts.release) * 100;
20
             i = atof(uts.release) * 100;
12
             if (i >= 310)
21
             if (i >= 310)
22
@@ -253,6 +258,7 @@ xf86OpenConsole()
23
 #endif
24
  acquire_vt:
25
             if (!xf86Info.ShareVTs) {
26
+                struct termios nTty;
27
                 /*
28
                  * now get the VT
29
                  */
30
@@ -287,6 +293,26 @@ xf86OpenConsole()
31
                 if (ioctl(xf86Info.consoleFd, KDSETMODE, KD_GRAPHICS) < 0) {
32
                     FatalError("xf86OpenConsole: KDSETMODE KD_GRAPHICS failed");
33
                 }
34
+
35
+                tcgetattr(xf86Info.consoleFd, &tty_attr);
36
+                ioctl(xf86Info.consoleFd, KDGKBMODE, &tty_mode);
37
+
38
+                /* disable special keys */
39
+                if (ioctl(xf86Info.consoleFd, KDSKBMODE, K_RAW) < 0) {
40
+                    FatalError("xf86OpenConsole: KDSKBMODE K_RAW failed (%s)",
41
+                               strerror(errno));
42
+                }
43
+
44
+                nTty = tty_attr;
45
+                nTty.c_iflag = IGNPAR | IGNBRK;
46
+                nTty.c_oflag = 0;
47
+                nTty.c_cflag = CREAD | CS8;
48
+                nTty.c_lflag = 0;
49
+                nTty.c_cc[VTIME] = 0;
50
+                nTty.c_cc[VMIN] = 1;
51
+                cfsetispeed(&nTty, 9600);
52
+                cfsetospeed(&nTty, 9600);
53
+                tcsetattr(xf86Info.consoleFd, TCSANOW, &nTty);
54
             }
55
             else {              /* xf86Info.ShareVTs */
56
                 close(xf86Info.consoleFd);
57
@@ -594,6 +620,8 @@ xf86CloseConsole()
58
     case SYSCONS:
59
     case PCVT:
60
         ioctl(xf86Info.consoleFd, KDSETMODE, KD_TEXT);  /* Back to text mode */
61
+        ioctl(xf86Info.consoleFd, KDSKBMODE, tty_mode);
62
+        tcsetattr(xf86Info.consoleFd, TCSANOW, &tty_attr);
63
         if (ioctl(xf86Info.consoleFd, VT_GETMODE, &VT) != -1) {
64
             VT.mode = VT_AUTO;
65
             ioctl(xf86Info.consoleFd, VT_SETMODE, &VT); /* dflt vt handling */
(-)x11-servers/xorg-server/files/patch-hw_xfree86_os-support_bsd_i386__video.c (-1 / +1 lines)
Lines 1-5 Link Here
1
Index: programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
1
Index: programs/Xserver/hw/xfree86/os-support/bsd/i386_video.c
2
--- hw/xfree86/os-support/bsd/i386_video.c.orig	2016-07-15 16:18:11 UTC
2
--- hw/xfree86/os-support/bsd/i386_video.c.orig	2017-03-15 18:05:25 UTC
3
+++ hw/xfree86/os-support/bsd/i386_video.c
3
+++ hw/xfree86/os-support/bsd/i386_video.c
4
@@ -32,6 +32,7 @@
4
@@ -32,6 +32,7 @@
5
 #include "xf86Priv.h"
5
 #include "xf86Priv.h"
(-)x11-servers/xorg-server/files/patch-hw_xfree86_os-support_bsd_ppc__video.c (-1 / +1 lines)
Lines 1-4 Link Here
1
--- hw/xfree86/os-support/bsd/ppc_video.c.orig	2016-07-15 16:18:11 UTC
1
--- hw/xfree86/os-support/bsd/ppc_video.c.orig	2017-03-15 18:05:25 UTC
2
+++ hw/xfree86/os-support/bsd/ppc_video.c
2
+++ hw/xfree86/os-support/bsd/ppc_video.c
3
@@ -79,7 +79,11 @@ xf86DisableIO()
3
@@ -79,7 +79,11 @@ xf86DisableIO()
4
 {
4
 {
(-)x11-servers/xorg-server/files/patch-hw_xfree86_xorg-wrapper.c (+27 lines)
Line 0 Link Here
1
* Skip the detection of root rights requirement, the assumption that presence
2
* of KMS drivers removes the root requirement is only valid for Linux
3
*
4
--- hw/xfree86/xorg-wrapper.c.orig	2017-03-15 18:05:25 UTC
5
+++ hw/xfree86/xorg-wrapper.c
6
@@ -188,9 +188,6 @@ static int on_console(int fd)
7
 
8
 int main(int argc, char *argv[])
9
 {
10
-#ifdef WITH_LIBDRM
11
-    struct drm_mode_card_res res;
12
-#endif
13
     char buf[PATH_MAX];
14
     int i, r, fd;
15
     int kms_cards = 0;
16
@@ -227,9 +224,10 @@ int main(int argc, char *argv[])
17
         }
18
     }
19
 
20
-#ifdef WITH_LIBDRM
21
+#if defined(WITH_LIBDRM) && defined(__linux__)
22
     /* Detect if we need root rights, except when overriden by the config */
23
     if (needs_root_rights == -1) {
24
+        struct drm_mode_card_res res;
25
         for (i = 0; i < 16; i++) {
26
             snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, i);
27
             fd = open(buf, O_RDWR);
(-)x11-servers/xorg-server/files/patch-include_dix-config.h.in (+14 lines)
Line 0 Link Here
1
* Add a define which will be toggled by configure when devd backend is activated
2
*
3
--- include/dix-config.h.in.orig	2017-03-15 18:05:25 UTC
4
+++ include/dix-config.h.in
5
@@ -433,6 +433,9 @@
6
 /* Support D-Bus */
7
 #undef HAVE_DBUS
8
 
9
+/* Use devd for input hotplug */
10
+#undef CONFIG_DEVD
11
+
12
 /* Use libudev for input hotplug */
13
 #undef CONFIG_UDEV
14
 
(-)x11-servers/xorg-server/files/patch-os_io.c (-34 lines)
Lines 1-34 Link Here
1
From e751722a7b0c5b595794e60b054ade0b3f6cdb4d Mon Sep 17 00:00:00 2001
2
From: Michal Srb <msrb@suse.com>
3
Date: Fri, 7 Jul 2017 17:04:03 +0200
4
Subject: os: Make sure big requests have sufficient length.
5
6
A client can send a big request where the 32B "length" field has value
7
0. When the big request header is removed and the length corrected,
8
the value will underflow to 0xFFFFFFFF.  Functions processing the
9
request later will think that the client sent much more data and may
10
touch memory beyond the receive buffer.
11
12
Signed-off-by: Eric Anholt <eric@anholt.net>
13
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
14
(cherry picked from commit 9c23685009aa96f4b861dcc5d2e01dbee00c4dd9)
15
16
diff --git a/os/io.c b/os/io.c
17
index f80580c..70f07f3 100644
18
--- os/io.c
19
+++ os/io.c
20
@@ -441,6 +441,11 @@ ReadRequestFromClient(ClientPtr client)
21
     if (!gotnow)
22
         AvailableInput = oc;
23
     if (move_header) {
24
+        if (client->req_len < bytes_to_int32(sizeof(xBigReq) - sizeof(xReq))) {
25
+            YieldControlDeath();
26
+            return -1;
27
+        }
28
+
29
         request = (xReq *) oci->bufptr;
30
         oci->bufptr += (sizeof(xBigReq) - sizeof(xReq));
31
         *(xReq *) oci->bufptr = *request;
32
-- 
33
cgit v0.10.2
34
(-)x11-servers/xorg-server/files/patch-xkb_Makefile.in (-2 / +7 lines)
Lines 1-6 Link Here
1
--- xkb/Makefile.in.orig	2017-01-19 15:20:42 UTC
1
* Skip installing a README into a directory which is actually a symlink created
2
* by another port. If this file is installed, then upon uninstall pkg will
3
* delete the directory under the symlink, which would cause a reinstall to fail
4
* as the target directory is not remade until reinstalling the other port
5
*
6
--- xkb/Makefile.in.orig	2017-03-16 05:24:43 UTC
2
+++ xkb/Makefile.in
7
+++ xkb/Makefile.in
3
@@ -878,7 +878,7 @@ info: info-am
8
@@ -886,7 +886,7 @@ info: info-am
4
 
9
 
5
 info-am:
10
 info-am:
6
 
11
 
(-)x11-servers/xorg-server/files/xkb_Makefile.am (+13 lines)
Line 0 Link Here
1
* Skip installing a README into a directory which is actually a symlink created
2
* by another port. If this file is installed, then upon uninstall pkg will
3
* delete the directory under the symlink, which would cause a reinstall to fail
4
* as the target directory is not remade until reinstalling the other port
5
*
6
--- xkb/Makefile.am.orig	2017-03-16 05:24:43 UTC
7
+++ xkb/Makefile.am
8
@@ -39,4 +39,4 @@ libxkbstubs_la_SOURCES = ddxVT.c ddxPriv
9
 EXTRA_DIST = xkbDflts.h xkbgeom.h xkb.h
10
 
11
 xkbcompileddir = $(XKB_COMPILED_DIR)
12
-dist_xkbcompiled_DATA = README.compiled
13
+#dist_xkbcompiled_DATA = README.compiled
(-)x11-servers/xorg-server/pkg-plist (-3 / +6 lines)
Lines 1-6 Link Here
1
bin/X
1
bin/X
2
%%SUID%%@(,,4555) bin/Xorg
2
bin/Xorg
3
%%NO_SUID%%bin/Xorg
3
%%SUID%%@(,,4555) bin/Xorg.wrap
4
bin/cvt
4
bin/cvt
5
bin/gtf
5
bin/gtf
6
include/xorg/BT.h
6
include/xorg/BT.h
Lines 159-165 Link Here
159
include/xorg/xorg-server.h
159
include/xorg/xorg-server.h
160
include/xorg/xorgVersion.h
160
include/xorg/xorgVersion.h
161
include/xorg/xserver-properties.h
161
include/xorg/xserver-properties.h
162
@comment include/xorg/xserver_poll.h
162
include/xorg/xserver_poll.h
163
include/xorg/xvdix.h
163
include/xorg/xvdix.h
164
include/xorg/xvmcext.h
164
include/xorg/xvmcext.h
165
lib/xorg/modules/drivers/modesetting_drv.so
165
lib/xorg/modules/drivers/modesetting_drv.so
Lines 177-182 Link Here
177
lib/xorg/protocol.txt
177
lib/xorg/protocol.txt
178
libdata/pkgconfig/xorg-server.pc
178
libdata/pkgconfig/xorg-server.pc
179
man/man1/Xorg.1.gz
179
man/man1/Xorg.1.gz
180
%%SUID%%man/man1/Xorg.wrap.1.gz
180
man/man1/Xserver.1.gz
181
man/man1/Xserver.1.gz
181
man/man1/cvt.1.gz
182
man/man1/cvt.1.gz
182
man/man1/gtf.1.gz
183
man/man1/gtf.1.gz
Lines 183-189 Link Here
183
man/man4/exa.4.gz
184
man/man4/exa.4.gz
184
man/man4/fbdevhw.4.gz
185
man/man4/fbdevhw.4.gz
185
man/man4/modesetting.4.gz
186
man/man4/modesetting.4.gz
187
%%SUID%%man/man5/Xwrapper.config.5.gz
186
man/man5/xorg.conf.5.gz
188
man/man5/xorg.conf.5.gz
187
man/man5/xorg.conf.d.5.gz
189
man/man5/xorg.conf.d.5.gz
190
%%UDEV%%share/X11/xorg.conf.d/10-quirks.conf
188
share/aclocal/xorg-server.m4
191
share/aclocal/xorg-server.m4
189
@dir etc/X11/xorg.conf.d
192
@dir etc/X11/xorg.conf.d
(-)x11-servers/xorg-vfbserver/Makefile (-17 lines)
Lines 2-8 Link Here
2
# $FreeBSD$
2
# $FreeBSD$
3
3
4
PORTNAME=	xorg-vfbserver
4
PORTNAME=	xorg-vfbserver
5
PORTVERSION=	1.19.1
6
PORTEPOCH=	1
5
PORTEPOCH=	1
7
6
8
COMMENT=	X virtual framebuffer server from X.Org
7
COMMENT=	X virtual framebuffer server from X.Org
Lines 11-40 Link Here
11
10
12
MASTERDIR=	${.CURDIR}/../xorg-server
11
MASTERDIR=	${.CURDIR}/../xorg-server
13
DESCR=		${.CURDIR}/pkg-descr
12
DESCR=		${.CURDIR}/pkg-descr
14
DISTINFO_FILE=	${.CURDIR}/distinfo
15
PATCHDIR=	${.CURDIR}/files
16
13
17
SLAVE_PORT=	yes
14
SLAVE_PORT=	yes
18
OPTIONS_EXCLUDE=DEVD HAL SUID
19
15
20
USE_XORG=	xfont2
21
22
CONFIGURE_ARGS+=--enable-xvfb --disable-dmx --disable-xephyr --disable-xnest \
16
CONFIGURE_ARGS+=--enable-xvfb --disable-dmx --disable-xephyr --disable-xnest \
23
		--disable-xwayland
17
		--disable-xwayland
24
18
25
PLIST_FILES=	bin/Xvfb man/man1/Xvfb.1.gz
19
PLIST_FILES=	bin/Xvfb man/man1/Xvfb.1.gz
26
20
27
EXTRA_PATCHES=	${MASTERDIR}/files/patch-CVE-2017-12176 \
28
		${MASTERDIR}/files/patch-CVE-2017-12177 \
29
		${MASTERDIR}/files/patch-CVE-2017-12178 \
30
		${MASTERDIR}/files/patch-CVE-2017-12179 \
31
		${MASTERDIR}/files/patch-CVE-2017-12183 \
32
		${MASTERDIR}/files/patch-CVE-2017-1218x \
33
		${MASTERDIR}/files/patch-CVE-2017-1218y \
34
		${MASTERDIR}/files/patch-CVE-2017-13721 \
35
		${MASTERDIR}/files/patch-CVE-2017-13723 \
36
		${MASTERDIR}/files/patch-os_io.c
37
38
do-install:
21
do-install:
39
	cd ${WRKSRC}/hw/vfb; DESTDIR=${STAGEDIR} ${MAKE} install
22
	cd ${WRKSRC}/hw/vfb; DESTDIR=${STAGEDIR} ${MAKE} install
40
23
(-)x11-servers/xorg-vfbserver/distinfo (-3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484389062
2
SHA256 (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 79ae2cf39d3f6c4a91201d8dad549d1d774b3420073c5a70d390040aa965a7fb
3
SIZE (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 6041792
(-)x11-servers/xwayland/Makefile (-20 / +3 lines)
Lines 1-7 Link Here
1
# $FreeBSD$
1
# $FreeBSD$
2
2
3
PORTNAME=	xwayland
3
PORTNAME=	xwayland
4
PORTVERSION=	1.19.1
5
4
6
COMMENT=	X Clients under Wayland
5
COMMENT=	X Clients under Wayland
7
6
Lines 13-44 Link Here
13
12
14
MASTERDIR=	${.CURDIR}/../xorg-server
13
MASTERDIR=	${.CURDIR}/../xorg-server
15
DESCR=		${.CURDIR}/pkg-descr
14
DESCR=		${.CURDIR}/pkg-descr
16
DISTINFO_FILE=	${.CURDIR}/distinfo
17
PATCHDIR=	${.CURDIR}/files
18
15
19
SLAVE_PORT=	yes
16
SLAVE_PORT=	yes
20
OPTIONS_EXCLUDE=DEVD HAL SUID
17
USE_XORG=	x11 xext
21
22
USE_XORG=	x11 xext xfont2
23
USE_GL+=	egl gbm
18
USE_GL+=	egl gbm
24
19
25
CONFIGURE_ARGS+=	--disable-docs --disable-devel-docs \
20
CONFIGURE_ARGS+=--disable-dmx --disable-xephyr --disable-xnest --disable-xvfb \
26
			--enable-xwayland --disable-xorg --disable-xvfb --disable-xnest \
21
		--enable-xwayland 
27
			--disable-xquartz --disable-xwin
28
22
29
PLIST_FILES=	bin/Xwayland
23
PLIST_FILES=	bin/Xwayland
30
24
31
EXTRA_PATCHES=	${MASTERDIR}/files/patch-CVE-2017-12176 \
32
		${MASTERDIR}/files/patch-CVE-2017-12177 \
33
		${MASTERDIR}/files/patch-CVE-2017-12178 \
34
		${MASTERDIR}/files/patch-CVE-2017-12179 \
35
		${MASTERDIR}/files/patch-CVE-2017-12183 \
36
		${MASTERDIR}/files/patch-CVE-2017-1218x \
37
		${MASTERDIR}/files/patch-CVE-2017-1218y \
38
		${MASTERDIR}/files/patch-CVE-2017-13721 \
39
		${MASTERDIR}/files/patch-CVE-2017-13723 \
40
		${MASTERDIR}/files/patch-os_io.c
41
42
do-install:
25
do-install:
43
	cd ${WRKSRC}/hw/xwayland; DESTDIR=${STAGEDIR} ${MAKE_CMD} install
26
	cd ${WRKSRC}/hw/xwayland; DESTDIR=${STAGEDIR} ${MAKE_CMD} install
44
27
(-)x11-servers/xwayland/distinfo (-3 lines)
Lines 1-3 Link Here
1
TIMESTAMP = 1484388904
2
SHA256 (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 79ae2cf39d3f6c4a91201d8dad549d1d774b3420073c5a70d390040aa965a7fb
3
SIZE (xorg/xserver/xorg-server-1.19.1.tar.bz2) = 6041792

Return to bug 196678