Skip to contentSkip to conversation

module: prevent warning when finit_module a 0 sized file

PATCH Applied Sasha Levin 2 participants 4 messages Dec 28, 2012 – Jan 7, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module: prevent warning when finit_module a 0 sized file

If we try to finit_module on a file sized 0 bytes vmalloc will scream and spit out a warning.

Since modules have to be bigger than 0 bytes anyways we can just check that beforehand and avoid the warning.

---
 kernel/module.c | 6 ++++++
 1 file changed, 6 insertions(+)
kernel/module.c +6 -0
index 250092c..2e1ce2e 100644
@@ -2527,6 +2527,12 @@ static int copy_module_from_fd(int fd, struct load_info *info)
 		err = -EFBIG;
 		goto out;
 	}
+
+	if (stat.size == 0) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	info->hdr = vmalloc(stat.size);
 	if (!info->hdr) {
 		err = -ENOMEM;
Signature · 1 line
1.8.0.2
#1 lore raw
Quoted 5 lines · Sasha Levin

If we try to finit_module on a file sized 0 bytes vmalloc will scream and spit out a warning.

Since modules have to be bigger than 0 bytes anyways we can just check that beforehand and avoid the warning.

Applied, but I added the comment you somehow missed :)

Thanks,
Rusty.

kernel/module.c +7 -0
index 250092c..41bc118 100644
@@ -2527,6 +2527,13 @@ static int copy_module_from_fd(int fd, struct load_info *info)
 		err = -EFBIG;
 		goto out;
 	}
+
+	/* Don't hand 0 to vmalloc, it whines. */
+	if (stat.size == 0) {
+		err = -EINVAL;
+		goto out;
+	}
+
 	info->hdr = vmalloc(stat.size);
 	if (!info->hdr) {
 		err = -ENOMEM;
#2 lore raw
Quoted 9 lines · Rusty Russell
Quoted 5 lines · Sasha Levin

If we try to finit_module on a file sized 0 bytes vmalloc will scream and spit out a warning.

Since modules have to be bigger than 0 bytes anyways we can just check that beforehand and avoid the warning.

Applied, but I added the comment you somehow missed :)

Thanks!

I do have a somewhat related follow-up question:

When init_module() goes through the module loading process, it will try to vmalloc() whatever size passed to it by the user, which may cause vmalloc() to scream and shout if the size passed from userspace is too big.

Do you think that reading just the header and doing a quick elf_header_check() on it before trying to read the entire file would make sense here?

Thanks,
Sasha

#3 lore raw
Quoted 13 lines · Sasha Levin
Quoted 9 lines · Rusty Russell
Quoted 5 lines · Sasha Levin

If we try to finit_module on a file sized 0 bytes vmalloc will scream and spit out a warning.

Since modules have to be bigger than 0 bytes anyways we can just check that beforehand and avoid the warning.

Applied, but I added the comment you somehow missed :)

Thanks!

Quoted 8 lines

I do have a somewhat related follow-up question:

When init_module() goes through the module loading process, it will try to vmalloc() whatever size passed to it by the user, which may cause vmalloc() to scream and shout if the size passed from userspace is too big.

Do you think that reading just the header and doing a quick elf_header_check() on it before trying to read the entire file would make sense here?

No. Root asked, we do. If modprobe wants to check the header, let it.

Cheers,
Rusty.