Пример #1
0
/** Our implementation of exit(). For DDE purposes this only relates
 * to kernel threads.
 */
void do_exit(long code)
{
	ddekit_thread_t *t = DDEKIT_THREAD(lxtask_to_ddethread(current));
//	printk("Thread %s exits with code %x\n", ddekit_thread_get_name(t), code);

	/* do some cleanup */
	detach_pid(current, 0);
	
	/* goodbye, cruel world... */
	ddekit_thread_exit();
}
Пример #2
0
int run_debugger(pid_t pid) 
{
    pid_t r_pid;
    int status;
    REGS regs;
    procmsg("[+] debugger start...\n");
    printf("[+] start to attach process pid %d\n",pid);
    /* attach process */
    if( -1 == attach_pid(pid)) 
    {
        printf("[-] fail to attach process pid %d\n",pid);
        return -1;
    }
    printf("[+] success to attach process pid %d\n",pid);
    
    if(-1 == (r_pid = waitpid(pid,&status,__WALL))){
        perror("waitpid error");
        return -1;
    }
    if(WIFSTOPPED(status)) 
    { 
        printf("[+] ****** attaching to  process pid %d\n",r_pid);
    
        /* read tracee regs info */
        readRegs(pid, &regs);
        
        printf("press any key to detach:");
        getchar();
    
        printf("[+] start to detach process pid %d\n",pid);
        /* detach process */
        if( -1 == detach_pid(pid)) 
        {
            printf("[-] fail to detach process pid %d\n",pid);
            return -1;
        }
        printf("[+] success to detach process pid %d\n",pid);
    }

    return 0;
}
Пример #3
0
/*
 * This needs some heavy checking ...
 * I just haven't the stomach for it. I also don't fully
 * understand sessions/pgrp etc. Let somebody who does explain it.
 *
 * OK, I think I have the protection semantics right.... this is really
 * only important on a multi-user system anyway, to make sure one user
 * can't send a signal to a process owned by another.  -TYT, 12/12/91
 *
 * Auch. Had to add the 'did_exec' flag to conform completely to POSIX.
 * LBT 04.03.94
 */
asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
{
	struct task_struct *p;
	struct task_struct *group_leader = current->group_leader;
	int err = -EINVAL;
	struct pid_namespace *ns;

	if (!pid)
		pid = task_pid_vnr(group_leader);
	if (!pgid)
		pgid = pid;
	if (pgid < 0)
		return -EINVAL;

	/* From this point forward we keep holding onto the tasklist lock
	 * so that our parent does not change from under us. -DaveM
	 */
	ns = current->nsproxy->pid_ns;

	write_lock_irq(&tasklist_lock);

	err = -ESRCH;
	p = find_task_by_pid_ns(pid, ns);
	if (!p)
		goto out;

	err = -EINVAL;
	if (!thread_group_leader(p))
		goto out;

	if (p->real_parent->tgid == group_leader->tgid) {
		err = -EPERM;
		if (task_session(p) != task_session(group_leader))
			goto out;
		err = -EACCES;
		if (p->did_exec)
			goto out;
	} else {
		err = -ESRCH;
		if (p != group_leader)
			goto out;
	}

	err = -EPERM;
	if (p->signal->leader)
		goto out;

	if (pgid != pid) {
		struct task_struct *g;

		g = find_task_by_pid_type_ns(PIDTYPE_PGID, pgid, ns);
		if (!g || task_session(g) != task_session(group_leader))
			goto out;
	}

	err = security_task_setpgid(p, pgid);
	if (err)
		goto out;

	if (task_pgrp_nr_ns(p, ns) != pgid) {
		struct pid *pid;

		detach_pid(p, PIDTYPE_PGID);
		pid = find_vpid(pgid);
		attach_pid(p, PIDTYPE_PGID, pid);
		set_task_pgrp(p, pid_nr(pid));
	}

	err = 0;
out:
	/* All paths lead to here, thus we are safe. -DaveM */
	write_unlock_irq(&tasklist_lock);
	return err;
}
Пример #4
0
asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
{
	struct task_struct *p;
	int err = -EINVAL;

	if (!pid)
		pid = current->pid;
	if (!pgid)
		pgid = pid;
	if (pgid < 0)
		return -EINVAL;

	/* From this point forward we keep holding onto the tasklist lock
	 * so that our parent does not change from under us. -DaveM
	 */
	write_lock_irq(&tasklist_lock);

	err = -ESRCH;
	p = find_task_by_pid(pid);
	if (!p)
		goto out;

	err = -EINVAL;
	if (!thread_group_leader(p))
		goto out;

	if (p->parent == current || p->real_parent == current) {
		err = -EPERM;
		if (p->signal->session != current->signal->session)
			goto out;
		err = -EACCES;
		if (p->did_exec)
			goto out;
	} else {
		err = -ESRCH;
		if (p != current)
			goto out;
	}

	err = -EPERM;
	if (p->signal->leader)
		goto out;

	if (pgid != pid) {
		struct task_struct *p;

		do_each_task_pid(pgid, PIDTYPE_PGID, p) {
			if (p->signal->session == current->signal->session)
				goto ok_pgid;
		} while_each_task_pid(pgid, PIDTYPE_PGID, p);
		goto out;
	}

ok_pgid:
	err = security_task_setpgid(p, pgid);
	if (err)
		goto out;

	if (process_group(p) != pgid) {
		detach_pid(p, PIDTYPE_PGID);
		p->signal->pgrp = pgid;
		attach_pid(p, PIDTYPE_PGID, pgid);
	}

	err = 0;
out:
	/* All paths lead to here, thus we are safe. -DaveM */
	write_unlock_irq(&tasklist_lock);
	return err;
}
Пример #5
0
/* The arrival of a new process might change a pid mapping on this
 * node.  Update any other processes which might be using that mapping
 * for something */
static
void masq_update_mappings(struct bproc_masq_master_t *m,
			  struct task_struct *proc) {
    struct list_head *l;
    struct task_struct *task;
    int /*id,*/ masq_id, real_id;

    /* Step 1: Our real/masq pid pair defines one masq->real mapping.
     * Any other processes in the system that have our masq pid in
     * their pgrp or session id might have to be updated.  */

    /* TGID: Since we're not allowing thread groups to span multiple
     * nodes, we should never end up with a situation where they're
     * out of sync.  (with multithreaded migration this might be
     * different some day.) */
    masq_id = proc->bproc.pid;
    real_id = proc->pid;
    for (l = m->proc_list.next; l != &m->proc_list; l = l->next) {
	task = list_entry(l, struct task_struct, bproc.list);

	/* tgid shouldn't be necessary since we're not going to allow
	 * thread groups to span nodes. */

	if (task->signal->bproc.pgrp == masq_id &&
	    task->signal->pgrp       != real_id) {
	    detach_pid(task, PIDTYPE_PGID);
	    task->signal->pgrp = real_id;
	    attach_pid(task, PIDTYPE_PGID, real_id);
	}

	if (task->signal->bproc.session == masq_id &&
	    task->signal->session       != real_id) {
	    detach_pid(task, PIDTYPE_SID);
	    task->signal->session = real_id;
	    attach_pid(task, PIDTYPE_SID, real_id);
	}
    }
#if 0
    /* Step 2: Our pgrp and session ID might exist in the system on
     * some other process.  If so, make sure that ours is uptodate as
     * well. */
    if (proc->signal->bproc.pgrp != proc->bproc.pid) {
	id = masq_find_id_mapping(m, proc->signal->bproc.pgrp, proc);
	if (!id)
	    id = alloc_pidmap();
	if (!id)
	    printk(KERN_EMERG "bproc: failed to allocate pid.\n");

	if (proc->signal->pgrp != id) {
	    detach_pid(proc, PIDTYPE_PGID);
	    proc->signal->pgrp = id;
	    attach_pid(proc, PIDTYPE_PGID, id);
	}
    }
    if (proc->signal->bproc.session != proc->bproc.pid) {
	id = masq_find_id_mapping(m, proc->signal->bproc.session, proc);
	if (!id)
	    id = alloc_pidmap();
	if (!id)
	    printk(KERN_EMERG "bproc: failed to allocate pid.\n");

	if (proc->signal->session != id) {
	    detach_pid(proc, PIDTYPE_SID);
	    proc->signal->session = id;
	    attach_pid(proc, PIDTYPE_SID, id);
	}
    }
#endif
}