Commit Graph

1384 Commits

Author SHA1 Message Date
Chrissie Caulfield
08a165dc2c
test: Add unit test for ipcs_connection_auth_set() (#397)
Only if we are root
2020-06-03 08:26:51 +01:00
Chrissie Caulfield
49641930d8
log: Fix threading races (#396)
It's possible that cs->filename or cs->format could be read
in the 'fast' path while the 'slow' path is still constructing
the object. So we need to lock arr_next_lock before copying them
out for the caller.

Also wthread_should_exit was unprotected.
2020-06-01 15:41:26 +01:00
Chrissie Caulfield
bdc716036a
Some bugs spotted by coverity (#399) 2020-05-28 07:30:26 +01:00
Jan Pokorný
803d9242ff log: journal: fix forgotten syslog reload when flipped from journal
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2020-05-04 08:32:47 +01:00
Ferenc Wágner
2baa2791ce Let remote_tempdir() assume a NUL-terminated name
This is the case already.  We also fix a buffer overflow opportunity in
the memcpy() call by this change.

Conflicts:
	lib/ipc_shm.c
2020-05-01 12:57:51 +01:00
Ferenc Wágner
e26ad0dae1 Make it impossible to truncate or overflow the connection description
It's hard to predict the length of formatted output, so we'd better
notice (and abort) if the description is truncated.  Incidentally,
mkdtemp() does this for us in the shared memory branch, but do an
explicit check there as well for consistency, and get rid of the wrongly
parametrized strncat() risking a buffer overflow (CONNECTION_DESCRIPTION
is not the length of the source "/qb").

Similar truncation checks should be added to qb_ipcs_{shm,us}_connect()
where they build the request/response names, and possibly to other
places using snprintf().
2020-05-01 12:54:30 +01:00
Chris Murphy
08806c5301
master: Issue 390: Clarify documentation of qb_loop_timer_expire_time_get and provide new function to return previously documented behavior (#391)
Includes unit test addition by chrissie-c
2020-04-29 13:20:52 +01:00
Fabio M. Di Nitto
93f9975617
Doxygen2man (#388)
* doxygen2man: Add utility to generate man pages from doxygen

This is in here from kronosnet so it cna be used by other parts
of the cluster stack.

* [man] drop trailing white spaces

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

* [build] cleanup variable names

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

* [build] add conditionals to use internal or external doxygen2man

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

* Update .gitignore

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>

Co-authored-by: Christine Caulfield <ccaulfie@redhat.com>
2020-03-18 10:29:38 +01:00
Chrissie Caulfield
1daca57c10
trie: Don't assume that chars are unsigned < 126 (#386)
* trie: Don't assume that chars are unsigned < 126

Trie fails on systems with unsigned chars when using characters over
126.
2020-03-09 08:14:39 +00:00
Jan Friesse
9249caf516
qblist: Retype ptr in qb_list_entry to char* (#385)
This allows pointer arithmetics without issuing warning.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
2020-02-26 08:52:19 +00:00
Chrissie Caulfield
f54d150619
list: #include <stddef.h> in qblist.h (#384)
Some platforms require it.
2020-02-21 08:44:34 +00:00
Chrissie Caulfield
7f4600de1b
list: fix list handling for gcc10 (#383)
-Wpointer-arith has been removed from warnings as with GCC10 that warns every time qb_list_entry is used, which is just noise.
2020-02-20 14:29:33 +00:00
Jonas Witschel
99671f4d75 Set correct ownership if qb_ipcs_connection_auth_set() has been used
When qb_ipcs_connection_auth_set() has been used, the ownership of the
temp directory initially set by handle_new_connection() must be updated
as well.
2020-02-10 11:21:45 +01:00
Ferenc Wágner
700fb2b27e Allow group access to the IPC directory
And don't abort if we aren't permitted to chown() it.  The client might
still have the privileges to enter it.
2020-02-10 10:57:16 +01:00
Ferenc Wágner
a8301de262 Errors are represented as negative values 2020-02-10 10:57:01 +01:00
Jan Pokorný
7f891f0069 build: allow for possible v1 branch continuity by generous SONAME offset
The main and the most ABI-touching thing for the envisioned 2.0 branch
is the usage of the linker-build-time allocated callsite info, avoiding
the non-economic evaluations and, under some circumstances dangerous,
heap allocations in the run-time.

Considering that v1.9.0 release (libqb.so.20) was expressly marked as
tech-preview[1,2] (hence something that shall not make it to production
use), there should be no harm for master branch (that is headed towards
2.0 and beyond) to receive noticable SONAME bump (libqb.so.100) so as to

- leave enough of space for a possible v1-compatible branch evolution
  (for use cases where recompile-everything is a no-go).
  in particular, with resuming with libqb.so.30, there would
  be a room for 99-33 = 63 add-new-drop-nothing compatible
  changes for that branch (which is more than plentiful)

- indicate some big change is going on more clearly towards client space

This is supposed to be a reasonable trade-off solution that would still
leave enough wiggle space, and would represent responsible approach to the
development (like the original attempt to prevent ABI break in the first
place was), allowing for more than an enforced unanimity (rather
antagonistic in the free software realms).

[1] https://lists.clusterlabs.org/pipermail/users/2019-December/026690.html
[2] https://github.com/ClusterLabs/libqb/releases/tag/1.9.0

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2020-01-10 12:27:35 +00:00
Jan Pokorný
e830a6805c
build: bump version for inter-release "plain repo" generated tarballs
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2020-01-07 16:25:39 +01:00
Fabio M. Di Nitto
c1bca92c89
[build] chown the right file
Closes: #377
Also, for original issue, closes: #375

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
Reviewed-by: Jan Pokorný <jpokorny@redhat.com>
2020-01-07 16:23:14 +01:00
Fabio M. Di Nitto
0f67f84813 [build] fix configure.ac in release tarball
only mingle with configure.ac if configure.ac-t exists

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2020-01-06 15:15:45 +00:00
Chrissie Caulfield
51a03aa9c6 make: Remove splint tests (#374)
Now that splint is actually contradicting errors that come from
the compilers I think it's time to retire it. I could cope with it
being a minor nuisance on the argument that "another check can't
hurt", but contradicting the actual compilers is too much.

The CI has Coverity installed which is much more up-to-date anyway.
Splint hasn't been updated since 2010
2019-12-11 18:46:22 +01:00
Christine Caulfield
3da80822b2 lib: Fix some minor warnings from newer compilers
and doxygen
2019-12-11 11:14:47 +00:00
Chrissie Caulfield
33b79ebc47 tests: Shorted deadlock test names (#372)
On newer Fedora systems that can have 32 bit PIDs, these long test
names can get truncated in the libqb internal buffers and thus break the
tests, so I've shortened the names.
2019-12-06 14:38:02 +01:00
Jan Friesse
302b564834 ipc: Always initialize response struct
Response structure was not initialized completely,
when mkdtemp/chown failed, server was not accepting connection yet or
connect failed for some reason.

This is not an issue, but valgrind reports this
as a problem so it is easy to miss real problem then.

Solution is to initialize response before it is used.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
2019-11-08 08:54:04 +00:00
Fabio M. Di Nitto
16abeeb920
[build] add --with-sanitizers= option for sanitizer builds (#366)
this option is stricly meant for runtime debugging purposes.
do NOT use in production.

check gcc/clang man pages on how to use ASAN/UBSAN/TSAN.

Also allow to users to specificy SANITIZERS_CFLAGS and SANITIZERS_LDFLAGS
for advanced use.

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-10-09 11:20:11 +02:00
Jan Pokorný
484fddddb8 ringbuffer: fix mistaken errno handling around _rb_chunk_reclaim
Previously, there were two separate logical issues:

- errno could be set negative in qb_rb_chunk_alloc when
  when "reclaim" notifier failed

- _rb_chunk_reclaim (note: local scoped, hence comfortable for changes)
  was already setting errno at a single (coincidentally, in a correct
  way, but that'd be overwritten with the inverse because of the
  previous logical issue in qb_rb_chunk_alloc), so make it set errno
  at each failure path (now also when internal integrity in
  _rb_chunk_reclaim failed(), sparing the callers to double on that task

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-07-26 09:39:58 +01:00
Ken Gaillot
aad74c7e39 array,log: Never set errno to a negative value
These are clearly a logical mistake due to the standard practice of returning
-errno on error, but errno itself should never be negative.
2019-07-26 09:39:58 +01:00
Ken Gaillot
7dc8d386fc log: Set errno when qb_log_target_alloc() fails
The callers of qb_log_target_alloc() return -errno when it fails.
However, qb_log_target_alloc() wasn't setting errno.

The only failure case is when QB_TARGET_LOG_MAX (32) logs have been opened, so
it's unlikely to ever be a real-world problem. But in that case, now set errno
to EMFILE ("Too many open files").
2019-07-26 09:39:58 +01:00
Christine Caulfield
9526df0c11 ipc: Remove kqueue EOF log message
It's not logged for epoll systems and just clutters up logs
and slows things down without telling us anything useful.
2019-06-27 13:19:08 +01:00
Christine Caulfield
8e50d0a4f1 tests: Speed up IPC tests, especially on FreeBSD
After much discussion on IRC it was decided that 70000 iterations
of the stress patch didn't achieve anything significant over a
reasonable but smaller number. So it has been reduced to 5000 on
all platforms.

This patch also fixes a bug where test_ipc_disconnect_after_created
committed a use-after-free which could cause a crash on FreeBSD-devel.
2019-06-27 13:19:08 +01:00
Christine Caulfield
f1bf5d9da3 ipc: fix force-filesystem-sockets
the /etc/libqb/force-filesystem-sockets option got broken for some
applications in the last security update.
2019-06-24 13:29:34 +01:00
Jan Friesse
ed29f84ab6 ipc: Fix named socket unlink on FreeBSD
Terminating NUL on FreeBSD is not part of the sun_path.
Add it to use sun_path as a parameter of unlink.

Signed-off-by: Jan Friesse <jfriesse@redhat.com>
2019-06-20 08:41:42 +01:00
Jan Pokorný
d5adc0cbc8
tests: ipc: fix the no-GLib conditionalizing
In particular, qb_ipcs_rate_limit() needs to be outside the
"#ifdef HAVE_GLIB" conditional, since it gets used regardless.
This should have been like this as of 28e7259.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-12 16:54:22 +02:00
Jan Pokorný
b46a5745ef
CI: travis: add (redundant for now, but...) libglib2.0-dev prerequisite
We want to run every and each test we can, without reliance on
transitive deoendencies and environment "invariants".

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-07 17:37:32 +02:00
Jan Pokorný
7f0dc55b8f
doc: qbloop.h: document pros/cons of using built-in event loop impl
Make the qbipcs.h module interdependence clear (also shedding light to
some semantic dependencies) as well.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-07 17:37:23 +02:00
Jan Pokorný
83da9f2109
IPC: server: fix debug message wrt. what actually went wrong
It's misleading towards a random code observer, at least,
hiding the fact that what failed is actually the queing up
of some handling to perform asynchronously in the future,
rather than invoking it synchronously right away.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-05 10:38:32 +02:00
Jan Pokorný
97adfa6ba0
IPC: server: avoid temporary channel priority loss, up to deadlock-worth
It turns out that while 7f56f58 allowed for less blocking (thus
throughput increasing) initial handling of connections from clients
within the abstract (out-of-libqb managed) event loop, it unfortunately
subscribes itself back to such polling mechanism for UNIX-socket-check
with a default priority, which can be lower than desired (via explicit
qb_ipcs_request_rate_limit() configuration) for particular channel
(amongst attention-competing siblings in the pool, the term here
refers to associated communication, that is, both server and
on-server abstraction for particular clients).  And priority-based
discrepancies are not forgiven in true priority abiding systems
(that is, unlikele with libqb's native event loop harness as detailed
in the previous commit, for which this would be soft-torelated hence
the problem would not be spotted in the first place -- but that's
expliicitly excluded from further discussion).

On top of that, it violates the natural assumption that once (single
threaded, which is imposed by libqb, at least between initial accept()
and after-said-UNIX-socket-check) server accepts the connection, it
shall rather take care of serving it (at least within stated initial
scope of client connection life cycle) rather than be rushing to accept
new ones -- which is exactly what used to happen previously once the
library user set the effectively priority in the abstract poll
above the default one.

It's conceivable, just as with the former case of attention-competing
siblings with higher priority whereby they could _infinitely_ live on
at the expense of starving the client in the initial handling phase
(authentication) despite the library user's as-high-as-siblings
intention (for using the default priority for that unconditionally
instead, which we address here), the dead lock is imminent also in
this latter accept-to-client-authentication-handling case as well
if there's an _unlimited_ fast-paced arrival queue (well, limited
by with number of allowable open descriptors within the system,
but for the Linux built-in maximum of 1M, there may be no practical
difference, at least for time-sensitive applications).

The only hope then is that such dead-locks are rather theoretical,
since a "spontaneous" constant stream of either communication on
unrelated, higher-prio sibling channels, or of new connection arrivals
can as well testify the poor design of the libqb's IPC application.
That being said, unconditional default priority in the isolated
context of initial server-side client authentication is clearly
a bug, but such application shall apply appropriate rate-limiting
measures (exactly on priority basis) to handle unexpected flux
nonetheless.

The fix makes test_ipc_dispatch_*_glib_prio_deadlock_provoke tests pass.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-05 10:36:55 +02:00
Jan Pokorný
28e725938a
tests: ipc: check deadlock-like situation due to mixing priorities
Compared to the outer world, libqb brings rather unintuitive approach
to priorities within a native event loop (qbloop.h) -- it doesn't do
an exhaustive high-to-low priorities in a batched (clean-the-level)
manner, but rather linearly adds a possibility to pick the handling
task from the higher priority level as opposed to lower priority ones.

This has the advantage of limiting the chances of starvation and
deadlock opportunities in the incorrectly constructed SW, on the other
hand, it means that libqb is not fulfilling the architected intentions
regarding what deserves a priority truthfully, so these priorities are
worth just a hint rather than urgency-based separation.

And consequently, a discovery of these deadlocks etc. is deferred to
the (as Murphy's laws have it) least convenient moment, e.g., when
said native event loop is exchanged for other (this time priority
trully abiding, like GLib) implementation, while retaining the same
basic notion and high-level handling of priorities on libqb
side, in IPC server (service handling) context.

Hence, demonstration of such a degenerate blocking is not trivial,
and we must defer such other event loop implementation.  After this
hassle, we are rewarded with a practical proof said "high-level
handling [...] in IPC server (service handling) context" contains
a bug (which we are going to subsequently fix) -- this is contrasted
with libqb's native loop implementation that works just fine even
prior that fix.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:07:27 +02:00
Jan Pokorný
2ced1b4341
tests: ipc: refactor/split test_ipc_dispatch part into client_dispatch
This way, this core part can be easily reused where needed.
Note that "ready_signaller" similarity with run_ipc_server is not
accidental, following commit will justify it.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:54 +02:00
Jan Pokorný
c54e2712a6
tests: ipc: allow for easier tests debugging by discerning PIDs/roles
Roles specifications are currently not applied and are rather
a preparation for the actual meaningful use to come.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:52 +02:00
Jan Pokorný
c3175eabd3
tests: ipc: speed the suite up with avoiding expendable sleep(3)s
Using i7-6820HQ CPU yields these results:

Before: ~2:54
After: ~2:26
Speedup: ~16%

The main optimization lies in how run_function_in_new_process helper is
constructed, since now, there's an actual synchronization between the
parent and its child (that needs to be prioritized here, which is
furthermore help with making the parent immediately give up it's
processor possession) after the fork, so that a subsequent sleep is
completely omitted -- at worst (unlikely), additional sleep round(s)
will need to be undertaken as already arranged for (and now, just
400 ms is waited rather than excessive 1 second).

Another slight optimization is likewise in omission of sleep where
the control gets returned to once the waited for process has been
suceesfully examined post-mortem, without worries it's previous
life is still resounding.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:48 +02:00
Jan Pokorný
571e162990
tests: ipc: avoid problems when UNIX_PATH_MAX (108) limits is hit
There's some slight reserve for when bigger PID ranges are in use.
The method to yield the limit on prefix string was derived from
practical experience (rather than based on exact calculations).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2019-06-04 13:06:44 +02:00
Ferenc Wágner
d90d45f576 doc: qbarray: reword comment about index partitioning 2019-05-07 14:46:02 +01:00
Ferenc Wágner
5f1b3f57d7 doc: qbarray.h: remove stray asterisk and parentheses 2019-05-07 14:46:02 +01:00
Christine Caulfield
6a4067c1d1 ipc: Use mkdtemp for more secure IPC files
Use mkdtemp makes sure that IPC files are only visible to the
owning (client) process and do not use predictable names outside
of that.

This is not meant to be the last word on the subject, it's mainly a
simple way of making the current libqb more secure. Importantly, it's
backwards compatible with an old server.

It calls rmdir on the directory created by mkdtemp way too often, but
it seems to be the only way to be sure that things get cleaned up on
the various types of server/client exit. I'm sure we can come up with
something tidier for master but I hope this, or something similar, will
be OK for 1.0.x.
2019-04-08 16:24:19 +01:00
Christine Caulfield
7cd7b06d52 ipc: fixes
Use O_EXCL on IPC files
2019-04-08 13:18:34 +01:00
Christine Caulfield
e322e98dc2 ipc: use O_EXCL on SHM files, and randomize the names
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2019-04-08 13:18:34 +01:00
Christine Caulfield
a5216040d3 tests: allow blackbox-segfault.sh to run out-of-tree 2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
e6c7798fae [tests] first pass at fixing test execution
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
44386edf7d [tests] enable building / shipping of libqb-tests.rpm
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00
Fabio M. Di Nitto
6255a1466c [tests] allow installation of test suite
Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
2019-03-26 11:31:05 +00:00