Skip to content

Commit 054a730

Browse files
committed
module: split up 'finit_module()' into init_module_from_file() helper
This will simplify the next step, where we can then key off the inode to do one idempotent module load. Let's do the obvious re-organization in one step, and then the new code in another. Signed-off-by: Linus Torvalds <[email protected]>
1 parent 89181f5 commit 054a730

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

kernel/module/main.c

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,34 +3057,24 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
30573057
return load_module(&info, uargs, 0);
30583058
}
30593059

3060-
SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
3060+
static int init_module_from_file(struct file *f, const char __user * uargs, int flags)
30613061
{
30623062
struct load_info info = { };
30633063
void *buf = NULL;
30643064
int len;
3065-
int err;
3066-
3067-
err = may_init_module();
3068-
if (err)
3069-
return err;
30703065

3071-
pr_debug("finit_module: fd=%d, uargs=%p, flags=%i\n", fd, uargs, flags);
3066+
if (!f || !(f->f_mode & FMODE_READ))
3067+
return -EBADF;
30723068

3073-
if (flags & ~(MODULE_INIT_IGNORE_MODVERSIONS
3074-
|MODULE_INIT_IGNORE_VERMAGIC
3075-
|MODULE_INIT_COMPRESSED_FILE))
3076-
return -EINVAL;
3077-
3078-
len = kernel_read_file_from_fd(fd, 0, &buf, INT_MAX, NULL,
3079-
READING_MODULE);
3069+
len = kernel_read_file(f, 0, &buf, INT_MAX, NULL, READING_MODULE);
30803070
if (len < 0) {
30813071
mod_stat_inc(&failed_kreads);
30823072
mod_stat_add_long(len, &invalid_kread_bytes);
30833073
return len;
30843074
}
30853075

30863076
if (flags & MODULE_INIT_COMPRESSED_FILE) {
3087-
err = module_decompress(&info, buf, len);
3077+
int err = module_decompress(&info, buf, len);
30883078
vfree(buf); /* compressed data is no longer needed */
30893079
if (err) {
30903080
mod_stat_inc(&failed_decompress);
@@ -3099,6 +3089,28 @@ SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
30993089
return load_module(&info, uargs, flags);
31003090
}
31013091

3092+
SYSCALL_DEFINE3(finit_module, int, fd, const char __user *, uargs, int, flags)
3093+
{
3094+
int err;
3095+
struct fd f;
3096+
3097+
err = may_init_module();
3098+
if (err)
3099+
return err;
3100+
3101+
pr_debug("finit_module: fd=%d, uargs=%p, flags=%i\n", fd, uargs, flags);
3102+
3103+
if (flags & ~(MODULE_INIT_IGNORE_MODVERSIONS
3104+
|MODULE_INIT_IGNORE_VERMAGIC
3105+
|MODULE_INIT_COMPRESSED_FILE))
3106+
return -EINVAL;
3107+
3108+
f = fdget(fd);
3109+
err = init_module_from_file(f.file, uargs, flags);
3110+
fdput(f);
3111+
return err;
3112+
}
3113+
31023114
/* Keep in sync with MODULE_FLAGS_BUF_SIZE !!! */
31033115
char *module_flags(struct module *mod, char *buf, bool show_state)
31043116
{

0 commit comments

Comments
 (0)