module: prevent warning when finit_module a 0 sized file
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
@@ -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
Rusty Russell
AppliedQuoted 5 lines · Sasha Levin
If we try to
finit_moduleon 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
@@ -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 ;
Quoted 9 lines · Rusty Russell
Quoted 5 lines · Sasha Levin
If we try to
finit_moduleon 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
Quoted 13 lines · Sasha Levin
Quoted 9 lines · Rusty Russell
Quoted 5 lines · Sasha Levin
If we try to
finit_moduleon 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 tovmalloc()whatever size passed to it by the user, which may causevmalloc()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.