]> bbs.cooldavid.org Git - net-next-2.6.git/blobdiff - fs/open.c
LSM: Add security_path_chroot().
[net-next-2.6.git] / fs / open.c
index 31191bf513e40ebcbd05668cc0db2bc46c1c1311..201041dfca5758207fa2491bb0055079d335e747 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -290,10 +290,9 @@ out:
        return error;
 }
 
-SYSCALL_DEFINE2(truncate, const char __user *, path, unsigned long, length)
+SYSCALL_DEFINE2(truncate, const char __user *, path, long, length)
 {
-       /* on 32-bit boxen it will cut the range 2^31--2^32-1 off */
-       return do_sys_truncate(path, (long)length);
+       return do_sys_truncate(path, length);
 }
 
 static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
@@ -588,6 +587,9 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
        error = -EPERM;
        if (!capable(CAP_SYS_CHROOT))
                goto dput_and_out;
+       error = security_path_chroot(&path);
+       if (error)
+               goto dput_and_out;
 
        set_fs_root(current->fs, &path);
        error = 0;
@@ -617,6 +619,9 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
        err = mnt_want_write_file(file);
        if (err)
                goto out_putf;
+       err = security_path_chmod(dentry, file->f_vfsmnt, mode);
+       if (err)
+               goto out_drop_write;
        mutex_lock(&inode->i_mutex);
        if (mode == (mode_t) -1)
                mode = inode->i_mode;
@@ -624,6 +629,7 @@ SYSCALL_DEFINE2(fchmod, unsigned int, fd, mode_t, mode)
        newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
        err = notify_change(dentry, &newattrs);
        mutex_unlock(&inode->i_mutex);
+out_drop_write:
        mnt_drop_write(file->f_path.mnt);
 out_putf:
        fput(file);
@@ -646,6 +652,9 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
        error = mnt_want_write(path.mnt);
        if (error)
                goto dput_and_out;
+       error = security_path_chmod(path.dentry, path.mnt, mode);
+       if (error)
+               goto out_drop_write;
        mutex_lock(&inode->i_mutex);
        if (mode == (mode_t) -1)
                mode = inode->i_mode;
@@ -653,6 +662,7 @@ SYSCALL_DEFINE3(fchmodat, int, dfd, const char __user *, filename, mode_t, mode)
        newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
        error = notify_change(path.dentry, &newattrs);
        mutex_unlock(&inode->i_mutex);
+out_drop_write:
        mnt_drop_write(path.mnt);
 dput_and_out:
        path_put(&path);
@@ -701,7 +711,9 @@ SYSCALL_DEFINE3(chown, const char __user *, filename, uid_t, user, gid_t, group)
        error = mnt_want_write(path.mnt);
        if (error)
                goto out_release;
-       error = chown_common(path.dentry, user, group);
+       error = security_path_chown(&path, user, group);
+       if (!error)
+               error = chown_common(path.dentry, user, group);
        mnt_drop_write(path.mnt);
 out_release:
        path_put(&path);
@@ -726,7 +738,9 @@ SYSCALL_DEFINE5(fchownat, int, dfd, const char __user *, filename, uid_t, user,
        error = mnt_want_write(path.mnt);
        if (error)
                goto out_release;
-       error = chown_common(path.dentry, user, group);
+       error = security_path_chown(&path, user, group);
+       if (!error)
+               error = chown_common(path.dentry, user, group);
        mnt_drop_write(path.mnt);
 out_release:
        path_put(&path);
@@ -745,7 +759,9 @@ SYSCALL_DEFINE3(lchown, const char __user *, filename, uid_t, user, gid_t, group
        error = mnt_want_write(path.mnt);
        if (error)
                goto out_release;
-       error = chown_common(path.dentry, user, group);
+       error = security_path_chown(&path, user, group);
+       if (!error)
+               error = chown_common(path.dentry, user, group);
        mnt_drop_write(path.mnt);
 out_release:
        path_put(&path);
@@ -768,7 +784,9 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group)
                goto out_fput;
        dentry = file->f_path.dentry;
        audit_inode(NULL, dentry);
-       error = chown_common(dentry, user, group);
+       error = security_path_chown(&file->f_path, user, group);
+       if (!error)
+               error = chown_common(dentry, user, group);
        mnt_drop_write(file->f_path.mnt);
 out_fput:
        fput(file);