From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: linux-modules@vger.kernel.org
Subject: [PATCH] Prevent offset + size overflow.
Date: Mon, 9 Feb 2015 23:22:51 +0100 [thread overview]
Message-ID: <20150209222251.GA22303@localhost> (raw)
[-- Attachment #1: Type: text/plain, Size: 1414 bytes --]
Hi,
it is possible to overflow uint64_t by summing variables offset and
size up in elf_get_section_info. Thee values are extracted from module
file and are possibly maliciously tampered with.
If offset is in valid range and size very large, the result will
overflow and the size check passes. Later on, this will most likely
lead to a segmentation fault due to accessing uninitialized memory.
Attached please find a proof of concept module, which will trigger
a segmentation fault on modinfo. Tested on amd64:
tobias:~$ modinfo poc.ko
filename: /home/tobias/poc.ko
Segmentation fault
Tobias
PS: There are more errors of this type in the ELF handling code, so let
me know if you are okay with the additional check in the if-block.
I will send patches like this one for the other occurrences then.
---
libkmod/libkmod-elf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libkmod/libkmod-elf.c b/libkmod/libkmod-elf.c
index d1b0f33..8a8a73d 100644
--- a/libkmod/libkmod-elf.c
+++ b/libkmod/libkmod-elf.c
@@ -251,7 +251,7 @@ static inline int elf_get_section_info(const struct kmod_elf *elf, uint16_t idx,
#undef READV
min_size = *offset + *size;
- if (min_size > elf->size) {
+ if (ULLONG_MAX - *offset < *size || min_size > elf->size) {
ELFDBG(elf, "out-of-bounds: %"PRIu64" >= %"PRIu64" (ELF size)\n",
min_size, elf->size);
return -EINVAL;
--
2.3.0
[-- Attachment #2: poc.ko --]
[-- Type: application/octet-stream, Size: 208 bytes --]
next reply other threads:[~2015-02-09 22:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-09 22:22 Tobias Stoeckmann [this message]
2015-02-10 2:56 ` [PATCH] Prevent offset + size overflow Lucas De Marchi
2015-02-10 8:26 ` Tobias Stöckmann
2015-02-10 10:31 ` Lucas De Marchi
2015-02-10 10:44 ` Tobias Stöckmann
2015-02-10 12:55 ` Lucas De Marchi
2015-02-10 13:23 ` Tobias Stöckmann
2015-02-10 10:33 ` Lucas De Marchi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150209222251.GA22303@localhost \
--to=tobias@stoeckmann.org \
--cc=linux-modules@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).