struct fbi_step *steps_source;
struct fbi_step *steps_dest = NULL;
uint8_t i;
-
+ int ret = 0;
memcpy(dest, source, sizeof(*source));
vars_size = source->fbi_i.var_count * sizeof(*source->fbi_i.vars);
vars = kmalloc(vars_size, GFP_KERNEL);
+ if (vars == NULL)
+ return -ENOMEM;
+
memcpy(vars, source->fbi_i.vars, vars_size);
for (i = 0; i != source->fbi_i.var_count; i++) {
steps_dest = kmalloc(steps_size, GFP_KERNEL);
if (steps_dest == NULL) {
print_err("can not alloc data\n");
- return -ENOMEM;
+ ret = -ENOMEM;
+ goto err;
}
memcpy(steps_dest, steps_source, steps_size);
dest->fbi_i.vars = vars;
- return 0;
+ return ret;
+err:
+ while (--i >= 0)
+ kfree(vars[i].steps);
+ kfree(vars);
+ return ret;
}
/* Register */
{
#ifdef __HAVE_ARCH_GATE_AREA
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
- struct mm_struct *mm = task->mm;
+ struct mm_struct *mm;
+
+ if (task == NULL)
+ return 0;
+
+ mm = task->mm;
IMP_MOD_DEP_WRAPPER(in_gate_area, mm, addr)
#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
IMP_MOD_DEP_WRAPPER(in_gate_area, task, addr)
chunk->index = kmalloc(sizeof(*chunk->index)*chunk->count_available,
GFP_ATOMIC);
+
+ if (chunk->index == NULL) {
+ printk(KERN_ERR "%s: failed to allocate memory\n", __FUNCTION__);
+ return;
+ }
+
p = chunk->index;
for (i = 0; i != chunk->count_available; ++p)
*p = ++i;
if (IS_ERR_OR_NULL(filename)) {
printk(FOPS_PREFIX "dentry_path_raw FAILED: %ld\n",
PTR_ERR(filename));
- strcpy(buf, NA);
+ strncpy(buf, NA, buflen);
filename = buf;
}
--cnt;
- rpp = kmalloc(GFP_KERNEL, sizeof(&(((struct ks_probe *) 0)->rp)) * cnt);
+ rpp = kmalloc(GFP_KERNEL, sizeof(*rpp) * cnt);
if (rpp == NULL) {
for (; cnt != end; --cnt) {
ret = unregister_syscall(id_p[cnt]);
{
struct probe *p = kzalloc(sizeof(*p), GFP_KERNEL);
+ if (p == NULL)
+ return NULL;
+
p->p.jp.kp.addr = p->p.rp.kp.addr = (void *)addr;
p->p.jp.pre_entry = pre_handler;
p->p.jp.entry = jp_handler;
int i;
unsigned int ret = 0;
+ if (target_binaries_cnt == 0)
+ return 0;
+
__target_binaries_lock();
*filenames_p = kmalloc(sizeof(**filenames_p) * target_binaries_cnt,
*/
static ssize_t loader_path_write(struct file *file, const char __user *buf,
- size_t len, loff_t *ppos)
+ size_t len, loff_t *ppos)
{
ssize_t ret;
char *path;
path = kmalloc(len, GFP_KERNEL);
if (path == NULL) {
- ret = -ENOMEM;
- goto out;
+ return -ENOMEM;
}
if (copy_from_user(path, buf, len)) {
ret = -EINVAL;
- goto out;
+ goto err;
}
path[len - 1] = '\0';
set_loader_file(path);
ret = len;
-out:
+ return ret;
+err:
+ kfree(path);
return ret;
}
/* This function should be called only for current */
struct task_struct *task = current;
- unsigned long page = __get_data_page(pd);
+ unsigned long page = 0;
int ret;
- if (pd == NULL || page == 0)
+ if (pd == NULL)
+ return NULL;
+
+ page = __get_data_page(pd);
+
+ if (page == 0)
return NULL;
- if (pd->is_mapped == 1)
+ if (pd->is_mapped == 1)
return __get_path(pd);
ret = preload_patcher_write_string((void *)page, handlers_info->path,
task);
if (ret <= 0) {
printk(KERN_ERR PRELOAD_PREFIX "Cannot copy string to user!\n");
- goto get_path_failed;
+ goto get_path_failed;
}
- pd->is_mapped = 1;
+ pd->is_mapped = 1;
return __get_path(pd);
get_path_failed:
- return NULL;
+ return NULL;
}
return __get_refcount(pd);
}
-int preload_pd_create_pd(void** target_place, struct task_struct *task)
+int preload_pd_create_pd(void **target_place, struct task_struct *task)
{
- struct process_data *pd;
- unsigned long page = 0;
+ struct process_data *pd;
+ unsigned long page = 0;
unsigned long base;
struct dentry *dentry;
- int ret;
+ int ret = 0;
ret = __pd_create_on_demand();
if (ret)
- goto create_pd_exit;
+ return ret;
pd = kzalloc(sizeof(*pd), GFP_ATOMIC);
- if (pd == NULL) {
- ret = -ENOMEM;
- goto create_pd_exit;
- }
-
- ret = 0;
+ if (pd == NULL)
+ return -ENOMEM;
/* 1. check if loader is already mapped */
dentry = preload_debugfs_get_loader_dentry();
*target_place = pd;
+ return ret;
+
create_pd_exit:
+ kfree(pd);
return ret;
}
unsigned long get_preload_flags(struct task_struct *task)
{
- return get_preload_td(task)->flags;
+ struct preload_td *td = get_preload_td(task);
+
+ if (td == NULL)
+ return 0;
+
+ return td->flags;
}
void set_preload_flags(struct task_struct *task,
unsigned long flags)
{
- get_preload_td(task)->flags = flags;
+ struct preload_td *td = get_preload_td(task);
+
+ if (td == NULL) {
+ printk(KERN_ERR "%s: invalid arguments\n", __FUNCTION__);
+ return;
+ }
+
+ td->flags = flags;
}
{
struct preload_td *td = get_preload_td(task);
+ if (td == NULL)
+ return NULL;
+
return list_empty(&td->slots) ? NULL :
list_last_entry(&td->slots, struct thread_slot, list);
}
*/
void sampler_timers_set_quantum(unsigned int timer_quantum)
{
- sampler_timer_quantum = timer_quantum * 1000 * 1000;
+ u64 tmp = (u64)timer_quantum;
+ sampler_timer_quantum = tmp * 1000 * 1000;
}
switch (n) {
case 0:
regs->ARM_r0 = val;
+ break;
case 1:
regs->ARM_r1 = val;
+ break;
case 2:
regs->ARM_r2 = val;
+ break;
case 3:
regs->ARM_r3 = val;
+ break;
}
ptr = (u32 *)regs->ARM_sp + n - 4;
if (!sspt_proc_is_send_event(proc))
return;
- sprintf(pid_str, "%d", proc->tgid);
+ snprintf(pid_str, sizeof(pid_str), "%d", proc->tgid);
len = strlen(pid_str);
}
ip = create_img_ip(addr, probe_i);
+ if (ip == NULL)
+ return -ENOMEM;
+
img_add_ip_by_list(file, ip);
return 0;
{
struct pl_struct *pls = kmalloc(sizeof(*pls), GFP_KERNEL);
+ if (pls == NULL)
+ return NULL;
+
INIT_LIST_HEAD(&pls->list);
pls->proc = proc;
case PIF_FIRST:
case PIF_ADD_PFG:
proc = sspt_proc_get_by_task(task);
- first_install(task, proc);
+ if (proc)
+ first_install(task, proc);
break;
case PIF_NONE:
case PIF_FIRST:
case PIF_ADD_PFG:
proc = sspt_proc_get_by_task(task);
- first_install(task, proc);
+ if (proc)
+ first_install(task, proc);
break;
case PIF_SECOND:
proc = sspt_proc_get_by_task(task);
- subsequent_install(task, proc, page_addr);
+ if (proc)
+ subsequent_install(task, proc, page_addr);
break;
case PIF_NONE:
break;
case US_DISARM:
up = probe_info_get_uprobe(ip->info, ip);
- disarm_uprobe(&up->kp, task);
+ if (up)
+ disarm_uprobe(&up->kp, task);
break;
case US_UNINSTALL:
probe_info_unregister(ip->info, ip, 0);
spin_lock_irqsave(&feature_img_lock, flags);
list_for_each_entry(fi, &feature_img_list, list) {
fd = create_feature_data(fi);
-
- /* add to list */
- list_add(&fd->list, &f->feature_list);
+ if (fd) /* add to list */
+ list_add(&fd->list, &f->feature_list);
}
spin_unlock_irqrestore(&feature_img_lock, flags);
}
*/
struct sspt_file *sspt_file_create(struct dentry *dentry, int page_cnt)
{
+ int i, table_size;
struct sspt_file *obj = kmalloc(sizeof(*obj), GFP_ATOMIC);
- if (obj) {
- int i, table_size;
- INIT_LIST_HEAD(&obj->list);
- obj->proc = NULL;
- obj->dentry = dentry;
- obj->loaded = 0;
- obj->vm_start = 0;
- obj->vm_end = 0;
+ if (obj == NULL)
+ return NULL;
+
+ INIT_LIST_HEAD(&obj->list);
+ obj->proc = NULL;
+ obj->dentry = dentry;
+ obj->loaded = 0;
+ obj->vm_start = 0;
+ obj->vm_end = 0;
- obj->page_probes_hash_bits = calculation_hash_bits(page_cnt);
- table_size = (1 << obj->page_probes_hash_bits);
+ obj->page_probes_hash_bits = calculation_hash_bits(page_cnt);
+ table_size = (1 << obj->page_probes_hash_bits);
- obj->page_probes_table =
+ obj->page_probes_table =
kmalloc(sizeof(*obj->page_probes_table)*table_size,
GFP_ATOMIC);
- for (i = 0; i < table_size; ++i)
- INIT_HLIST_HEAD(&obj->page_probes_table[i]);
- }
+ if (obj->page_probes_table == NULL)
+ goto err;
+
+ for (i = 0; i < table_size; ++i)
+ INIT_HLIST_HEAD(&obj->page_probes_table[i]);
return obj;
+
+err:
+ kfree(obj);
+ return NULL;
}
/**
if (page == NULL) {
page = sspt_page_create(offset);
- sspt_add_page(file, page);
+ if (page)
+ sspt_add_page(file, page);
}
return page;
/* FIXME: delete ip */
struct us_ip *ip = create_ip(offset, probe_i, page);
- sspt_add_ip(page, ip);
+ if (page && ip)
+ sspt_add_ip(page, ip);
}
/**
file = sspt_proc_find_file(proc, dentry);
if (file == NULL) {
file = sspt_file_create(dentry, 10);
- sspt_proc_add_file(proc, file);
+ if (file)
+ sspt_proc_add_file(proc, file);
}
return file;
struct slot_manager *create_sm_us(struct task_struct *task)
{
struct slot_manager *sm = kmalloc(sizeof(*sm), GFP_ATOMIC);
+
+ if (sm == NULL)
+ return NULL;
+
sm->slot_size = UPROBES_TRAMP_LEN;
sm->alloc = sm_alloc_us;
sm->free = sm_free_us;
static ssize_t write_app_info(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos)
{
- int ret;
+ int ret = 0;
char *buf, *path, *id;
int n;
}
web_prof_data_set(path, id);
- sprintf(app_info, "%s\n", buf);
+ snprintf(app_info, sizeof(app_info), "%s\n", buf);
free_app_info:
kfree(id);
ssize_t ret;
buf = kmalloc(len + 2, GFP_KERNEL);
- memcpy(buf, name, len);
+ if (buf == NULL)
+ return -ENOMEM;
+ memcpy(buf, name, len);
buf[len] = '\0';
buf[len + 1] = '\n';
switch (fmt[fmt_i]) {
case 'b': /* 1 byte(bool) */
- if (len < 1)
- return -ENOMEM;
*buf = (char)!!get_arg(regs, i);
buf += 1;
len -= 1;
break;
case 'c': /* 1 byte(char) */
- if (len < 1)
- return -ENOMEM;
*buf = (char)get_arg(regs, i);
buf += 1;
len -= 1;