Commit Graph

745 Commits

Author SHA1 Message Date
Alan Coopersmith
0e8c0d2f23 ospoll: Fix Solaris ports implementation to build on Solaris 11.4
Wrong version got committed, but wasn't noticed since it only builds
with meson, not autoconf.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-09-23 15:12:01 -07:00
Adam Jackson
7d0e660e0e meson: Add dtrace support 2019-08-27 17:38:59 -04:00
Adam Jackson
7968d10fad dtrace: Move Xserver.d from dix/ to include/
dix/ is typically not in the include path, and this properly belongs in
include anyway since it's needed from os/ too.
2019-08-27 17:38:54 -04:00
Jon Turney
a026972776 Clarify authorization failure reason strings sent back to the client 2019-07-23 19:50:25 +00:00
Jon Turney
7b4b030df8 configure: Check for sigprocmask
MinGW defines SIG_BLOCK, but doesn't have signal masks, so rather than
checking for SIG_BLOCK, add a configure check for sigprocmask.

v2:
Also add check to meson.build
2019-05-18 14:59:38 +00:00
Jon Turney
6c5d048095 os: Fix build of xserver_poll.c on MinGW
Include winsock.h for definition of fd_set type and select()

Future work: Maybe this also needs some error checking for fd > FD_SETSIZE?
2019-05-18 14:59:38 +00:00
Topi Miettinen
bb46e78540 os: add support for systemd notification
It can take some time for Xorg to start. If Xorg runs as a systemd
service and other services are based on it, they have no way to
determine when Xorg is really ready to accept requests. Let's use
sd_notify() provided by libsystemd to signal systemd for readiness.
If Xorg has not been started as a systemd service, this won't do
anything.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
2019-05-07 09:01:47 +03:00
Jon Turney
655b1eb32e meson: Convert xquartz from autotools
Differences from autotools:

* Autotools defined NO_ALLOCA for OSX builds.  I don't think we need
this anymore as Xalloc.h is no longer used anywhere in the xserver.

* X11.bin is linked with -u,miDCInitialize, and then libserver_mi
provided to satisfy (just) that.  It's been that way since the commit
which added it.  We can't write the equivalent in meson due to linker
argument ordering issues, but do we really need to?

* An explicit -Dsecure-rpc=false is required for OSX, since in meson we
don't do the checks that XTRANS_SECURE_RPC_FLAGS did for the existence
of the specific RPC functions required.
2019-05-02 15:42:58 +00:00
Jon Turney
d3a528c91e Remove unneeded include of dix.h from strcasestr.c
In the meson build, functions to make up for the shortcomings of libc
are compiled into a separate library. We don't bother making the pixman
headers available (reasonably enough) to this compilation, but they are
required indirectly by dix.h.  Just remove this unneeded include.
2019-04-30 20:07:51 +00:00
Alan Coopersmith
4ad21c3247 Add ddxInputThread call from os layer into ddx layer
Allows ddx's to run additional code as necessary to set up the
input thread.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-02-25 15:48:03 +00:00
Peter Harris
937a5b78a2 os: Fix GetTimeInMicros resolution
GetTimeInMillis is called first, which sets clockid to
CLOCK_MONOTONIC_COARSE, which is typically much lower resolution than
the callers of GetTimeInMicros want.

Prior to a779fda224, GetTimeInMillis and
GetTimeInMicros did not share a clockid.

Restore the clockid split to fix the granularity of GetTimeInMicros.

Signed-off-by: Peter Harris <pharris@opentext.com>
2019-01-30 14:56:46 -05:00
Alan Coopersmith
7fb6338c68 os: Report errors opening authorization file (#469)
Fixes: xorg/xserver#469

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2019-01-01 16:50:24 -08:00
Adam Jackson
23752b3ef8 os: Establish new connections synchronously not on the work queue
This contortion made a bit more sense before we got SetNotifyFd and
friends, but now there's no need for it.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-11-13 10:36:40 -05:00
Matthieu Herrb
248d164eae LogFilePrep: add a comment to the unsafe format string.
CVE-2018-14665 also made it possible to exploit this to access
memory. With -logfile forbidden when running with elevated privileges
this is no longer an issue.

Signed-off-by: Matthieu Herrb <matthieu@herrb.eu>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-10-25 09:17:11 -04:00
Andreas Fett
08ff37d05a os/xdmcp: Fix binding of ipv6 source address
Choose the socket fd of the correct address family based
on the address family of the argument to the -from option.

Fixes: xorg/xserver#4
2018-10-24 19:29:29 +00:00
Adam Jackson
53d32c94f3 dix: Remove the magic WhenMapped backing store hack
Automatic compositing exists, if that's what you want then use it.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-10-23 18:37:46 +00:00
Alexander Volkov
32677ce03d os/xdmcp: Don't create a new socket in XdmcpReset()
xdmcpSocket survives during the reset, there is no
need to create a new one.

This commit restores logic that was broken by
49c0f2413d in Xorg 1.19.

Signed-off-by: Alexander Volkov <a.volkov@rusbitech.ru>
2018-10-03 17:46:15 +00:00
Adam Jackson
a23eba2a91 dix: Merge AbortDDX into ddxGiveUp
These are so close to identical that most DDXes implement one in terms
of the other. All the relevant cases can be distinguished by the error
code, so merge the functions together to make things simpler.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-09-28 16:25:12 -04:00
Adam Jackson
3a4d7c79e7 dix: Remove MaxClients
This variable was no longer being read anywhere. MAXCLIENTS the macro is
the compile-time maximum limit, LIMITCLIENTS the macro is the default
limit, LimitClients the variable is the limit for the current server.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-09-12 19:31:07 +00:00
Eric Anholt
4ba7866770 meson: Get close to parity with autotools for CLIENTIDS tracking.
The client ID is only needed for XRes, and autotools build ignores the
--clientids= arg if xres is disabled.  We haven't made a meson option
for disabling tracking client ids (is it actually worth a build
option?), so just make this depend on xres.

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-08-09 13:42:54 -04:00
Lyude Paul
d95a1310ef meson: ensure the libc has RPC functions when secure-rpc is enabled
Currently our meson.build just makes the assumption that the libc is
going to provide RPC functions. This doesn't actually seem to be the
case on Fedora, which causes compilation to fail unexpectedly:

../../Projects/xserver/os/rpcauth.c:47:10: fatal error: rpc/rpc.h: No such file or directory
 #include <rpc/rpc.h>
          ^~~~~~~~~~~
compilation terminated.

So, in the event that we can't use libtirpc ensure that we actually
check whether or not the libc provides rpc/rpc.h. If it doesn't, raise
an error.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Lyude Paul <lyude@redhat.com>
2018-07-03 17:13:38 -04:00
Damien Leone
f33cb42643 os: Recompute whether any clients are ready after check_timers()
If a driver calls AttendClient() from within a timer callback we
need to re-compute the local 'are_ready' to prevent the attended
client from waiting until WaitForSomething() times out.

This is a fix similar to commit 9ed5b263.

Signed-off-by: Damien Leone <dleone@nvidia.com>
Reviewed-by: Keith Packard <keithp@keithp.com>
2018-06-26 17:03:32 -07:00
Chris Wilson
1e9d5533e3 os/WaitFor: Use the simpler xorg_list_for_each_entry()
As we are not freeing elements while iterating the list of timers, we
can forgo using the safe variant, and reduce the number of pointer
dances required for the insertion sort.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2018-05-21 13:52:13 -04:00
Chris Wilson
6115d8b40c os/WaitFor: Use xorg_list_append()
Currently, we use xorg_list_add(new, head->prev) which is functionaly
equivalent to xorg_list_append(), but with more pointer chasing, so
reduce the strain on the reader and compiler by using the simpler
append().

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2018-05-21 13:52:09 -04:00
Chris Wilson
ac7a4bf44c os/WaitFor: Check timers on every iteration
Currently we only check timer expiry if there are no client fd (or
other input) waiting to be serviced. This makes it very easy to starve
the timers with long request queues, and so miss critical timestamps.

The timer subsystem is just another input waiting to be serviced, so
evaluate it on every loop like all the others, at the cost of calling
GetTimeInMillis() slightly more frequently. (A more invasive and likely
OS specific alternative would be to move the timer wheel to the local
equivalent of timerfd, and treat it as an input fd to the event loop
exactly equivalent to all the others, and so also serviced on every
pass. The trade-off being that the kernel timer wheel is likely more
efficiently integrated with epoll, but individual updates to each timer
would then require syscalls.)

Reviewed-by: Peter Harris <pharris@opentext.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
2018-04-17 16:30:36 -04:00
Thierry Reding
f3b0a2aee2 meson: Remove usage of pkg-config --variable=includedir
Querying a pkg-config variable using the --variable option produces the
value of the given variable as stored in the pkg-config file and should
not be used to add directories to the include search path.

The reason for this is that it breaks cross-compilation, because header
files are installed relative to the host sysroot. pkg-config supports a
PKG_CONFIG_SYSROOT_DIR environment variable that points to this sysroot
and will prepend that to the path of directories in -I or -L options in
pkg-config's Cflags, Libs or Libs.private keywords. However, because no
context can be inferred from variable names, as opposed to the keywords
with fixed meaning, the sysroot path will not be prepended to them. The
build system is responsible for doing so if necessary since it is aware
of the context in which the variable is used.

Adding the include directory returned by pkg-config to the include path
leaks build system information into the cross-build and break with very
confusing errors such as this:

	In file included from include/misc.h:82:0,
			 from dix/atom.c:55:
	/usr/include/pthread.h:682:6: warning: '__regparm__' attribute directive ignored [-Wattributes]
	      __cleanup_fct_attribute;
	      ^~~~~~~~~~~~~~~~~~~~~~~

or this:

	In file included from include/misc.h:139:0,
			 from dix/atom.c:55:
	/usr/include/stdlib.h:133:8: error: '_Float128' is not supported on this target
	 extern _Float128 strtof128 (const char *__restrict __nptr,
		^~~~~~~~~

Fix this by replacing the include directory with the appropriate xproto
dependency required to add the correct include directory to the compile
command for subdirectories that are missing the dependency. As detailed
above, this gives pkg-config the opportunity to prepend the sysroot for
all paths in -I compiler options.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
2018-04-02 13:42:02 -04:00
Antoine Martin
c95361465e os: Fix -logfile when used with -displayfd
Trivial way to reproduce the bug:

$ Xorg -logfile /tmp/mylog -config /etc/xpra/xorg.conf -displayfd 2

The server then moans:

Failed to rename log file "/tmp/mylog" to "/tmp/mylog": No such file or directory

And the log file is created but immediately renamed to "/tmp/mylog.old".
This is caused by the changes to the log file handling introduced by
this commit:

https://cgit.freedesktop.org/xorg/xserver/commit/?id=edcb6426f20c3be5dd5f50b76a686754aef2f64e

To fix this, only rename the logfile if the log filename contains the
magic substitution string "%s".

Signed-off-by: Antoine Martin <antoine@nagafix.co.uk>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2018-03-28 15:16:02 -04:00
Nicolai Hähnle
1b6910af12 os: use PrivsElevated instead of a manual check
Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Ben Crocker <bcrocker@redhat.com>
Reviewed-by: Antoine Martin <antoine@nagafix.co.uk>
Tested-by: Ben Crocker <bcrocker@redhat.com>
2018-03-21 10:58:40 -04:00
Nicolai Hähnle
9ef602de46 os: move xf86PrivsElevated here
Having different types of code all trying to check for elevated privileges
is a bad idea. This implementation is the most thorough one.

Signed-off-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Ben Crocker <bcrocker@redhat.com>
Reviewed-by: Antoine Martin <antoine@nagafix.co.uk>
Tested-by: Ben Crocker <bcrocker@redhat.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2018-03-21 10:58:39 -04:00
Adam Jackson
f69cd2024e os: Define {ReadFdFrom,WriteFdTo}Client unconditionally
Otherwise this is broken on cygwin:

    rrlease.c: In function ‘ProcRRCreateLease’:
    rrlease.c:305:9: error: implicit declaration of function ‘WriteFdToClient’ [-Werror=implicit-function-declaration]
         if (WriteFdToClient(client, fd, TRUE) < 0) {

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-03-08 14:12:36 -05:00
Jeffrey Smith
272fa18170 os: avoid uninitialized offsets in backtrace
When xorg_backtrace calls unw_get_proc_name and an error occurs, offset
might not be set for the current frame.

Initialize offset for each frame so that the offset from another frame
cannot be used inadvertently.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-02-19 13:12:18 -05:00
Jeff Smith
510e7d0d86 os: Always return microseconds from GetTimeInMicros()
When a monotonic clock is not available, GetTimeInMicros() returns the
time in nanoseconds.  Instead, return the time in microseconds, as the
name indicates.

Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-01-31 16:02:39 -05:00
Michal Srb
71348e99a8 os/inputthread: Force unlock when stopping thread.
The inputthread is kept locked all the time while X server's VT is not active.
If the X server is terminated while not active, it will be stuck forever in
InputThreadFini waiting for the thread to join, but it wouldn't because it is
locked.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=103782
Signed-off-by: Michal Srb <msrb@suse.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-01-24 16:27:31 -05:00
Jon Turney
514d2c243e meson: Use and prefer tirpc for Secure RPC authentication
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-01-22 13:15:10 -05:00
Adam Jackson
c3fbe2bbff meson: Enable SUN-DES-1 auth code
Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
2018-01-16 16:04:39 -05:00
Adam Jackson
652913cd94 os: Fix a type error in the IPv6 XDMCP code
Building with strict-aliasing rightly chirps here:

../os/xdmcp.c: In function ‘XdmcpRegisterConnection’:
../os/xdmcp.c:489:31: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
                     &((struct sockaddr_in6 *) &address)->sin6_addr.s6_addr[12];
                               ^~~~~~~~~~~~

We have "const char *address", so &address here is a char ** (i.e., it
points to the slot on the stack containing the pointer to the character
array passed in as an argument). Casting that to a struct sockaddr_in6 *
is wrong, because it means that area of the stack will be reinterpreted
as a struct sockaddr_in6.

Instead, cast address, not &address.

Signed-off-by: Adam Jackson <ajax@redhat.com>
2018-01-08 16:19:42 -05:00
Peter Harris
edda951fa5 os: Add epoll-like port implementation for Solaris
x11perf -noop with 200 xlogos connected is slightly faster with ports:

  before           after         Operation
----------   -----------------   --------------------
18400000.0   19200000.0 (1.04)   X protocol NoOperation

Acked-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Peter Harris <pharris@opentext.com>
2017-12-13 11:19:09 -05:00
Peter Harris
83c04ee6ea os: Add epoll-like pollset implementation for AIX
AIX's poll only allows FD_SETSIZE entries in the fd list, which is
insufficient for expanded MaxClients.

As a bonus, x11perf -noop with ~250 xlogos connected is slightly faster
with pollset:

 before          after         Operation
---------   ----------------   --------------------
5750000.0   5990000.0 (1.04)   X protocol NoOperation

Signed-off-by: Peter Harris <pharris@opentext.com>
Acked-by: Keith Packard <keithp@keithp.com>
2017-12-13 11:18:07 -05:00
Adam Jackson
9c72887939 os: Make OsSignalHandler ask for core dumps for signo != SIGQUIT
SIGQUIT is a normal termination request, but any other signal we handle
here wants a core. This has the effect of making FatalError's call to
AbortServer trigger the

    if (CoreDump)
        OsAbort();

path. This will allow us to remove some DDX code that has the same net
effect.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Olivier Fourdan <ofourdan@redhat.com>
Reviewed-by: Dave Airlie <airlied@redhat.com>
2017-12-13 11:11:42 -05:00
Tomasz Śniatowski
6883ae43eb os: Fix strtok/free crash in ComputeLocalClient
Don't reuse cmd for strtok output to ensure the proper pointer is
freed afterwards.

The code incorrectly assumed the pointer returned by strtok(cmd, ":")
would always point to cmd. However, strtok(str, sep) != str if str
begins with sep. This caused an invalid-free crash when running
a program under X with a name beginning with a colon.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=104123
Signed-off-by: Tomasz Śniatowski <kailoran@gmail.com>
Reviewed-by: Michel Dänzer <michel.daenzer@amd.com>
2017-12-13 09:54:14 -05:00
Daniel Martin
918afeecbc os/xdmcp: Honour -once when session is dead
Terminate a dead session when -once was passed. Don't restart it.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Walter Harms <wharms@bfs.de>
2017-11-29 14:50:12 -05:00
Adam Jackson
4d15a2645f os: Remove mffs()
This was always wide enough to work on an fd_mask ("mask" ffs
presumably). We don't operate on fd_masks anymore, so this can go.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2017-11-06 17:22:46 -05:00
Daniel Martin
d5379b350f Use ARRAY_SIZE all over the tree
Roundhouse kick replacing the various (sizeof(foo)/sizeof(foo[0])) with
the ARRAY_SIZE macro from dix.h when possible. A semantic patch for
coccinelle has been used first. Additionally, a few macros have been
inlined as they had only one or two users.

Signed-off-by: Daniel Martin <consume.noise@gmail.com>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2017-10-30 13:45:20 -04:00
Michal Srb
9c23685009 os: Make sure big requests have sufficient length.
A client can send a big request where the 32B "length" field has value
0. When the big request header is removed and the length corrected,
the value will underflow to 0xFFFFFFFF.  Functions processing the
request later will think that the client sent much more data and may
touch memory beyond the receive buffer.

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-10-09 17:08:33 -07:00
Adam Jackson
aabf65d2a0 os: Fix warning in LockServer
The meson build gives me:

../os/utils.c: In function ‘LockServer’:
../os/utils.c:310:40: warning: ‘snprintf’ output may be truncated before the last format character [-Wformat-truncation=]
     snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
                                        ^~~~~~~~~
../os/utils.c:310:5: note: ‘snprintf’ output between 12 and 13 bytes into a destination of size 12
     snprintf(pid_str, sizeof(pid_str), "%10ld\n", (long) getpid());
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Which seems to be due to the %d part meaning that a negative number's -
sign would be one wider than we're expecting. Fine, just coerce it to
unsigned.

Signed-off-by: Adam Jackson <ajax@redhat.com>
Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2017-08-30 15:53:04 -04:00
Emil Velikov
1ef6569225 os: make MitGenerateCookie() independent of XCSECURITY
Analogous to previous commit.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-08-22 10:59:40 -04:00
Emil Velikov
292ee71516 os: make GenerateRandomData() independent of XCSECURITY
The function itself does not depend on the macro. Move it outside
of the ifdef guard and remove the identical copy in XWIN.

This is step 1 towards removing the duplication in winauth.c and moving
the OS specifics to os/

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Jon Turney <jon.turney@dronecode.org.uk>
2017-08-22 10:59:40 -04:00
Peter Harris
c52f77e4ca meson: Fix epoll detection
The epoll code depends on epoll_create1, not epoll_create.

Signed-off-by: Peter Harris <pharris@opentext.com>
Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Eric Anholt <eric@anholt.net>
2017-08-14 13:34:11 -07:00
Keith Packard
f3689f637f os: Set oc->fd to -1 when connection is closed
This ensures that we don't use the now-closed file descriptor in the
future.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2017-06-13 09:56:44 -04:00
Keith Packard
d05c754e1b os: Check oc->trans_conn before using oc->fd in YieldControlNoInput
oc->trans_conn is set to NULL when the connection is closed. At this
point, oc->fd is no longer valid and shouldn't be used. Move
dereference of oc->fd up into YieldControlNoInput where the state of
oc->trans_conn can be checked in a single place.

Reviewed-by: Adam Jackson <ajax@redhat.com>
Signed-off-by: Keith Packard <keithp@keithp.com>
2017-06-13 09:56:41 -04:00