From: Vyacheslav Cherkashin Date: Thu, 21 May 2015 18:31:10 +0000 (+0300) Subject: [FIX] check_pf_by_comm() X-Git-Tag: submit/tizen/20151123.110932~78 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6e749d72dc8d84cada3f7b37aaddf0471511c50c;p=kernel%2Fswap-modules.git [FIX] check_pf_by_comm() Change-Id: Ic8b1ea648daf8d80c435797aa8331b4eb4358530 Signed-off-by: Vyacheslav Cherkashin --- diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index cc1fa79..9b3e7e3 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -305,6 +305,7 @@ EXPORT_SYMBOL_GPL(get_pf_group_by_tgid); */ struct pf_group *get_pf_group_by_comm(char *comm, void *priv) { + int ret; struct pf_group *pfg; list_for_each_entry(pfg, &pfg_list, list) { @@ -316,7 +317,12 @@ struct pf_group *get_pf_group_by_comm(char *comm, void *priv) if (pfg == NULL) return NULL; - set_pf_by_comm(&pfg->filter, comm, priv); + ret = set_pf_by_comm(&pfg->filter, comm, priv); + if (ret) { + printk(KERN_ERR "ERROR: set_pf_by_comm, ret=%d\n", ret); + free_pfg(pfg); + return NULL; + } add_pfg_by_list(pfg); diff --git a/us_manager/pf/proc_filters.c b/us_manager/pf/proc_filters.c index 64b94d7..ee9cf4c 100644 --- a/us_manager/pf/proc_filters.c +++ b/us_manager/pf/proc_filters.c @@ -144,17 +144,25 @@ void set_pf_by_tgid(struct proc_filter *pf, pid_t tgid, void *priv) * @param pf Pointer to the proc_filter struct * @param comm Task comm * @param priv Private data - * @return Void + * @return 0 on suceess, error code on error. */ -void set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv) +int set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv) { size_t len = strnlen(comm, TASK_COMM_LEN); + char *new_comm = kmalloc(len, GFP_KERNEL); + + if (new_comm == NULL) + return -ENOMEM; + + /* copy comm */ + memcpy(new_comm, comm, len - 1); + new_comm[len - 1] = '\0'; pf->call = &call_by_comm; - pf->data = kmalloc(len, GFP_KERNEL); - memset(pf->data, 0, len); - memcpy(pf->data, comm, len - 1); + pf->data = new_comm; pf->priv = priv; + + return 0; } /** @@ -228,7 +236,7 @@ int check_pf_by_tgid(struct proc_filter *filter, pid_t tgid) int check_pf_by_comm(struct proc_filter *filter, char *comm) { return ((filter->call == &call_by_comm) && (filter->data != NULL) && - (!strncmp(filter->data, comm, TASK_COMM_LEN))); + (!strncmp(filter->data, comm, TASK_COMM_LEN - 1))); } /** diff --git a/us_manager/pf/proc_filters.h b/us_manager/pf/proc_filters.h index 26fe9c3..fe96276 100644 --- a/us_manager/pf/proc_filters.h +++ b/us_manager/pf/proc_filters.h @@ -54,7 +54,7 @@ struct proc_filter { void set_pf_by_dentry(struct proc_filter *pf, struct dentry *dentry, void *priv); void set_pf_by_tgid(struct proc_filter *pf, pid_t tgid, void *priv); -void set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv); +int set_pf_by_comm(struct proc_filter *pf, char *comm, void *priv); void set_pf_dumb(struct proc_filter *pf, void *priv);