Skip to contentSkip to conversation

libkmod: Verify memory sizes on 32 bit systems.

PATCH New Tobias Stoeckmann 1 participant 1 message Jun 25, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libkmod: Verify memory sizes on 32 bit systems.

Large file system support is activated by default, which means that on 32 bit systems, off_t is 64 bit in size.

Using st.st_size or any other 64 bit variable with mmap can lead to integer truncation and therefore insufficient memory mapping.

---
 libkmod/libkmod-file.c | 2 ++
 1 file changed, 2 insertions(+)
libkmod/libkmod-file.c +2 -0
index 5eeba6a..86f34c6 100644
@@ -255,6 +255,8 @@ static int load_reg(struct kmod_file *file)
 		return -errno;
 
 	file->size = st.st_size;
+	if ((uintmax_t)st.st_size > (uintmax_t)SIZE_MAX)
+		return -EFBIG;
 	file->memory = mmap(NULL, file->size, PROT_READ, MAP_PRIVATE,
 			    file->fd, 0);
 	if (file->memory == MAP_FAILED)
Signature · 1 line
2.13.2