Skip to content

Commit be4df0c

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: use generic vfs_ioc_setflags_prepare() helper
Canonalize to ioctl FS_* flags instead of inode S_* flags. Note that we do not call the helper vfs_ioc_fssetxattr_check() for FS_IOC_FSSETXATTR ioctl. The reason is that underlying filesystem will perform all the checks. We only need to perform the capability check before overriding credentials. Signed-off-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 61536be commit be4df0c

1 file changed

Lines changed: 30 additions & 32 deletions

File tree

fs/overlayfs/file.c

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -559,12 +559,28 @@ static long ovl_real_ioctl(struct file *file, unsigned int cmd,
559559
return ret;
560560
}
561561

562+
static unsigned int ovl_iflags_to_fsflags(unsigned int iflags)
563+
{
564+
unsigned int flags = 0;
565+
566+
if (iflags & S_SYNC)
567+
flags |= FS_SYNC_FL;
568+
if (iflags & S_APPEND)
569+
flags |= FS_APPEND_FL;
570+
if (iflags & S_IMMUTABLE)
571+
flags |= FS_IMMUTABLE_FL;
572+
if (iflags & S_NOATIME)
573+
flags |= FS_NOATIME_FL;
574+
575+
return flags;
576+
}
577+
562578
static long ovl_ioctl_set_flags(struct file *file, unsigned int cmd,
563-
unsigned long arg, unsigned int iflags)
579+
unsigned long arg, unsigned int flags)
564580
{
565581
long ret;
566582
struct inode *inode = file_inode(file);
567-
unsigned int old_iflags;
583+
unsigned int oldflags;
568584

569585
if (!inode_owner_or_capable(inode))
570586
return -EACCES;
@@ -576,10 +592,9 @@ static long ovl_ioctl_set_flags(struct file *file, unsigned int cmd,
576592
inode_lock(inode);
577593

578594
/* Check the capability before cred override */
579-
ret = -EPERM;
580-
old_iflags = READ_ONCE(inode->i_flags);
581-
if (((iflags ^ old_iflags) & (S_APPEND | S_IMMUTABLE)) &&
582-
!capable(CAP_LINUX_IMMUTABLE))
595+
oldflags = ovl_iflags_to_fsflags(READ_ONCE(inode->i_flags));
596+
ret = vfs_ioc_setflags_prepare(inode, oldflags, flags);
597+
if (ret)
583598
goto unlock;
584599

585600
ret = ovl_maybe_copy_up(file_dentry(file), O_WRONLY);
@@ -598,22 +613,6 @@ static long ovl_ioctl_set_flags(struct file *file, unsigned int cmd,
598613

599614
}
600615

601-
static unsigned int ovl_fsflags_to_iflags(unsigned int flags)
602-
{
603-
unsigned int iflags = 0;
604-
605-
if (flags & FS_SYNC_FL)
606-
iflags |= S_SYNC;
607-
if (flags & FS_APPEND_FL)
608-
iflags |= S_APPEND;
609-
if (flags & FS_IMMUTABLE_FL)
610-
iflags |= S_IMMUTABLE;
611-
if (flags & FS_NOATIME_FL)
612-
iflags |= S_NOATIME;
613-
614-
return iflags;
615-
}
616-
617616
static long ovl_ioctl_set_fsflags(struct file *file, unsigned int cmd,
618617
unsigned long arg)
619618
{
@@ -622,24 +621,23 @@ static long ovl_ioctl_set_fsflags(struct file *file, unsigned int cmd,
622621
if (get_user(flags, (int __user *) arg))
623622
return -EFAULT;
624623

625-
return ovl_ioctl_set_flags(file, cmd, arg,
626-
ovl_fsflags_to_iflags(flags));
624+
return ovl_ioctl_set_flags(file, cmd, arg, flags);
627625
}
628626

629-
static unsigned int ovl_fsxflags_to_iflags(unsigned int xflags)
627+
static unsigned int ovl_fsxflags_to_fsflags(unsigned int xflags)
630628
{
631-
unsigned int iflags = 0;
629+
unsigned int flags = 0;
632630

633631
if (xflags & FS_XFLAG_SYNC)
634-
iflags |= S_SYNC;
632+
flags |= FS_SYNC_FL;
635633
if (xflags & FS_XFLAG_APPEND)
636-
iflags |= S_APPEND;
634+
flags |= FS_APPEND_FL;
637635
if (xflags & FS_XFLAG_IMMUTABLE)
638-
iflags |= S_IMMUTABLE;
636+
flags |= FS_IMMUTABLE_FL;
639637
if (xflags & FS_XFLAG_NOATIME)
640-
iflags |= S_NOATIME;
638+
flags |= FS_NOATIME_FL;
641639

642-
return iflags;
640+
return flags;
643641
}
644642

645643
static long ovl_ioctl_set_fsxflags(struct file *file, unsigned int cmd,
@@ -652,7 +650,7 @@ static long ovl_ioctl_set_fsxflags(struct file *file, unsigned int cmd,
652650
return -EFAULT;
653651

654652
return ovl_ioctl_set_flags(file, cmd, arg,
655-
ovl_fsxflags_to_iflags(fa.fsx_xflags));
653+
ovl_fsxflags_to_fsflags(fa.fsx_xflags));
656654
}
657655

658656
long ovl_ioctl(struct file *file, unsigned int cmd, unsigned long arg)

0 commit comments

Comments
 (0)