* Shared /dev/zero support, Kanoj Sarcar <kanoj@sgi.com>
* Move the mm functionality over to mm/shmem.c, Christoph Rohland <cr@sap.com>
*
- * support for audit of ipc object properties and permission changes
- * Dustin Kirkland <dustin.kirkland@us.ibm.com>
*/
#include <linux/config.h>
#include <linux/capability.h>
#include <linux/ptrace.h>
#include <linux/seq_file.h>
-#include <linux/mutex.h>
#include <linux/vs_context.h>
#include <linux/vs_limit.h>
static inline void shm_inc (int id) {
struct shmid_kernel *shp;
- shp = shm_lock(id);
- BUG_ON(!shp);
+ if(!(shp = shm_lock(id)))
+ BUG();
shp->shm_atim = get_seconds();
shp->shm_lprid = current->tgid;
shp->shm_nattch++;
*
* @shp: struct to free
*
- * It has to be called with shp and shm_ids.mutex locked,
+ * It has to be called with shp and shm_ids.sem locked,
* but returns with shp unlocked and freed.
*/
static void shm_destroy (struct shmid_kernel *shp)
int id = file->f_dentry->d_inode->i_ino;
struct shmid_kernel *shp;
- mutex_lock(&shm_ids.mutex);
+ down (&shm_ids.sem);
/* remove from the list of attaches of the shm segment */
- shp = shm_lock(id);
- BUG_ON(!shp);
+ if(!(shp = shm_lock(id)))
+ BUG();
shp->shm_lprid = current->tgid;
shp->shm_dtim = get_seconds();
shp->shm_nattch--;
shm_destroy (shp);
else
shm_unlock(shp);
- mutex_unlock(&shm_ids.mutex);
+ up (&shm_ids.sem);
}
static int shm_mmap(struct file * file, struct vm_area_struct * vma)
struct shmid_kernel *shp;
int err, id = 0;
- mutex_lock(&shm_ids.mutex);
+ down(&shm_ids.sem);
if (key == IPC_PRIVATE) {
err = newseg(key, shmflg, size);
} else if ((id = ipc_findkey(&shm_ids, key)) == -1) {
err = -EEXIST;
} else {
shp = shm_lock(id);
- BUG_ON(shp==NULL);
+ if(shp==NULL)
+ BUG();
if (shp->shm_segsz < size)
err = -EINVAL;
else if (ipcperms(&shp->shm_perm, shmflg))
}
shm_unlock(shp);
}
- mutex_unlock(&shm_ids.mutex);
+ up(&shm_ids.sem);
return err;
}
return err;
memset(&shm_info,0,sizeof(shm_info));
- mutex_lock(&shm_ids.mutex);
+ down(&shm_ids.sem);
shm_info.used_ids = shm_ids.in_use;
shm_get_stat (&shm_info.shm_rss, &shm_info.shm_swp);
shm_info.shm_tot = shm_tot;
shm_info.swap_attempts = 0;
shm_info.swap_successes = 0;
err = shm_ids.max_id;
- mutex_unlock(&shm_ids.mutex);
+ up(&shm_ids.sem);
if(copy_to_user (buf, &shm_info, sizeof(shm_info))) {
err = -EFAULT;
goto out;
if(err)
goto out_unlock;
- err = audit_ipc_obj(&(shp->shm_perm));
- if (err)
- goto out_unlock;
-
if (!capable(CAP_IPC_LOCK)) {
err = -EPERM;
if (current->euid != shp->shm_perm.uid &&
* Instead we set a destroyed flag, and then blow
* the name away when the usage hits zero.
*/
- mutex_lock(&shm_ids.mutex);
+ down(&shm_ids.sem);
shp = shm_lock(shmid);
err = -EINVAL;
if (shp == NULL)
if(err)
goto out_unlock_up;
- err = audit_ipc_obj(&(shp->shm_perm));
- if (err)
- goto out_unlock_up;
-
if (current->euid != shp->shm_perm.uid &&
current->euid != shp->shm_perm.cuid &&
!capable(CAP_SYS_ADMIN)) {
shm_unlock(shp);
} else
shm_destroy (shp);
- mutex_unlock(&shm_ids.mutex);
+ up(&shm_ids.sem);
goto out;
}
err = -EFAULT;
goto out;
}
- mutex_lock(&shm_ids.mutex);
+ if ((err = audit_ipc_perms(0, setbuf.uid, setbuf.gid, setbuf.mode)))
+ return err;
+ down(&shm_ids.sem);
shp = shm_lock(shmid);
err=-EINVAL;
if(shp==NULL)
err = shm_checkid(shp,shmid);
if(err)
goto out_unlock_up;
- err = audit_ipc_obj(&(shp->shm_perm));
- if (err)
- goto out_unlock_up;
- err = audit_ipc_set_perm(0, setbuf.uid, setbuf.gid, setbuf.mode, &(shp->shm_perm));
- if (err)
- goto out_unlock_up;
err=-EPERM;
if (current->euid != shp->shm_perm.uid &&
current->euid != shp->shm_perm.cuid &&
out_unlock_up:
shm_unlock(shp);
out_up:
- mutex_unlock(&shm_ids.mutex);
+ up(&shm_ids.sem);
goto out;
out_unlock:
shm_unlock(shp);
invalid:
up_write(¤t->mm->mmap_sem);
- mutex_lock(&shm_ids.mutex);
- shp = shm_lock(shmid);
- BUG_ON(!shp);
+ down (&shm_ids.sem);
+ if(!(shp = shm_lock(shmid)))
+ BUG();
shp->shm_nattch--;
if(shp->shm_nattch == 0 &&
shp->shm_perm.mode & SHM_DEST)
shm_destroy (shp);
else
shm_unlock(shp);
- mutex_unlock(&shm_ids.mutex);
+ up (&shm_ids.sem);
*raddr = (unsigned long) user_addr;
err = 0;
loff_t size = 0;
int retval = -EINVAL;
- if (addr & ~PAGE_MASK)
- return retval;
-
down_write(&mm->mmap_sem);
/*