Skip to contentSkip to conversation

Guard check in module loader against integer overflow

PATCH Applied David Howells 2 participants 2 messages May 22, 2012 – May 23, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Guard check in module loader against integer overflow

The check:

	if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr))

may not work if there's an overflow in the right-hand side of the condition.

---

 kernel/module.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
kernel/module.c +2 -1
index 78ac6ec..377cb06 100644
@@ -2429,7 +2429,8 @@ static int copy_and_check(struct load_info *info,
 		goto free_hdr;
 	}
 
-	if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr)) {
+	if (hdr->e_shoff >= len ||
+	    hdr->e_shnum * sizeof(Elf_Shdr) > len - hdr->e_shoff) {
 		err = -ENOEXEC;
 		goto free_hdr;
 	}
#1 lore raw
Quoted 7 lines · David Howells

The check:

	if (len < hdr->e_shoff + hdr->e_shnum * sizeof(Elf_Shdr))

may not work if there's an overflow in the right-hand side of the condition.

Thanks; though the sanity checks are merely against accidents, not malice, it's worth fixing.

Applied,
Rusty.