]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/journal/journal-file.c
journal: make sure to explicitly copy out values of mmap before doing arithmetics...
authorLennart Poettering <lennart@poettering.net>
Thu, 23 Apr 2020 10:05:15 +0000 (12:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 23 Apr 2020 10:13:10 +0000 (12:13 +0200)
commit893e0f8fb670caff2f5717683902be08bd449f39
tree48e36cfe335b1a2f37fb7e57e1ac8f6743d80fd2
parent711398986efc2e31d7506a8bcb53e6ee13c6d9e4
journal: make sure to explicitly copy out values of mmap before doing arithmetics on them

Our journal code is generally supposed to be written in a fashion that
the underlying file can be deallocated any time, i.e. our mmap of it
suddenly becomes all zeroes. The idea is that we catch that when parsing
everything. For that to work safely we need to make sure that when doing
arithmetics or comparisons on values read from the map we don't run into
TTOCTTOU issues when determining validity. Hence we need to copy out the
values before use and operate on the copies. This requires some special
care since the C compiler could suppress our copies as optimization.
Hence use the new READ_NOW() macro to force a copy by using memcpy(),
and use it whenever we start doing an arithmetic operation on it, or
validity checking of multiple steps.

Fixes: #14943
src/journal/journal-file.c
src/journal/sd-journal.c