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.
This commit is contained in:
committed by
Lennart Poettering
parent
94ce42bcb6
commit
1a823cdeb9
+1
-1
@@ -219,7 +219,7 @@ static int get_file_version(int fd, char **v) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "EFI binary is not a regular file: %m");
|
||||
|
||||
if (st.st_size < 27) {
|
||||
if (st.st_size < 27 || file_offset_beyond_memory_size(st.st_size)) {
|
||||
*v = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user