* [PATCH] module: prevent warning when finit_module a 0 sized file
@ 2012-12-28 19:27 Sasha Levin
2013-01-03 0:41 ` Rusty Russell
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2012-12-28 19:27 UTC (permalink / raw)
To: Rusty Russell, linux-kernel; +Cc: 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.
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
---
kernel/module.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/kernel/module.c b/kernel/module.c
index 250092c..2e1ce2e 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -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;
--
1.8.0.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] module: prevent warning when finit_module a 0 sized file
2012-12-28 19:27 [PATCH] module: prevent warning when finit_module a 0 sized file Sasha Levin
@ 2013-01-03 0:41 ` Rusty Russell
2013-01-03 22:14 ` Sasha Levin
0 siblings, 1 reply; 4+ messages in thread
From: Rusty Russell @ 2013-01-03 0:41 UTC (permalink / raw)
To: Sasha Levin, linux-kernel; +Cc: Sasha Levin
Sasha Levin <sasha.levin@oracle.com> writes:
> 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.
diff --git a/kernel/module.c b/kernel/module.c
index 250092c..41bc118 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -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;
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] module: prevent warning when finit_module a 0 sized file
2013-01-03 0:41 ` Rusty Russell
@ 2013-01-03 22:14 ` Sasha Levin
2013-01-07 0:50 ` Rusty Russell
0 siblings, 1 reply; 4+ messages in thread
From: Sasha Levin @ 2013-01-03 22:14 UTC (permalink / raw)
To: Rusty Russell; +Cc: linux-kernel
On 01/02/2013 07:41 PM, Rusty Russell wrote:
> Sasha Levin <sasha.levin@oracle.com> writes:
>
>> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] module: prevent warning when finit_module a 0 sized file
2013-01-03 22:14 ` Sasha Levin
@ 2013-01-07 0:50 ` Rusty Russell
0 siblings, 0 replies; 4+ messages in thread
From: Rusty Russell @ 2013-01-07 0:50 UTC (permalink / raw)
To: Sasha Levin; +Cc: linux-kernel
Sasha Levin <sasha.levin@oracle.com> writes:
> On 01/02/2013 07:41 PM, Rusty Russell wrote:
>> Sasha Levin <sasha.levin@oracle.com> writes:
>>
>>> 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?
No. Root asked, we do. If modprobe wants to check the header, let it.
Cheers,
Rusty.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-01-07 1:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-28 19:27 [PATCH] module: prevent warning when finit_module a 0 sized file Sasha Levin
2013-01-03 0:41 ` Rusty Russell
2013-01-03 22:14 ` Sasha Levin
2013-01-07 0:50 ` Rusty Russell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox