Compare commits

...

2 Commits
1.7.3 ... 1.7.4

Author SHA1 Message Date
3084db8b26 release: 1.7.4: fix missing fput of executable
Change-Id: If3e2bb10bd21515876c5a37839cd9fcf12774329
2021-03-07 17:44:53 +09:00
cba263ff12 mcexec_open_exec: guard fput and add to mckernel_exec_files with spin_lock_irqsave
Change-Id: Id5dae8cb7f947d4e9939bf9c6762c2d1dcdd3776
2021-03-07 17:39:16 +09:00
2 changed files with 23 additions and 28 deletions

View File

@ -7,7 +7,7 @@ endif (NOT CMAKE_BUILD_TYPE)
enable_language(C ASM) enable_language(C ASM)
project(mckernel C ASM) project(mckernel C ASM)
set(MCKERNEL_VERSION "1.7.3") set(MCKERNEL_VERSION "1.7.4")
# See "Fedora Packaging Guidelines -- Versioning" # See "Fedora Packaging Guidelines -- Versioning"
set(MCKERNEL_RELEASE "") set(MCKERNEL_RELEASE "")

View File

@ -1799,8 +1799,7 @@ out:
} }
LIST_HEAD(mckernel_exec_files); LIST_HEAD(mckernel_exec_files);
DEFINE_SEMAPHORE(mckernel_exec_file_lock); static DEFINE_SPINLOCK(mckernel_exec_file_lock);
struct mckernel_exec_file { struct mckernel_exec_file {
ihk_os_t os; ihk_os_t os;
@ -1977,6 +1976,7 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
char *fullpath = NULL; char *fullpath = NULL;
char *kfilename = NULL; char *kfilename = NULL;
int len; int len;
unsigned long flags;
if (os_ind < 0) { if (os_ind < 0) {
return -EINVAL; return -EINVAL;
@ -1991,38 +1991,39 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
kfilename = kmalloc(PATH_MAX, GFP_KERNEL); kfilename = kmalloc(PATH_MAX, GFP_KERNEL);
if (!kfilename) { if (!kfilename) {
retval = -ENOMEM; retval = -ENOMEM;
kfree(pathbuf);
goto out; goto out;
} }
len = strncpy_from_user(kfilename, filename, PATH_MAX); len = strncpy_from_user(kfilename, filename, PATH_MAX);
if (unlikely(len < 0)) { if (unlikely(len < 0)) {
retval = -EINVAL; retval = -EINVAL;
goto out_free; goto out;
} }
/* fget and list_add should be atomic */ /* fget and list_add should not be interrupted by hardware interrupt */
down(&mckernel_exec_file_lock); spin_lock_irqsave(&mckernel_exec_file_lock, flags);
file = open_exec(kfilename); file = open_exec(kfilename);
retval = PTR_ERR(file); retval = PTR_ERR(file);
if (IS_ERR(file)) { if (IS_ERR(file)) {
up(&mckernel_exec_file_lock); spin_unlock_irqrestore(&mckernel_exec_file_lock, flags);
goto out_free; goto out;
} }
fullpath = d_path(&file->f_path, pathbuf, PATH_MAX); fullpath = d_path(&file->f_path, pathbuf, PATH_MAX);
if (IS_ERR(fullpath)) { if (IS_ERR(fullpath)) {
up(&mckernel_exec_file_lock); fput(file);
spin_unlock_irqrestore(&mckernel_exec_file_lock, flags);
retval = PTR_ERR(fullpath); retval = PTR_ERR(fullpath);
goto out_put_file; goto out;
} }
mcef = kmalloc(sizeof(*mcef), GFP_KERNEL); mcef = kmalloc(sizeof(*mcef), GFP_KERNEL);
if (!mcef) { if (!mcef) {
up(&mckernel_exec_file_lock); fput(file);
spin_unlock_irqrestore(&mckernel_exec_file_lock, flags);
retval = -ENOMEM; retval = -ENOMEM;
goto out_put_file; goto out;
} }
memset(mcef, 0, sizeof(struct mckernel_exec_file)); /* debug */ memset(mcef, 0, sizeof(struct mckernel_exec_file)); /* debug */
@ -2046,22 +2047,15 @@ int mcexec_open_exec(ihk_os_t os, char * __user filename)
/* Create /proc/self/exe entry */ /* Create /proc/self/exe entry */
add_pid_entry(os_ind, task_tgid_vnr(current)); add_pid_entry(os_ind, task_tgid_vnr(current));
proc_exe_link(os_ind, task_tgid_vnr(current), fullpath); proc_exe_link(os_ind, task_tgid_vnr(current), fullpath);
up(&mckernel_exec_file_lock); spin_unlock_irqrestore(&mckernel_exec_file_lock, flags);
dprintk("%d open_exec and holding file: %s\n", (int)task_tgid_vnr(current), dprintk("%d open_exec and holding file: %s\n", (int)task_tgid_vnr(current),
kfilename); kfilename);
kfree(kfilename); retval = 0;
kfree(pathbuf);
return 0;
out_put_file:
fput(file);
out_free:
kfree(pathbuf);
kfree(kfilename);
out: out:
kfree(pathbuf);
kfree(kfilename);
return retval; return retval;
} }
@ -2070,12 +2064,13 @@ int mcexec_close_exec(ihk_os_t os, int pid)
struct mckernel_exec_file *mcef = NULL; struct mckernel_exec_file *mcef = NULL;
int found = 0; int found = 0;
int os_ind = ihk_host_os_get_index(os); int os_ind = ihk_host_os_get_index(os);
unsigned long flags;
if (os_ind < 0) { if (os_ind < 0) {
return EINVAL; return EINVAL;
} }
down(&mckernel_exec_file_lock); spin_lock_irqsave(&mckernel_exec_file_lock, flags);
list_for_each_entry(mcef, &mckernel_exec_files, list) { list_for_each_entry(mcef, &mckernel_exec_files, list) {
if (mcef->os == os && mcef->pid == pid) { if (mcef->os == os && mcef->pid == pid) {
allow_write_access(mcef->fp); allow_write_access(mcef->fp);
@ -2088,7 +2083,7 @@ int mcexec_close_exec(ihk_os_t os, int pid)
} }
} }
up(&mckernel_exec_file_lock); spin_unlock_irqrestore(&mckernel_exec_file_lock, flags);
return (found ? 0 : EINVAL); return (found ? 0 : EINVAL);
} }