BACKPORT: umh: add exit routine for UMH process
A UMH process which is created by the fork_usermode_blob() such as bpfilter needs to release members of the umh_info when process is terminated. But the do_exit() does not release members of the umh_info. hence module which uses UMH needs own code to detect whether UMH process is terminated or not. But this implementation needs extra code for checking the status of UMH process. it eventually makes the code more complex. The new PF_UMH flag is added and it is used to identify UMH processes. The exit_umh() does not release members of the umh_info. Hence umh_info->cleanup callback should release both members of the umh_info and the private data. Suggested-by: David S. Miller <davem@davemloft.net> Change-Id: I280bc1d8a89c544dfb215a63e45f79e39f39c2a2 Signed-off-by: Taehee Yoo <ap420073@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sorayukii <sorayukii69@gmail.com>
This commit is contained in:
parent
2399740568
commit
c205e65605
4 changed files with 43 additions and 2 deletions
|
|
@ -2535,6 +2535,7 @@ extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut,
|
|||
#define PF_SWAPWRITE 0x00800000 /* Allowed to write to swap */
|
||||
#define PF_MEMSTALL 0x01000000 /* Stalled due to lack of memory */
|
||||
#define PF_MIGRATE_ED_TASK 0x02000000 /* early detection task migration */
|
||||
#define PF_UMH 0x02000000 /* I'm an Usermodehelper process */
|
||||
#define PF_NO_SETAFFINITY 0x04000000 /* Userland is not allowed to meddle with cpus_allowed */
|
||||
#define PF_MCE_EARLY 0x08000000 /* Early kill for mce process policy */
|
||||
#define PF_MIGRATE_CUM_ADJ_TASK 0x10000000 /* cumulative task adjustment should be done */
|
||||
|
|
@ -3924,6 +3925,14 @@ static inline void inc_syscfs(struct task_struct *tsk)
|
|||
#define TASK_SIZE_OF(tsk) TASK_SIZE
|
||||
#endif
|
||||
|
||||
void __exit_umh(struct task_struct *tsk);
|
||||
|
||||
static inline void exit_umh(struct task_struct *tsk)
|
||||
{
|
||||
if (unlikely(tsk->flags & PF_UMH))
|
||||
__exit_umh(tsk);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MEMCG
|
||||
extern void mm_update_next_owner(struct mm_struct *mm);
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ struct umh_info {
|
|||
const char *cmdline;
|
||||
struct file *pipe_to_umh;
|
||||
struct file *pipe_from_umh;
|
||||
struct list_head list;
|
||||
void (*cleanup)(struct umh_info *info);
|
||||
pid_t pid;
|
||||
};
|
||||
int fork_usermode_blob(void *data, size_t len, struct umh_info *info);
|
||||
|
|
|
|||
|
|
@ -844,6 +844,7 @@ void __noreturn do_exit(long code)
|
|||
exit_task_namespaces(tsk);
|
||||
exit_task_work(tsk);
|
||||
exit_thread(tsk);
|
||||
exit_umh(tsk);
|
||||
|
||||
/*
|
||||
* Flush inherited counters to the parent - before the parent
|
||||
|
|
|
|||
33
kernel/umh.c
33
kernel/umh.c
|
|
@ -37,6 +37,8 @@ static kernel_cap_t usermodehelper_bset = CAP_FULL_SET;
|
|||
static kernel_cap_t usermodehelper_inheritable = CAP_FULL_SET;
|
||||
static DEFINE_SPINLOCK(umh_sysctl_lock);
|
||||
static DECLARE_RWSEM(umhelper_sem);
|
||||
static LIST_HEAD(umh_list);
|
||||
static DEFINE_MUTEX(umh_list_lock);
|
||||
|
||||
static void call_usermodehelper_freeinfo(struct subprocess_info *info)
|
||||
{
|
||||
|
|
@ -108,10 +110,12 @@ static int call_usermodehelper_exec_async(void *data)
|
|||
commit_creds(new);
|
||||
|
||||
sub_info->pid = task_pid_nr(current);
|
||||
if (sub_info->file)
|
||||
if (sub_info->file) {
|
||||
retval = do_execve_file(sub_info->file,
|
||||
sub_info->argv, sub_info->envp);
|
||||
else
|
||||
if (!retval)
|
||||
current->flags |= PF_UMH;
|
||||
} else
|
||||
retval = do_execve(getname_kernel(sub_info->path),
|
||||
(const char __user *const __user *)sub_info->argv,
|
||||
(const char __user *const __user *)sub_info->envp);
|
||||
|
|
@ -519,6 +523,11 @@ int fork_usermode_blob(void *data, size_t len, struct umh_info *info)
|
|||
goto out;
|
||||
|
||||
err = call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC);
|
||||
if (!err) {
|
||||
mutex_lock(&umh_list_lock);
|
||||
list_add(&info->list, &umh_list);
|
||||
mutex_unlock(&umh_list_lock);
|
||||
}
|
||||
out:
|
||||
fput(file);
|
||||
return err;
|
||||
|
|
@ -672,6 +681,26 @@ static int proc_cap_handler(struct ctl_table *table, int write,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void __exit_umh(struct task_struct *tsk)
|
||||
{
|
||||
struct umh_info *info;
|
||||
pid_t pid = tsk->pid;
|
||||
|
||||
mutex_lock(&umh_list_lock);
|
||||
list_for_each_entry(info, &umh_list, list) {
|
||||
if (info->pid == pid) {
|
||||
list_del(&info->list);
|
||||
mutex_unlock(&umh_list_lock);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
mutex_unlock(&umh_list_lock);
|
||||
return;
|
||||
out:
|
||||
if (info->cleanup)
|
||||
info->cleanup(info);
|
||||
}
|
||||
|
||||
struct ctl_table usermodehelper_table[] = {
|
||||
{
|
||||
.procname = "bset",
|
||||
|
|
|
|||
Loading…
Reference in a new issue