Commit Graph

39 Commits (7183a3d3de67a945224c71900e0d3511359bd7e8)

Author SHA1 Message Date
Michael Meeks 7183a3d3de spdx: improve machine and human readability of headers.
Change-Id: Ice934380029bf27054e830fffc07a5d037d1430f
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-14 19:36:31 +00:00
Caolán McNamara e0c161c17b These warnings are frequent but harmless
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Id2517f310a1df71dc1357d103ea074bdd12e7e65
2023-10-25 20:08:20 +02:00
Caolán McNamara 6208b37a32 cid#318945 Unchecked return value from library
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I37cb5ddd7a1ce2dd1357738130f62950e76bbc6a
2023-09-26 16:08:09 +01:00
Ashod Nakashian 13b6f64d59 wsd: unmount the test mount directory too
We test if mounting is possible by mounting
a test directory. This can leak in crashes
and failed tests, therefore it needs to be
cleaned up too.

Change-Id: I2638cc0863f3f5575f697bece9801d42cd321ed1
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-07-08 04:19:00 -04:00
Ashod Nakashian 9efc81a51b wsd: random device mounting
We now warn when we fail to use mknod
to create the random devices and have
stricter requirements to mounting
character-devices. Specifically,
we explicitly only allow mounting
the random devices.

Change-Id: Ib0dc300dedc40942ea52426af2b267f6a81fbeb8
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-23 18:13:59 +02:00
Ashod Nakashian 214f212571 wsd: fallback from mknode to bind-mount for random devs
In some cases we may not have permission to create devices.
This happen on nodev systems and some containers. In
those cases, we gracefully fallback to bind-mounting.

Ideally, we would like to reduce the number of bind-mount
cases we do per document, which i why mknod is preferred.

Cleaning up works without modification because the
random devices are mounted in /tmp (in the chroot),
which itself is bind-mounted. So removing it is
sufficient.

Change-Id: If9a4f0a511273952ead95d6c6855ca2becaf757f
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-20 09:42:49 +02:00
Ashod Nakashian 95cf60ed5c killpoco: use own file stat helper
Change-Id: I668c2aab04083689a867e7d1f77e2b52c9351969
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-06-20 09:42:49 +02:00
Ashod Nakashian c42e74ec2f wsd: add fixme for safer jail removal
Change-Id: Id9dee5feae58f5394e2777941963ec949e59a194
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-05-15 08:47:26 +01:00
Michael Meeks f6bd976f00 Jail cleanup - include coolwsd pid + hash into a jails sub-directory.
This avoids removing the jails of other running coolwsd that share
the same jails/ directory, such as unit-tests, cypress tests etc.

Assert on fatal system error to help catch this during test builds.

Remove old unit-test specific approach, and generalize it, since
apparently we did a recursive cleanup of other people's jails anyway.

Remove over-complicated recursive approach, for a rather simpler
one-level scheme. Avoid following symlinks too for safety.

Remove obsolete lo_jail_subpath setting.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I371f8c0e22f64fb2befb4b58f72cefa39567f3b5
2023-04-25 10:41:57 +01:00
Ashod Nakashian acdce2e72f wsd: check if SysTemplate is writable once per update
Change-Id: I3bc77eaf42cc84e7e5b6365f7fc446ea38df5dc0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-03-10 07:45:12 -05:00
Ashod Nakashian d01b73456c wsd: catch mounting exceptions to fallback
In some cases mounting fails on /tmp, which
should be writable. This results in Poco
exception when trying to write to it during
mounting.

This catches exceptions and fails gracefully
to enable falling back to copying.

Change-Id: I38c8db4f452767ee43bb20a98d13bd5cc36fdba2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-12-07 17:33:11 +03:00
Ashod Nakashian 19c70b89f4 wsd: re-create the jail directory when mounting fails
This guarantees that the jail directory is always
created, especially in case mounting fails and
we cleanup and fallback.

Also, move the directory creation and setting
the perms into a helper, and reuse.

Change-Id: If6e9ef86afa5107638aa27050554e94c0af22b6e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-09-23 16:39:56 +01:00
Ashod Nakashian 5c7d94206f wsd: disable mounting when unmount fails
It seems that on some systems it is possible
to succeed in mounting, but fail to unmount.

This is proving very problematic and it is
best to detect unmount failures and disable
mount-binding altogether.

Change-Id: I6f708b3a1e585dcbd95cced45c668629410562d6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-09-23 08:53:09 +01:00
Ashod Nakashian e31d4023e7 wsd: log unmount errors only when mounting is enabled
When bind-mounting is disabled, we do a best-effort
to unmount any lingering mount-points. This is a
cleanup that helps with leftovers. Here, we
do a debug log level in case the unmounting fails,
and error, otherwise, when bind-mounting is enabled.

Change-Id: I199d6234aebfd84e6be812e5b7d3758273086815
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-08-17 21:27:30 +02:00
Ashod Nakashian b0d6e1b859 wsd: sig: forward USR2 to child processes
We now have USR2 signal that dumps the
stack-trace of each process. This is useful for
capturing the state of misbehaving instances.
COOLWSD forwards USR2 to forkit and the kits
so they dump their stacktraces too.

This patch does not change the behavior of USR1.
Specifically, unlike USR2, USR1 is not forwarded
from wsd to frk and the kits. Also unlike USR2,
USR1 dumps into stderr.

Change-Id: I1d82f678f30f430f627692cc42961b1928f69e11
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-12 13:43:43 +01:00
Ashod Nakashian 8004653c63 wsd: jail: no need to pass loSubPath between processes
Since the value of the loSubPath (i.e. the directory
name of lo within the jail) is a compile-time constant,
there is no reason to pass it around at runtime.

Change-Id: If7457ea7f3e3fe5c42215eed3ce1ce4c8f328f16
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-12 13:43:43 +01:00
Ashod Nakashian b74666201c wsd: jail: rename jails to childroot to distinguish them
This is an internal rename of identifiers.

Child-Root is the top-level, configurable, directory
that stores the jails and related directories/files.

A Jail, by contrast, is the directory that contains
the filesyste tree of a Kit process. That is, it's
the directory that is chroot-ed.

To distinguish the two, we shall use "jail" for
the chroot-ed directory, and "child-root" for the
top-level directory.

Change-Id: Ie38b1c350234b75ddd15beb1c6bcdd2e53a82af0
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-12 13:43:43 +01:00
Ashod Nakashian c3b9cb6cab wsd: privatize internal JailUtil helpers
Change-Id: I86c87f162fd174d888cb167d7d89ccd0d13cadeb
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-07-03 18:03:35 -04:00
Ashod Nakashian b53d353779 wsd: reduce debug and generally redundant logs
In 'debug' log-level we expect a detailed, but
still readable output. Having one area with
disproportionately large number of logs reduces
the overall utility of the log output.

This patch reduces a number of redundant log
entries, including errors that are already
logged. It also reduces the level of some
others from 'information' to 'debug' and
from 'debug' to 'trace'.

The goal is to make 'debug' level as useful as
possible to read the progress and be able to
understand what was going on, such that one is
able to decide which area to dig deeper into.
Then, trace level could be used to get more
insight into that area, if necessary. For
example, when investigating a test failure,
one first enables 'debug' logs and reads through.
Once a section between two debug entries is
identified as being of interest, enabling 'trace'
level logs becomes more productive as it's
now possible to easily reach the first DBG
entry and read through until the second one.

It's unfortunate that we don't have per-area
control for enabling/disabling logs, so it
is common to see more and more 'debug' log
entries added all around, making logs
less and less readable.

It is also a limitation of the levels we have
that we really only have 3 usable levels:
one, two, many. That is, 'information' for
the most important events, 'debug' for
technical details needed to investigate issues,
and 'trace' for everything else. ('warning'
and 'error' aren't really 'levels'; they have
semantics that makes them special-cases.)
So we have to avoid degrading one into the
other, or have differences without distinction.

If any of these entries are needed to be
displayed more frequently, changing them
back to 'debug' or even 'information' should
be done. Though for me they seem special
cases that don't benefit most log readings.

Change-Id: Id2c6a9dc027483b81a066b0b4b50a298c5eff449
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2022-02-24 07:38:13 -05:00
Gleb Popov cec1a927c2 cleanupJails: Postpone removing tmp directory until the end.
Otherwise, coolmount refuses to unmount devfs hierarchy on FreeBSD, because
the tmp/dev directory doesn't exist anymore.

Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I412f6947c4e1f3c04c2504e6cd88ca5645219878
2022-02-21 10:20:01 +01:00
Gleb Popov 34574724b4 Teach coolmount to mount devfs on FreeBSD.
Use it to create /dev/{u}random devices instead of calling mknod().

Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: I6ae7842c89255f3f43a8ac7f082a275d5496690a
2022-02-21 10:20:01 +01:00
Aron Budea 65e3a54857 wsd: Adjust log levels
A non-writable path isn't an error in itself.

The reason why the service tried to write the systemplate,
and the perf implications is worth reporting even on default
log level.

Signed-off-by: Aron Budea <aron.budea@collabora.com>
Change-Id: Ie168875ceb4e501291676a5aa4ddc21b88c5761f
2022-01-23 13:31:17 -05:00
Andras Timar f07ff8c7e0 rename: remaining lool->cool changes
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: Ib7d4e804bebe52dead8d53b0e0bbaed0f08bf3d0
2021-11-18 14:14:11 +01:00
Mert Tumer c9a4d2f6f3 rename: loolmount -> coolmount
Signed-off-by: Mert Tumer <mert.tumer@collabora.com>
Change-Id: Ic025c5a76c6f27cdf1a6267f24cf8052733f1f24
2021-11-17 21:51:05 +01:00
Henry Castro ae76450398 common: revisit log messages misc files
LOG_FTL = abnormal, crash, denied service
LOG_ERR = load, save, session, connection, wrong parameters
other cases LOG_WRN, LOG_INF

Change-Id: I15bc840f5a6eaf9a74a1ee1caa57d447baa2afce
Signed-off-by: Henry Castro <hcastro@collabora.com>
2021-05-05 13:50:41 -04:00
Michael Meeks 317dffb817 Optimize copy of jails to hard-linking with new capability.
In some cases we cannot do a fast bind-mount of the files we want
in our jail since we don't have cap_sys_admin for loolmount inside
eg. docker.

Thus we need to fallback to hard-linking, however various security
systems namespace parts of our tree, such that link() fails with
EXDEV even across the (apparently) same file-system.

As such we need to assemble a copy of what we want to hard-link
close to our jails. However, this needs to be owned by root / the
system to avoid having writable files shared between jails. Hence
we need cap_chown in addition to cap_fowner, to get ownership right
and then hard-link.

Change-Id: Iba0ef46ddbc1c03f3dc7177bc1ec1755624135db
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2021-01-04 15:05:36 +00:00
Ashod Nakashian 693ac2fa52 wsd: logs and const
Change-Id: Id7e4f81ab9709b62eddfa747479ab593a5ad45a2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-12-22 11:24:13 -05:00
Ashod Nakashian c74a17545e wsd: log something sensible when a dynamic file is missing
Change-Id: I9af5e0f9de8431f5a639710483a79d3944d4c683
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-11-29 19:27:23 -05:00
Ashod Nakashian d4857b603b wsd: cleanup temp incoming directories after use
The temporary directories created for convert-to
and insertfile are used only once and should be
cleaned up to avoid clutter.

We also de-poco the temp directory creation as
it doesn't add value and do a bit of cleanup.

Change-Id: Ie1fd5b4749788ff4407f2cc886d405258f65f97a
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2020-11-23 21:29:34 -05:00
Gleb Popov f7faaad790 Replace all `__linux` in CPP conditions with `__linux__`.
Signed-off-by: Gleb Popov <6yearold@gmail.com>
Change-Id: If3e213b1cf1f3c4ab960276fc6edfb71f9416420
2020-11-17 09:21:45 +00:00
Ashod Nakashian 2af764bcb8 mount: handle /dev directory creation failure
Change-Id: I053cb17418daa086f0ac47961dd9880e2a5845af
2020-10-20 09:54:19 +02:00
Ashod Nakashian 50943eeea2 wsd: gracefully warn when /dev/random cannot be created
Change-Id: I5a9c291da48c4a1446057247f9b8400f9010b9dc
2020-10-19 07:34:26 +02:00
Ashod Nakashian f9402ea965 mount: handle symlinks and improve updating systemplate
We should have no symlinks in the jail whatsoever, except
those we create to files known to exist in the jail.

Unfortunately, some systems have some of the /etc files
as symlinks. When we create hard-links to these files,
they can't be accessed from the jail, since the path
they point to isn't replicated in systemplate and jails.

First change here is to always link to the source file or,
when copying, to copy the source rather than a symlink.

Next, to detect modifications, we compare not just the
size and timestamp, but also the contents. This way we
can be certain that any modification will be detected.

Finally, when we copy at least one file in the
systemplate/etc directory, we flag it by creating the
'copied' file. This way we have a reliable indicator
and don't need to second guess if the files are
hard-linked or copied.

We also avoid some noisy errors when we fail to update
systemplate when it's read-only by first checking
if systemplate is writable or not and insue a friendly
log instead.

Change-Id: Ie8c3e70ea4ec19ee098309f8666c00639fa7319b
2020-10-19 07:34:26 +02:00
Andras Timar 0002fdfd6c fix license headers
Change-Id: I8623770b32d278a45357dc7f757fabfadd2b4af7
2020-10-01 11:56:43 +02:00
Ashod Nakashian 29a5a1f1e9 wsd: move jail setup to the script to support readonly systemplate
We now gracefully fallback to copying when/if systemplate
is readonly.

The bulk of the change is to support proper cleanup in
both cases.

First, we had to move as much of the jail bootstrapping
into the loolwsd-systemplate-setup script, so systemplate
will be as complete as possible before it is locked down.
Next, we needed to update the jail with graceful fallback
to linking/copying upon failure. For that, the jail setup
logic in Kit.cpp has been reworked to support not just
update failures, but also more comprehensive mounting
failures as well.

Finally, jail cleanup now is seamless. To support proper
cleanup when we had mounting enabled but had to fallback,
we mark jails that aren't mounted so we can 'rm -rf' the
contents safely and without fear or causing undue damage
(as unlikely as that is, technically we wouldn't want to
rm systemplate files, if mounting read-only had failed).

There are a few minor refactorings of JailUtil to make
it cleaner and more robust.

Change-Id: Iac34869cb84f45acf64fbbc46d46898367b496d2
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/101260
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
2020-08-25 07:58:30 +02:00
Ashod Nakashian bc8da0cb33 wsd: support read-only systemplate
For various reasons, systemplate may be read-only
or under a different owner and therefore impossible
to update the dynamic files in it.

To support such a scenario, we first link the
eight dynamic files in /etc when creating systemplate.
If this fails, we copy the files.

When creating jails, we always check that all the
dynamic files are up-to-date. If they are, nothing
further is necessary and we bind-mount, if enabled
and possible.

However, if the dynamic files are not up-to-date,
we disable bind-mounting and force linking
the files in the jails. Failing that, we copy them,
which is not ideal, but allows us to ensure the
dynamic files are up-to-date as we copy them too.

Ideally, the dynamic files in question would be
hard-link (or at least soft-linked) in systemplate
at creation. From then on we would bind-mount
the jails and everything would work perfectly and
no files would need updating. This patch is fallback
for when this scheme fails, which should be exceedingly
rare anyway, but which still ensures correct operation.

Change-Id: I09c6f057c49396579aaddb1b8bf4af0930dd4247
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/100834
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
2020-08-17 13:51:56 +02:00
Ashod Nakashian d6259d6a54 wsd: support parallel systemplate setup
When tests are run in parallel, they will all
compete to update and set up the systemplate
directory, which has a handful of files that
need to be up-to-date. This is a source of errors.

Normally, these files are linked (hard- or soft-
link, whichever succeeds). With linking, we
only need to worry about the initial setup,
as the files will never be out-of-date from
then on. However, when linking fails, we need
to copy the files, and update them (by copying
over fresh versions of the files, if necessary)
every time a new kit is forked. Copying over
is tricky, as it's not atomic. To make it
atomic, we copy the files to the destination
directory under a temporary (random) name,
and then rename to the final name (which is
atomic, including replacing the target file,
if it exists).

No such race exists in production, where there
is (or should be) but one instance of loolwsd
(which does the initial setup) and forkit
(which updates systemplate before forking
new kit instances).
This is an issue with parallel tests only.

Change-Id: I6ba1514d00a84da7397d28efeb6378619711d52f
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97785
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-07-07 19:05:23 +02:00
Ashod Nakashian 9f7f6dca6a wsd: cleanup realpath call
The new utility is safer and more readable.

Change-Id: I3a86675378d458cb004e5534dbf2b401936d0e57
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98183
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-07-06 13:54:54 +02:00
Ashod Nakashian 5c9988f2e3 wsd: faster jail setup via bind-mount
loolmount now works and supports mounting and
unmounting, plus numerous improvements,
refactoring, logging, etc..  When enabled,
binding improves the jail setup time by anywhere
from 2x to orders of magnitude (in docker, f.e.).

A new config entry mount_jail_tree controls
whether mounting is used or the old method of
linking/copying of jail contents. It is set to
true by default and falls back to linking/copying.
A test mount is done when the setting is enabled,
and if mounting fails, it's disabled to avoid noise.

Temporarily disabled for unit-tests until we can
cleanup lingering mounts after Jenkins aborts our
build job. In a future patch we will have mount/jail
cleanup as part of make.

The network/system files in /etc that need frequent
refreshing are now updated in systemplate to make
their most recent version available in the jails.
These files can change during the course of loolwsd
lifetime, and are unlikely to be updated in
systemplate after installation at all. We link to
them in the systemplate/etc directory, and if that
fails, we copy them before forking each kit
instance to have the latest.

This reworks the approach used to bind-mount the
jails and the templates such that the total is
now down to only three mounts: systemplate, lo, tmp.

As now systemplate and lotemplate are shared, they
must be mounted as readonly, this means that user/
must now be moved into tmp/user/ which is writable.

The mount-points must be recursive, because we mount
lo/ within the mount-point of systemplate (which is
the root of the jail). But because we (re)bind
recursively, and because both systemplate and
lotemplate are mounted for each jails, we need to
make them unbindable, so they wouldn't multiply the
mount-points for each jails (an explosive growth!)
Contrarywise, we don't want the mount-points to
be shared, because we don't expect to add/remove
mounts after a jail is created.

The random temp directory is now created and set
correctly, plus many logging and other improvements.

Change-Id: Iae3fda5e876cf47d2cae6669a87b5b826a8748df
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92829
Tested-by: Jenkins
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
2020-07-01 05:42:43 +02:00