Exemplo n.º 1
0
/**
 * aa_ptrace - do ptrace permission check and auditing
 * @tracer: task doing the tracing (NOT NULL)
 * @tracee: task being traced (NOT NULL)
 * @mode: ptrace mode either PTRACE_MODE_READ || PTRACE_MODE_ATTACH
 *
 * Returns: %0 else error code if permission denied or error
 */
int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee,
              unsigned int mode)
{
    /*
     * tracer can ptrace tracee when
     * - tracer is unconfined ||
     *   - tracer is in complain mode
     *   - tracer has rules allowing it to trace tracee currently this is:
     *       - confined by the same profile ||
     *       - tracer profile has CAP_SYS_PTRACE
     */

    struct aa_profile *tracer_p;
    /* cred released below */
    const struct cred *cred = get_task_cred(tracer);
    int error = 0;
    tracer_p = aa_cred_profile(cred);

    if (!unconfined(tracer_p)) {
        /* lcred released below */
        const struct cred *lcred = get_task_cred(tracee);
        struct aa_profile *tracee_p = aa_cred_profile(lcred);

        error = aa_may_ptrace(tracer, tracer_p, tracee_p, mode);
        error = aa_audit_ptrace(tracer_p, tracee_p, error);

        put_cred(lcred);
    }
    put_cred(cred);

    return error;
}
Exemplo n.º 2
0
int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee,
	      unsigned int mode)
{
	/*
                                 
                             
                                  
                                                                       
                                           
                                             
  */

	struct aa_profile *tracer_p;
	/*                     */
	const struct cred *cred = get_task_cred(tracer);
	int error = 0;
	tracer_p = aa_cred_profile(cred);

	if (!unconfined(tracer_p)) {
		/*                      */
		const struct cred *lcred = get_task_cred(tracee);
		struct aa_profile *tracee_p = aa_cred_profile(lcred);

		error = aa_may_ptrace(tracer, tracer_p, tracee_p, mode);
		error = aa_audit_ptrace(tracer_p, tracee_p, error);

		put_cred(lcred);
	}
	put_cred(cred);

	return error;
}
Exemplo n.º 3
0
/**
 * aa_task_setrlimit - test permission to set an rlimit
 * @profile - profile confining the task  (NOT NULL)
 * @task - task the resource is being set on
 * @resource - the resource being set
 * @new_rlim - the new resource limit  (NOT NULL)
 *
 * Control raising the processes hard limit.
 *
 * Returns: 0 or error code if setting resource failed
 */
int aa_task_setrlimit(struct aa_profile *profile, struct task_struct *task,
		      unsigned int resource, struct rlimit *new_rlim)
{
	struct aa_profile *task_profile;
	int error = 0;

	rcu_read_lock();
	task_profile = aa_get_profile(aa_cred_profile(__task_cred(task)));
	rcu_read_unlock();

	/* TODO: extend resource control to handle other (non current)
	 * profiles.  AppArmor rules currently have the implicit assumption
	 * that the task is setting the resource of a task confined with
	 * the same profile or that the task setting the resource of another
	 * task has CAP_SYS_RESOURCE.
	 */
	if ((profile != task_profile &&
	     aa_capable(profile, CAP_SYS_RESOURCE, 1)) ||
	    (profile->rlimits.mask & (1 << resource) &&
	     new_rlim->rlim_max > profile->rlimits.limits[resource].rlim_max))
		error = -EACCES;

	aa_put_profile(task_profile);

	return audit_resource(profile, resource, new_rlim->rlim_max, error);
}