core: check size before mmap
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 2 Mar 2022 21:03:26 +0000 (22:03 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Sat, 5 Mar 2022 21:03:32 +0000 (21:03 +0000)
commit6b37adf4a16c8f7e917dfd9f19dab259cda878b2
tree99130459db36f1cc967a30327970bffe8cf0d890
parentb707664eeed77be0c06f8e8dbeeb7e3ba9dcba5c
core: check size before mmap

The data type off_t can be 64 on 32 bit systems if they have large
file support. Since mmap expects a size_t with 32 bits as second
argument truncation could occur. At worst these huge files could
lead to mmaps smaller than the previous check for small files.

This in turn shouldn't have a lot of impact because mmap allocates
at page size boundaries. This also made the PAGE_ALIGN call in
open_mmap unneeded. In fact it was neither in sync with other mmap
calls nor with its own munmap counterpart in error path.

If such large files are encountered, which is very unlikely in these
code paths, treat them with the same error as if they are too small.

(cherry picked from commit 1a823cdeb9faea3849843e0b3dae0fbdd607e8b7)
src/basic/fileio.h
src/basic/locale-util.c
src/boot/bootctl.c
src/libsystemd/sd-hwdb/sd-hwdb.c
src/libsystemd/sd-journal/catalog.c
src/libsystemd/sd-journal/compress.c