core: check size before mmap
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 2 Mar 2022 21:03:26 +0000 (22:03 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 3 Mar 2022 21:48:43 +0000 (22:48 +0100)
commit1a823cdeb9faea3849843e0b3dae0fbdd607e8b7
treee7e6f91ec7e59db9d0b07edcb5d3d3c98ca21420
parent94ce42bcb6288583bfa8995aa705d99a9221f47e
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.
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