Commit graph

1023 commits

Author SHA1 Message Date
Michael Meeks
a30df0f583 js: remove obsolete CRS.Earth references.
Change-Id: I3c5a25bd3ff1ee7af01c6190244400ec8d68e47c
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-02-07 17:13:48 +00:00
Michael Meeks
29fa4a40a1 signal activity dumping: enrich with session details and state.
Cue up some basic state for being signal safe dumped on crash/abort.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ibc6713aef2a0e7b878b178b05f0e13c8d40b47fc
2024-02-06 19:29:28 +00:00
Ashod Nakashian
398cf7bc82 killpoco: move own logging out of experimental
This enables our own logging (much faster)
out of the experimental flag and enables
permanently.

Not for backporting.

Change-Id: I15161ff4f82a2e298942f81f35aea305bb06f683
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-02-05 16:47:08 +00:00
Ashod Nakashian
3d4efc0030 wsd: header clean up and SPDX license
Change-Id: I6e75b9a6d5ddd192bef18f637ef9c3d5548d9c88
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-02-05 16:47:08 +00:00
Caolán McNamara
f04d3450cd rng::getHardRandomHexString is now the same impl as rng::getHexString
so remove one in favor of the other

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I47778f7bce24f0687565aa179b7a3bbea9d95120
2024-02-05 16:19:38 +00:00
Ashod Nakashian
6174fc3098 wsd: rescue the clipboard before autosaving on unload
This moves the clipboard resque logic earlier to
make sure it is cached before the Kit process
exits.

By putting the clipboard-fetching command before
the save-before-exit, we should get the clipboard
in most-all cases. There are still edge-cases
that can slip through, but they should be much
less frequent, and they will require much more
involved logic (tbd).

Change-Id: I0eff95c28524002a6131fa0a57ef8e09ae21ca59
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-02-05 11:52:02 +01:00
Caolán McNamara
5432562801 getTempFileCopyPath is only used by tests so move to test-only code
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I7c8a122425c689edb3eeb8c80e08470eac347bcc
2024-02-01 10:01:08 +00:00
Michael Meeks
9ff5c5bce6 randomness: abort if we can't get randomness, with a message.
Avoid using LOG_TRC etc. during static initializers before logging
is setup:

 #0  0x00007ffff7362183 in std::string::size() const () from /lib64/libstdc++.so.6
 #1  0x00000000007d1acc in std::operator==<char> (__lhs="", __rhs=<error reading variable: Cannot access memory at address 0xffffffffffffffe8>)
     at /opt/rh/devtoolset-12/root/usr/include/c++/12/bits/basic_string.h:3586
 #2  0x00000000008fdc04 in Poco::Logger::unsafeGet (name="") at src/Logger.cpp:289
 #3  0x00000000008fdb81 in Poco::Logger::get (name="") at src/Logger.cpp:280
 #4  0x000000000066a30f in Log::logger () at /opt/rh/devtoolset-12/root/usr/include/c++/12/bits/new_allocator.h:90
 #5  0x0000000000692f8e in Util::rng::getBytes (length=16) at ../common/Util.cpp:122
 #6  0x0000000000693312 in Util::rng::getSeed () at ../common/Util.cpp:91
 #7  0x000000000044f987 in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at ../common/Log.hpp:87

Change-Id: I6a32a0d3f50a8e769994737d4c09befe11599b4e
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-31 20:13:19 +00:00
Michael Meeks
b627777b13 Remove trendy C++ & Poco wrappers for random numbers.
And improve quality of low-grade random numbers significantly.
_rd.entropy() ? is not your friend.

Change-Id: I477557245949334bec517cdeae653c7452ed2049
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-31 16:28:15 +00:00
Michael Meeks
b5701214c2 handle filename collision if necessary.
Change-Id: I9f2e8a16b07e78105ede57f4847c9762ea066368
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-31 16:28:15 +00:00
Michael Meeks
767fa5356d Revert "when exec'ing subprocess, only inherit stdin/stdout/stderr"
This reverts commit 8afaae86a8.
2024-01-27 12:03:53 +00:00
Noel Grandin
8afaae86a8 when exec'ing subprocess, only inherit stdin/stdout/stderr
we want the normal ones, so we see the output in our own console, but we
don't want the others.

It would be better to use posix_spawn_file_actions_addinherit_np here,
but that seems to be currently macos-only.

Signed-off-by: Noel Grandin <noel.grandin@collabora.co.uk>
Change-Id: Ifd42c51f68ca2f340b78066b381cdbc6a23f0abe
2024-01-27 11:26:44 +00:00
Noel Grandin
16228fa0ed speed up spawning/execing child programs
using fork(), the kernel needs to copy the VM data structures,
which can be quite large for the main COOL processes.

I looked into things like vfork(), clone() and using a helper-process,
but it looks like posix_spawn is sufficient for our needs.
Internally it uses clone(CLONE_VM) which means we avoid the VMA copies.

Also, simplify the arguments of spawnProcess,
we don't use the optional params anymore.

Signed-off-by: Noel Grandin <noel.grandin@collabora.co.uk>
Change-Id: I8f943541dc4d7f56c2d36ccbf7b78c40ec14b8e0
2024-01-27 11:26:44 +00:00
Michael Meeks
6f749b1055 signal activity dumping: log sixteen previous activies not eight.
Eight is a little few with multiple users around.

Change-Id: I0fe3e8a463463b9d7f2bb3e9efdc4aa12e7777e9
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-26 20:03:45 +00:00
Miklos Vajna
33310613cd wsd: fix reading past the end of the clipboard in postProcessCopyPayload()
Add a way to search with an offset in findInVector() and then we can
avoid strstr() which assumes a null-terminated input, which may not be
the case.

	READ of size 55 at 0x606000068a56 thread T8 (docbroker_001)
	    #0 0x55d0d6718a5a in StrstrCheck(void*, char*, char const*, char const*) /home/abuild/rpmbuild/BUILD/llvm-15.0.7.src/build/../projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:652:5
	    #1 0x55d0d6718882 in __interceptor_strstr /home/abuild/rpmbuild/BUILD/llvm-15.0.7.src/build/../projects/compiler-rt/lib/asan/../sanitizer_common/sanitizer_common_interceptors.inc:669:5
	    #2 0x55d0d71872c9 in ClientSession::postProcessCopyPayload(std::shared_ptr<Message> const&)::$_4::operator()(std::vector<char, std::allocator<char>>&) const /home/vmiklos/git/collaboraonline/online-23.05-san/wsd/ClientSession.cpp:1631:31

During unit-uno-command.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Id42669d912bab4746d9f7d99a192c4c3f1d175f7
2024-01-23 08:38:26 +00:00
Miklos Vajna
56abb1c760 common: fix 0 read size in FileUtil::readFile()
/usr/bin/../lib64/gcc/x86_64-suse-linux/12/../../../../include/c++/12/bits/stl_vector.h:1124:9: runtime error: reference binding to null pointer of type 'char'
    #0 0x557ce8c06055 in std::vector<char, std::allocator<char>>::operator[](unsigned long) /usr/bin/../lib64/gcc/x86_64-suse-linux/12/../../../../include/c++/12/bits/stl_vector.h:1124:2
    #1 0x557ce8f16e3f in FileUtil::readFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int) /home/vmiklos/git/collaboraonline/online-23.05-san/test/../common/FileUtil.cpp:449:37

While running toplevel 'make'. Both 'st.st_size' and 'off' were 0, so
this is an edge case.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I4899bffa48a761c84b6ee7d42776453b641ff5a7
2024-01-22 09:39:38 +00:00
Michael Meeks
f477e17d5e ChildSession - dump much more internal state.
Change-Id: I1441d88968040b6852bf6338e8a4dfcdf8e308f5
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-18 20:18:56 +00:00
Michael Meeks
ca34860bbc clipboard - dump saved clipboard state and details.
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I1dcee22ad66bce1081b88262b58e9999f6e81ada
2024-01-17 09:52:58 +00:00
Michael Meeks
5bd1f1d0e8 convert-to: be more tolerant of unusual filenames.
But re-write them anyway to be more sensible.

Change-Id: Ie146f4f84b539ab7e826a1c1b947497acde7e384
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-15 11:57:55 +01:00
Caolán McNamara
258bffdfb1 cid#340396 Insecure data handling
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I7b0e1e9b1dc87587759cfe04aa9ac89d85e174dd
2024-01-15 08:38:31 +01:00
Miklos Vajna
973d12b2a7 admin: improve error handling on bad json for updateroutetoken
terminate called after throwing an instance of 'Poco::JSON::JSONException'
...
    #11 0x7f70540e006a in Poco::JSON::ParserImpl::parseImpl(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) (/usr/lib64/libPocoJSON.so.92+0x4206a) (BuildId: 149b3c1772e35fcbe5692d435f1b06820707bad3)
    #12 0x556a70a9511b in Poco::JSON::Parser::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&) /usr/include/Poco/JSON/Parser.h:202:9
    #13 0x556a70a9511b in JsonUtil::parseJSON(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, Poco::SharedPtr<Poco::JSON::Object, Poco::ReferenceCounter, Poco::ReleasePolicy<Poco::JSON::Object>>&) /home/vmiklos/git/collaboraonline/online-fuzz/./common/JsonUtil.hpp:37:50
    #14 0x556a70a7edde in AdminSocketHandler::handleMessage(std::vector<char, std::allocator<char>> const&) /home/vmiklos/git/collaboraonline/online-fuzz/wsd/Admin.cpp:325:13

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: Iebe0f5d689032a8b3c1e5d38c5ee80d344d1cbed
2024-01-09 14:13:46 +00:00
Ashod Nakashian
61cf7b9601 wsd: clean up unused header includes
Clang-tidy recommendation driven header
include clean-up.

Change-Id: I30c32866b7798e70df0463ee6bc7a0bcc3de5049
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2024-01-08 08:38:48 +01:00
Michael Meeks
29db7db278 logging: calm down dropping of on-the-fly messages.
These tend to be sent at small increments of time, so have some
hysteresis to aggregate drops. Stalled JS such as in a debugger
or a client not responding can cause this for quite some tiles.

Change-Id: Ia807d4ba0ac26a95cad435cba9ed191f22706041
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2024-01-08 08:32:12 +01:00
Michael Meeks
b10b9276b8 Use /proc/self/smaps_rollup for improved perf #7927
Using the aggregated file saves a hundred+ system-calls per
pid we're getting data for, and presumably also lots of time.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: I41c40982ebbec44aba72a1d15dabf24a8986f59e
2024-01-03 20:20:02 +00:00
Jaume Pujantell
35d6e2925f use isKitInProcess() instead of KIT_IN_PROCESS
Removed all uses of KIT_IN_PROCESS, used Utils::isKitInProcess()
when necessary. Also removed the now unused parameter 'limit' from
forkLibreOfficeKit.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: I068d3f55ab49076590f111847c87b3188f4d25d0
2023-12-18 10:34:10 +00:00
Jaume Pujantell
eca990920a add logic to sapwn threads intead of processes
Added code that spawns forkit and lokit in threads instead of new processes.

Signed-off-by: Jaume Pujantell <jaume.pujantell@collabora.com>
Change-Id: I6b6ad6dccfedaf28ebd0d68851205c540b9a0317
2023-12-18 10:34:10 +00:00
Ashod Nakashian
6a42339640 wasm: log to stdout instead of stderr
Change-Id: I747945635c749127d2851cab1f738f4fa58d99f7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-12-09 19:22:24 +00:00
Ashod Nakashian
a96f8a0f92 configure: WASMAPP is now defined for WASM targets
This is in line with MOBILEAPP and GTKAPP and
is independent of __EMSCRIPTEN__.

Replace all application-specific cases, leaving
only toolchain-specific ones (such as include
protection).

Change-Id: Ic44288aa5ace51e0a8b54566170c19120f7bf0dd
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-12-09 19:22:24 +00:00
Darshan-upadhyay1110
3f46c1db44 kit-in-process: pure re-factor to a run-time function to flag this.
Avoids a number of compile time conditionals and adds flexibility.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Iff6b294b504526e70715e436ad33d47c8df4752c
2023-11-22 17:06:29 +00:00
Michael Meeks
6a32adcfe8 delta: fix threading gotcha when working.
The ThreadPool::work function can get its condition signalled -very- late.

With bad timing, this can occur after all the work is done, and when the
next batch of work is being fed into the pool.

This can mean that it takes work from the queue, and subverts the:

        bool useThreads = _threads.size() > 1 && _work.size() > 1;

check in ThreadPool::run - which can believe we are in a single
threaded, single tile mode - and not wait for this thread to complete.

That's not good [!] so ensure that threads are only runnable during
ThreadPool::run.

Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
Change-Id: Ifebb0f15cbb4c22ef33ffba06e7c6c87493818be
2023-11-20 19:24:13 +00:00
Michael Meeks
1a4dafa3e5 Fetch available memory and limits from our control group not the system.
To test:

sudo mkdir /sys/fs/cgroup/memory/0
echo "900M" | sudo tee /sys/fs/cgroup/memory/0/memory.limit_in_bytes
echo $$ | sudo tee /sys/fs/cgroup/memory/0/tasks
make run # and check the log.

Change-Id: I81cf5f6212418d1f900a56cdfe476e1594f4fe77
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-11-14 19:36:31 +00:00
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
Andras Timar
78d4fe22b3 fix log date, tm.tm_mon is 0-11
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I93f7ac7a83c9724537b9b214cd8b54e5132c54e4
2023-11-09 13:20:07 +01: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
Ashod Nakashian
c3fb1d0dde wsd: helper to serialize pairs
Since we don't want to propagate Poco types
as well as our pair containers, it's best
to have these are named functions rather
than as operator<<.

Change-Id: I9772b8f314262147b6c445464bf3ce8cb598b56d
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-24 21:33:02 -04:00
Ashod Nakashian
44cc7145c2 wsd: helper to concatenate streamable elements together
Change-Id: I0d989b54d5eebbd3efee2502d84a82281ebf62a7
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-24 09:20:32 +02:00
Caolán McNamara
d6c1916cb2 cool#7374 very little delta threading
We only run one task in each thread when run() is called, then complete
the remainder of tasks in the main thread while the other threads wait.

https: //github.com/CollaboraOnline/online/issues/7374
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Id4fc0a620d98b0bb55310b495eeff7411a4544b5
2023-10-16 09:26:32 +01:00
Caolán McNamara
9ae7c294bc cid#318975 help coverity see assert
Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: Ibf735e47362715d442c0122b9a29a0225d1cdc9a
2023-10-09 10:24:11 +02:00
Michael Meeks
71213b675e logging: allocate temporary buffer on the stack.
Change-Id: I1805db7c9c6bc6c66afbb912a16e01f6bf0f2699
Signed-off-by: Michael Meeks <michael.meeks@collabora.com>
2023-10-06 09:11:15 +02:00
Caolán McNamara
3e67acd361 cid#318942 Unchecked return value from library
use a more standard way to zero the _sb stat struct

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I98973affe6b96a5779cfc3eef3c349019c34d0a0
2023-10-04 09:57:39 +02:00
Skyler Grey
e6d9c1f87c Add support for URP messages in COOLWSD
- Allow COOLWSD client sessions to forward messages with the prefix
  'urp' to the child, and return messages with 'urp:' to the client,
  communicating with binary
- Make COOLWSD child sessions use the FunctionBasedURPConnection from
  https://gerrit.libreoffice.org/c/core/+/155100
  (core change ID I2bda3d0b988bef7883f9b6829eeb5b7ae8075f27) to start a
  new URP session
- Make COOLWSD child sessions submit messages to this URP session,
  stripping and adding the 'urp' and 'urp:' prefixes so the Java client
  from https://gerrit.libreoffice.org/c/core/+/154680
  (core change ID I91ee52922a24688a6b94512cb7e7bc760bf25ec9) can
  use the connection (and to avoid interference with any other websocket
  messages)
- Add a COOLWSD option for enabling/disabling URP given the security
  implications around allowing anyone to write URP (e.g. URP lets you
  run shell commands so a mallicious actor can take over the child
  session)

Signed-off-by: Skyler Grey <skyler.grey@collabora.com>
Change-Id: Idadfe288a78cfd72b01253dfdade150d506e3f05
2023-10-03 10:15:55 +01:00
Ashod Nakashian
7d0276c394 killpoco: replace LocalDateTime
This replaces Poco's LocalDateTime, which
took a lock, called tzset each time, and
did unnecessary Julian-to-Gregorian conversion.

The result is a standards-compliant implementation
that is about an order of magnitude faster (0.3 us
vs 3 us on average).

Change-Id: Iced73056a9f9e6497106224c351110113e21d8d6
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
c5d47b4b20 wsd: log: verify that all threads are stopped
This verifies that in debug-builds the log
thread-local buffers are destroyed, and
therefore the threads are gracefully stopped.

This is necessary to make sure no log entries
are lost by the time we exit the process.

Change-Id: I0db20835109e92d8758a5c4eec6845cd240da025
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
483a602f93 wsd: log: BufferedConsoleChannel with thread-local buffer
This gives each logging thread its own buffer.
We then guarantee that all threads exit clearly
and flush their buffers.

For now, we don't flush buffers when fatally signaled,
primarily because of technical complexities.
Specifically, we don't know if we have a Poco logger
or our Buffered Logger, and there are a host of
threading and signal-safety concerns. To be revisited.

Change-Id: I39674a25feeee3aabd87c8b707ea1adf3c039817
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
150663cc28 wsd: stop the rendering thread pool before exiting
Change-Id: I8a084ee1fd583f6c37ba4ca8c1ebf8abe74288a2
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
370b649b3e killpoco: own implementation of ColorConsoleChannel
This replaces Poco's ColorConsoleChannel with our
own, which is simpler and more efficient. It also
doesn't break log entries arbitrarily (only when
the entry is exceedingly long).

Change-Id: I46ba58d35bc913ca83fe97aaaa958c03b81ae44e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
066af307ba killpoco: own implementation of BufferedConsoleChannel
This is a buffered version of our ConsoleChannel.

Change-Id: Ie1728e136376fdf82ec28010b67d8344fd812768
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
57a9cf053a wsd: support EnableExperimental in Log
Now that we depend on EnableExperimental in Log.cpp,
we must define it in the standalone binaries that
otherwise don't define it.

Change-Id: Ic56032eaf6df7d0d5d707a60eeddf2d75c9041ac
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
a00fbae7c5 wsd: log: retry on write failure and flush
Change-Id: I7417a74959a52e2a079bfe4502ed238d1517ea60
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00
Ashod Nakashian
56fd825187 killpoco: our implementation of ConsoleChannel
This replaces Poco's implementation of ConsoleChannel
which has a horrible issue with writing the new line
in a separate syscall. This often results in multiple
log entries on the same line and other horrors.

This implementation does no buffering.

Change-Id: I8d18de1313d8f160270ec04552ba7e7b69d2363e
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
2023-10-02 20:14:53 +01:00