Re: Problems with some of the current hooks

From: Stephen Smalley (sdsat_private)
Date: Mon Aug 06 2001 - 13:47:21 PDT

  • Next message: richard offer: "Re: Making forward progress"

    I've attached another patch, relative to the previous patch,
    that moves several other hook functions after the DAC logic.
    Specifically, this patch moves the setattr, ptrace, 
    setscheduler, setnice, and setpgid hook calls.
    
    --
    Stephen D. Smalley, NAI Labs
    ssmalleyat_private
    
    
    
    
    diff -X /home/sds/dontdiff -ru lsm.old/fs/attr.c lsm.new/fs/attr.c
    --- lsm.old/fs/attr.c	Mon Jun 18 13:22:05 2001
    +++ lsm.new/fs/attr.c	Mon Aug  6 11:39:49 2001
    @@ -121,17 +121,17 @@
     		attr->ia_mtime = now;
     
     	lock_kernel();
    -	error = security_ops->inode_ops->setattr(dentry, attr);
    -	if (error)
    -		goto unlock_and_out;
    -	if (inode->i_op && inode->i_op->setattr) 
    -		error = inode->i_op->setattr(dentry, attr);
    -	else {
    +	if (inode->i_op && inode->i_op->setattr) {
    +		error = security_ops->inode_ops->setattr(dentry, attr);
    +		if (!error)
    +			error = inode->i_op->setattr(dentry, attr);
    +	} else {
     		error = inode_change_ok(inode, attr);
     		if (!error)
    +			error = security_ops->inode_ops->setattr(dentry, attr);
    +		if (!error)
     			inode_setattr(inode, attr);
     	}
    -unlock_and_out:
     	unlock_kernel();
     	if (!error) {
     		unsigned long dn_mask = setattr_mask(ia_valid);
    diff -X /home/sds/dontdiff -ru lsm.old/kernel/ptrace.c lsm.new/kernel/ptrace.c
    --- lsm.old/kernel/ptrace.c	Wed Aug  1 08:53:30 2001
    +++ lsm.new/kernel/ptrace.c	Mon Aug  6 11:47:42 2001
    @@ -20,9 +20,6 @@
     {
     	int retval;
     	task_lock(task);
    -	retval = security_ops->ptrace(current, task);
    -	if (retval)
    -		goto bad;
     	retval = -EPERM;
     	if (task->pid <= 1)
     		goto bad;
    @@ -42,6 +39,9 @@
     		goto bad;
     	/* the same process cannot be attached many times */
     	if (task->ptrace & PT_PTRACED)
    +		goto bad;
    +	retval = security_ops->ptrace(current, task);
    +	if (retval)
     		goto bad;
     
     	/* Go */
    diff -X /home/sds/dontdiff -ru lsm.old/kernel/sched.c lsm.new/kernel/sched.c
    --- lsm.old/kernel/sched.c	Thu Aug  2 14:50:06 2001
    +++ lsm.new/kernel/sched.c	Mon Aug  6 11:56:17 2001
    @@ -956,16 +956,16 @@
     	if ((policy == SCHED_OTHER) != (lp.sched_priority == 0))
     		goto out_unlock;
     
    -	retval = security_ops->task_ops->setscheduler(p, policy, &lp);
    -	if (retval)
    -		goto out_unlock;
    -
     	retval = -EPERM;
     	if ((policy == SCHED_FIFO || policy == SCHED_RR) && 
     	    !capable(CAP_SYS_NICE))
     		goto out_unlock;
     	if ((current->euid != p->euid) && (current->euid != p->uid) &&
     	    !capable(CAP_SYS_NICE))
    +		goto out_unlock;
    +
    +	retval = security_ops->task_ops->setscheduler(p, policy, &lp);
    +	if (retval)
     		goto out_unlock;
     
     	retval = 0;
    diff -X /home/sds/dontdiff -ru lsm.old/kernel/sys.c lsm.new/kernel/sys.c
    --- lsm.old/kernel/sys.c	Mon Aug  6 16:38:03 2001
    +++ lsm.new/kernel/sys.c	Mon Aug  6 12:07:10 2001
    @@ -214,22 +214,23 @@
     		int no_nice;
     		if (!proc_sel(p, which, who))
     			continue;
    -		no_nice = security_ops->task_ops->setnice(p, niceval);
    -		if (no_nice) {
    -			error = no_nice;
    -			continue;
    -		}
     		if (p->uid != current->euid &&
     			p->uid != current->uid && !capable(CAP_SYS_NICE)) {
     			error = -EPERM;
     			continue;
     		}
    +		if (niceval < p->nice && !capable(CAP_SYS_NICE)) {
    +			error = -EACCES;
    +			continue;
    +		}
    +		no_nice = security_ops->task_ops->setnice(p, niceval);
    +		if (no_nice) {
    +			error = no_nice;
    +			continue;
    +		}
     		if (error == -ESRCH)
     			error = 0;
    -		if (niceval < p->nice && !capable(CAP_SYS_NICE))
    -			error = -EACCES;
    -		else
    -			p->nice = niceval;
    +		p->nice = niceval;
     	}
     	read_unlock(&tasklist_lock);
     
    @@ -818,10 +819,6 @@
     	if (!p)
     		goto out;
     
    -	err = security_ops->task_ops->setpgid(p, pgid);
    -	if (err)
    -		goto out;
    -
     	if (p->p_pptr == current || p->p_opptr == current) {
     		err = -EPERM;
     		if (p->session != current->session)
    @@ -845,6 +842,10 @@
     	}
     
     ok_pgid:
    +	err = security_ops->task_ops->setpgid(p, pgid);
    +	if (err)
    +		goto out;
    +
     	p->pgrp = pgid;
     	err = 0;
     out:
    
    _______________________________________________
    linux-security-module mailing list
    linux-security-moduleat_private
    http://mail.wirex.com/mailman/listinfo/linux-security-module
    



    This archive was generated by hypermail 2b30 : Mon Aug 06 2001 - 13:48:48 PDT