mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-29 03:01:39 -04:00
[PATCH] r/o bind mounts: elevate write count for ioctls()
Some ioctl()s can cause writes to the filesystem. Take these, and make them use mnt_want/drop_write() instead. [AV: updated] Acked-by: Al Viro <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]> Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Al Viro <[email protected]>
This commit is contained in:
parent
20ddee2c75
commit
42a74f206b
9 changed files with 265 additions and 155 deletions
|
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include <linux/capability.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/mount.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/xattr.h>
|
||||
#include <asm/uaccess.h>
|
||||
|
|
@ -35,25 +36,32 @@ int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
flags |= FS_NODUMP_FL; /* EXT2_NODUMP_FL */
|
||||
return put_user(flags, (int __user *)arg);
|
||||
case HFSPLUS_IOC_EXT2_SETFLAGS: {
|
||||
if (IS_RDONLY(inode))
|
||||
return -EROFS;
|
||||
|
||||
if (!is_owner_or_cap(inode))
|
||||
return -EACCES;
|
||||
|
||||
if (get_user(flags, (int __user *)arg))
|
||||
return -EFAULT;
|
||||
int err = 0;
|
||||
err = mnt_want_write(filp->f_path.mnt);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (!is_owner_or_cap(inode)) {
|
||||
err = -EACCES;
|
||||
goto setflags_out;
|
||||
}
|
||||
if (get_user(flags, (int __user *)arg)) {
|
||||
err = -EFAULT;
|
||||
goto setflags_out;
|
||||
}
|
||||
if (flags & (FS_IMMUTABLE_FL|FS_APPEND_FL) ||
|
||||
HFSPLUS_I(inode).rootflags & (HFSPLUS_FLG_IMMUTABLE|HFSPLUS_FLG_APPEND)) {
|
||||
if (!capable(CAP_LINUX_IMMUTABLE))
|
||||
return -EPERM;
|
||||
if (!capable(CAP_LINUX_IMMUTABLE)) {
|
||||
err = -EPERM;
|
||||
goto setflags_out;
|
||||
}
|
||||
}
|
||||
|
||||
/* don't silently ignore unsupported ext2 flags */
|
||||
if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (flags & ~(FS_IMMUTABLE_FL|FS_APPEND_FL|FS_NODUMP_FL)) {
|
||||
err = -EOPNOTSUPP;
|
||||
goto setflags_out;
|
||||
}
|
||||
if (flags & FS_IMMUTABLE_FL) { /* EXT2_IMMUTABLE_FL */
|
||||
inode->i_flags |= S_IMMUTABLE;
|
||||
HFSPLUS_I(inode).rootflags |= HFSPLUS_FLG_IMMUTABLE;
|
||||
|
|
@ -75,7 +83,9 @@ int hfsplus_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
|
|||
|
||||
inode->i_ctime = CURRENT_TIME_SEC;
|
||||
mark_inode_dirty(inode);
|
||||
return 0;
|
||||
setflags_out:
|
||||
mnt_drop_write(filp->f_path.mnt);
|
||||
return err;
|
||||
}
|
||||
default:
|
||||
return -ENOTTY;
|
||||
|
|
|
|||
Loading…
Reference in a new issue