ANDROID: sdcardfs: override credential for ioctl to lower fs

Otherwise, lower_fs->ioctl() fails due to inode_owner_or_capable().

Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
Bug: 63260873
Change-Id: I623a6c7c5f8a3cbd7ec73ef89e18ddb093c43805
This commit is contained in:
Jaegeuk Kim 2017-07-06 19:12:22 -07:00 committed by Amit Pundir
parent dedbddf5e4
commit 980ab18fbd

View file

@ -104,12 +104,19 @@ static long sdcardfs_unlocked_ioctl(struct file *file, unsigned int cmd,
{ {
long err = -ENOTTY; long err = -ENOTTY;
struct file *lower_file; struct file *lower_file;
const struct cred *saved_cred = NULL;
struct dentry *dentry = file->f_path.dentry;
struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
lower_file = sdcardfs_lower_file(file); lower_file = sdcardfs_lower_file(file);
/* XXX: use vfs_ioctl if/when VFS exports it */ /* XXX: use vfs_ioctl if/when VFS exports it */
if (!lower_file || !lower_file->f_op) if (!lower_file || !lower_file->f_op)
goto out; goto out;
/* save current_cred and override it */
OVERRIDE_CRED(sbi, saved_cred, SDCARDFS_I(file_inode(file)));
if (lower_file->f_op->unlocked_ioctl) if (lower_file->f_op->unlocked_ioctl)
err = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg); err = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg);
@ -117,6 +124,7 @@ static long sdcardfs_unlocked_ioctl(struct file *file, unsigned int cmd,
if (!err) if (!err)
sdcardfs_copy_and_fix_attrs(file_inode(file), sdcardfs_copy_and_fix_attrs(file_inode(file),
file_inode(lower_file)); file_inode(lower_file));
REVERT_CRED(saved_cred);
out: out:
return err; return err;
} }
@ -127,15 +135,23 @@ static long sdcardfs_compat_ioctl(struct file *file, unsigned int cmd,
{ {
long err = -ENOTTY; long err = -ENOTTY;
struct file *lower_file; struct file *lower_file;
const struct cred *saved_cred = NULL;
struct dentry *dentry = file->f_path.dentry;
struct sdcardfs_sb_info *sbi = SDCARDFS_SB(dentry->d_sb);
lower_file = sdcardfs_lower_file(file); lower_file = sdcardfs_lower_file(file);
/* XXX: use vfs_ioctl if/when VFS exports it */ /* XXX: use vfs_ioctl if/when VFS exports it */
if (!lower_file || !lower_file->f_op) if (!lower_file || !lower_file->f_op)
goto out; goto out;
/* save current_cred and override it */
OVERRIDE_CRED(sbi, saved_cred, SDCARDFS_I(file_inode(file)));
if (lower_file->f_op->compat_ioctl) if (lower_file->f_op->compat_ioctl)
err = lower_file->f_op->compat_ioctl(lower_file, cmd, arg); err = lower_file->f_op->compat_ioctl(lower_file, cmd, arg);
REVERT_CRED(saved_cred);
out: out:
return err; return err;
} }