Commit Graph

43 Commits

Author SHA1 Message Date
Chrissie Caulfield
eaa95ecf03
lib: Fix some small bugs spotted by newest covscan (#471)
* lib: Fix some small bugs spotted by newest covscan
2022-08-17 13:17:33 +01:00
Chrissie Caulfield
06ac2d43a9
cov: Quieten some covscan warnings (#427) 2020-12-03 09:39:28 +00: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
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
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
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
wferi
5eea612ac1 Fix spelling: optvat -> optval (#270) 2017-10-13 12:45:11 +01:00
Chrissie Caulfield
f7ec9a055c ipc: fix compile warning on non-Linux platforms (#252)
Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2017-05-18 16:16:22 +01:00
Jan Pokorný
41ae3e1267 Memleak fixes (#194)
* memleak: ipc_socket: properly dispose local-scoped strndup values

Leaking memory was only possible when using filesystem sockets (see
use_filesystem_sockets function) and either:
- client is deliberately disconnecting from a server (continued run
  imposes a risk of exhausting memory)
- server is deliberately disconnecting from its client (ditto, but
  more substantial risk due to the common shared-resource nature
  of the server)

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>

* memleak: ipc_socket: properly dispose inter-function strdup values

Leaking memory was only possible when the server accepted the client,
but didn't get (or was too shy) to talk to it prior to proceeding with
a disconnect.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>

* ipc_socket: care to explain what's going on with file name inference

Related to the code parts at hand, there was an investigation/fix in
the past, initiated by "make check" failure on FreeBSD 9 [rhbz#1256701].
Unfortunately, not only the magic constant being modified was not
explained in 1908e6c, but (one can derive because of a lack of solid
background of what's going on here, which might have caused that),
it was modified incorrectly at one instance (see also [PR165 comment]),
which was then reinstated in 7ebcb3d.

So, finally de-mystify those magic constants.  Also break the symmetry
between the client/server further with depending on the canonical
"request socket" alias at the server side (the former worked equally but
it was unnecessarily confusing and there's a risk this artificial alias
will get removed in the future).

[rhbz#1256701] https://bugzilla.redhat.com/1256701
[PR165 comment] https://github.com/ClusterLabs/libqb/issues/165#issuecomment-142949541

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
2017-05-18 11:29:15 +01:00
Chrissie Caulfield
41a24a3df7 Allow Linux to use filesystem sockets (#248)
* IPC: Allow filesystem sockets to be chosen at run-time on Linux

Most of this patch came from Andrew Beekhof.
Keep a global variable that decides whether or not to use filesystem sockets
or abstract sockets for IPC connections. This variable is set by the presence of a file (default /etc/libqb/force-filesystem-sockets).

* tests: Fix test_ipcc_truncate_when_unlink_fails_shm test using FS sockets

When using filesystem sockets, the
test_ipcc_truncate_when_unlink_fails_shm test always fails, this was
because the unlink() call is wrapped to fail and so it never cleans up
the old version of the socket.
The fix is to preemptively remove the file before unlink gets wrapped.

* doc: Explain the force-filesystem-sockets option

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2017-04-28 16:13:02 +01:00
Jan Pokorný
6fad6b7b2d
tests: better diagnose test_max_dgram_size test failures 2016-11-28 15:16:04 +01:00
Jan Pokorný
ab78f2a4fd
Low: sanitize import of <poll.h> symbols 2016-10-17 17:39:09 +02:00
Jan Pokorný
b7f6dae97a
Fix typos: availabi{l -> li}ty, explici{lt -> tl}y 2016-10-12 20:10:22 +02:00
David Shane Holden
33794cce5a ipc: return -errno when getsockopt/setsockopt fail 2016-02-14 16:44:17 -05:00
David Shane Holden
4978104ae4 ipc: set socket buffer size used by ipcs service 2016-02-14 16:29:11 -05:00
David Shane Holden
e788d618ee ipc: set socket receive buffer
Set the sockets receive buffer size to match the send buffer.  On
FreeBSD without this calls to sendto() will result in an ENOBUFS error
if the message is larger than net.local.dgram.recvspace sysctl.
2016-02-14 06:31:45 -05:00
David Shane Holden
4f131253fc update: per kgaillot review
* remove pid/euid from qb_ipcc_connection
* use proper #elif defines
* return NULL instead of 0 for pointers
* return -ENOMEM when malloc fails
* remove redundant if check
* use -1 for uid to chown()
2016-01-25 21:27:29 -05:00
David Shane Holden
8668d051c5 ipc: set gid on unix sockets
When creating a unix socket it's default gid is that of the parent
directory.  If the SOCKETDIR is owned by root:wheel with 1777 mode
some of the pacemaker daemons end up unable to communicate with one
another due to having insufficient permissions on the sockets.

This can be fixed by setting the client sockets gid to the primary
group of the server socket owner it's attempting to connect to.  And,
on the server side by setting the gid to the already captured gid
stored in the connection info.  This ensures that regardless of who
owns the socket directory, as long as the applications have r/w
access to it they should work.
2016-01-23 10:32:42 -05:00
David Shane Holden
29b2c44fb6 ipc: set file permissions on created sockets
When using sockets for IPC the file permissions default to whatever
the umask is.  This isn't a problem on Linux since it uses abstract
namespace sockets which don't have any permissions, but on other
platforms this causes problems with pacemaker which spawns processes
under the hacluster user and ends up failing to connect.
2016-01-18 18:31:49 -05:00
Christine Caulfield
7ebcb3d3cf ipc: Revert half of a previous *BSD ipc-name patch
Only one of the strndup calls should have subtracted 9 from
the name length. The other should have remained at 8.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2015-09-24 16:15:05 +01:00
Christine Caulfield
1908e6c15b Fix deletion of sockets on *BSD platforms
The code removed the last 8 characters of a socket name
to get the 'base name', but 9 are needed.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
2015-09-22 09:58:23 +01:00
Andreas Grueninger
01703fdf62 Fix: Unlink files before qb_ipcc_us_sock_close
Changed the #if clauses to all non linux OSe.
2015-01-13 19:01:57 +01:00
Andreas Grueninger
ea4d931563 Fix: Unlink files bound to unix domain sockets
In qb_ipcs_us_connect 4 files are created and bound.
I dont' know how this works for QB_LINUX or QB_CYGWIN.
But for the other OS the files are created and must be unlinked.
I use the same logic to construct the file names and unlink the files.

qb_ipcc_us_connect calls this
...
  res = qb_ipc_dgram_sock_connect(r->response, "response", "request",
          r->max_msg_size, &c->request.u.us.sock);
and qb_ipc_dgram_sock_connect calls
..
set_sock_addr

and in set_sock_addr the files are created if not Linux or Cygwin.
...
#if defined(QB_LINUX) || defined(QB_CYGWIN)
  snprintf(address->sun_path + 1, UNIX_PATH_MAX - 1, "%s", socket_name);
#else
  snprintf(address->sun_path, sizeof(address->sun_path), "%s/%s", SOCKETDIR,
     socket_name);
#endif
...
2014-12-22 22:05:36 +01:00
Super-User
22d0f94cd2 High: ipc_socket: Signalhandler must be resetted to Default, use only cleanup_sigpipe to return from qb_ipc_dgram_sock_setup.
Some OS like Solaris/Illumos return with ECONNRESET or EPIPE in the case of a disconnecting peer.
Change the return code to ENOTCONN and continue.
2014-08-14 14:53:59 -04:00
David Vossel
08356b84fa Fix: ipcc: Properly timeout during recv when timeout value is provided 2014-03-12 14:05:13 -04:00
David Vossel
334762c90e Low: ipc_socket: further optimize max msg size calculations for fbsd portability tests 2014-02-11 11:19:57 -06:00
David Vossel
9e6cacd4e6 Low: ipc_socket: Allow socket max msg size to be calculated more accurately 2014-02-10 16:55:36 -06:00
David Vossel
58c0c90979 Low: ipc: Remove ipc connection reference given to dispatch functions
We don't need to give the dispatch_add callback a reference
since the dispatch_del callback must occur before the
connection is destroyed. This extra reference counting
causes unnecessary complexity.
2014-01-15 11:44:44 -06:00
David Vossel
b327dbec73 Low: ipc_socket: Fixes fd leak in socket ipc client disconnection 2013-09-16 18:38:20 -05:00
Michael van der Westhuizen
57e630f63f Use sizeof to get the correct size of the sockaddr_un sun_path member in a portable way. Fixes corosync on Mac OS X. 2013-09-03 08:44:15 +02:00
David Vossel
2a0a0790e9 Low: ipc_socket: Output send event failure as debug instead of error 2013-07-23 22:37:08 -05:00
David Vossel
54ef796126 High: ipc_socket.c: Detect EOF connection on connection STREAM socket 2013-07-23 20:01:41 -05:00
David Vossel
e6c99f6280 Merge pull request #81 from davidvossel/dgram_max_msg
Added ability to estimate kernel's actual max dgram buffer size in a portable way.
2013-07-22 14:04:52 -07:00
David Vossel
a881c14086 Low: ipc_socket.c: Handle the unlikely event of an EAGAIN or EINTR during dgram max size detection 2013-07-22 20:29:24 -05:00
David Vossel
c04e887cf1 fixes double close 2013-07-22 16:58:46 -05:00
David Vossel
f14be872a1 Fixes double close 2013-07-22 16:57:47 -05:00
David Vossel
65d044be18 High: ipcc: Add abilty to verify dgram kernel buffer size meets max msg value 2013-07-19 18:51:59 -05:00
David Vossel
6a1186863f Low: ipc_socket: In fbsd send() returns ENOBUFS when dgram queue is full, this should be treated similar to EAGAIN 2013-07-12 19:04:47 -05:00
David Vossel
95e48fdb76 Fix: ipcs: Properly disconnect client connection on POLLNVAL or any other error causing connection removal from mainloop.
qb_ipcs_dispatch_connection_request is a callback function registered with
mainloop, or whatever other looping thread implementation is in use.  When
this callback is registered, a reference of the connection object is given
to the mainloop thread.  If this callback ever returns something none zero
the callback (and corresponding fd) is unregistered from the loop automatically,
so we must decrement the reference in this instance.

Since unregistering this callback from mainloop guarantees a disconnect
simply because requests on the fd are no longer processed, it is best
that we completely disconnect the connection (which will handle the unref)
when this callback returns an error... Otherwise since the fd is unregistered
from the mainloop thread, it may not be possible to detect a disconnect
in the future.
2013-07-01 18:46:31 -05:00
Angus Salkeld
75a550d8d3 IPC: fix call to QB_SUN_LEN
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2013-03-12 20:45:47 +11:00
Angus Salkeld
31d9f0900d Use dgram sockets for message oriented communications
This is to prevent partial sends and gettting stuck in
retry loops.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2013-02-18 20:51:33 +11:00
Angus Salkeld
9d2eca251b IPC: seperate ipc_us.c into 2 files
Seperate into a setup file and a socket backend file, it was getting messy
and confusing. Also preparing for using DGRAM sockets.

This should not result in any logical changes.

Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
2013-02-06 11:21:05 +11:00