diff options
author | Jan Kara <jack@suse.cz> | 2016-05-26 08:46:43 -0400 |
---|---|---|
committer | Jan Kara <jack@suse.cz> | 2016-09-22 04:56:19 -0400 |
commit | 69bca80744eef58fa155e8042996b968fec17b26 (patch) | |
tree | 6b2de5926d4a916c8053778c59c069283bdbd7b3 | |
parent | 073931017b49d9458aa351605b43a7e34598caef (diff) |
xfs: Propagate dentry down to inode_change_ok()
To avoid clearing of capabilities or security related extended
attributes too early, inode_change_ok() will need to take dentry instead
of inode. Propagate dentry down to functions calling inode_change_ok().
This is rather straightforward except for xfs_set_mode() function which
does not have dentry easily available. Luckily that function does not
call inode_change_ok() anyway so we just have to do a little dance with
function prototypes.
Acked-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jan Kara <jack@suse.cz>
-rw-r--r-- | fs/xfs/xfs_file.c | 2 | ||||
-rw-r--r-- | fs/xfs/xfs_inode.c | 2 | ||||
-rw-r--r-- | fs/xfs/xfs_ioctl.c | 2 | ||||
-rw-r--r-- | fs/xfs/xfs_iops.c | 94 | ||||
-rw-r--r-- | fs/xfs/xfs_iops.h | 3 |
5 files changed, 68 insertions, 35 deletions
diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c index ed95e5bb04e6..79205202a29a 100644 --- a/fs/xfs/xfs_file.c +++ b/fs/xfs/xfs_file.c | |||
@@ -973,7 +973,7 @@ xfs_file_fallocate( | |||
973 | 973 | ||
974 | iattr.ia_valid = ATTR_SIZE; | 974 | iattr.ia_valid = ATTR_SIZE; |
975 | iattr.ia_size = new_size; | 975 | iattr.ia_size = new_size; |
976 | error = xfs_setattr_size(ip, &iattr); | 976 | error = xfs_vn_setattr_size(file_dentry(file), &iattr); |
977 | if (error) | 977 | if (error) |
978 | goto out_unlock; | 978 | goto out_unlock; |
979 | } | 979 | } |
diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index e08eaea6327b..df22e1254c98 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c | |||
@@ -1710,7 +1710,7 @@ xfs_inactive_truncate( | |||
1710 | /* | 1710 | /* |
1711 | * Log the inode size first to prevent stale data exposure in the event | 1711 | * Log the inode size first to prevent stale data exposure in the event |
1712 | * of a system crash before the truncate completes. See the related | 1712 | * of a system crash before the truncate completes. See the related |
1713 | * comment in xfs_setattr_size() for details. | 1713 | * comment in xfs_vn_setattr_size() for details. |
1714 | */ | 1714 | */ |
1715 | ip->i_d.di_size = 0; | 1715 | ip->i_d.di_size = 0; |
1716 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); | 1716 | xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE); |
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 96a70fd1f5d6..0d9021f0551e 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c | |||
@@ -720,7 +720,7 @@ xfs_ioc_space( | |||
720 | iattr.ia_valid = ATTR_SIZE; | 720 | iattr.ia_valid = ATTR_SIZE; |
721 | iattr.ia_size = bf->l_start; | 721 | iattr.ia_size = bf->l_start; |
722 | 722 | ||
723 | error = xfs_setattr_size(ip, &iattr); | 723 | error = xfs_vn_setattr_size(file_dentry(filp), &iattr); |
724 | break; | 724 | break; |
725 | default: | 725 | default: |
726 | ASSERT(0); | 726 | ASSERT(0); |
diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c index ab820f84ed50..f5db392e7d1e 100644 --- a/fs/xfs/xfs_iops.c +++ b/fs/xfs/xfs_iops.c | |||
@@ -542,6 +542,30 @@ xfs_setattr_time( | |||
542 | inode->i_mtime = iattr->ia_mtime; | 542 | inode->i_mtime = iattr->ia_mtime; |
543 | } | 543 | } |
544 | 544 | ||
545 | static int | ||
546 | xfs_vn_change_ok( | ||
547 | struct dentry *dentry, | ||
548 | struct iattr *iattr) | ||
549 | { | ||
550 | struct inode *inode = d_inode(dentry); | ||
551 | struct xfs_inode *ip = XFS_I(inode); | ||
552 | struct xfs_mount *mp = ip->i_mount; | ||
553 | |||
554 | if (mp->m_flags & XFS_MOUNT_RDONLY) | ||
555 | return -EROFS; | ||
556 | |||
557 | if (XFS_FORCED_SHUTDOWN(mp)) | ||
558 | return -EIO; | ||
559 | |||
560 | return inode_change_ok(inode, iattr); | ||
561 | } | ||
562 | |||
563 | /* | ||
564 | * Set non-size attributes of an inode. | ||
565 | * | ||
566 | * Caution: The caller of this function is responsible for calling | ||
567 | * inode_change_ok() or otherwise verifying the change is fine. | ||
568 | */ | ||
545 | int | 569 | int |
546 | xfs_setattr_nonsize( | 570 | xfs_setattr_nonsize( |
547 | struct xfs_inode *ip, | 571 | struct xfs_inode *ip, |
@@ -558,21 +582,6 @@ xfs_setattr_nonsize( | |||
558 | struct xfs_dquot *udqp = NULL, *gdqp = NULL; | 582 | struct xfs_dquot *udqp = NULL, *gdqp = NULL; |
559 | struct xfs_dquot *olddquot1 = NULL, *olddquot2 = NULL; | 583 | struct xfs_dquot *olddquot1 = NULL, *olddquot2 = NULL; |
560 | 584 | ||
561 | trace_xfs_setattr(ip); | ||
562 | |||
563 | /* If acls are being inherited, we already have this checked */ | ||
564 | if (!(flags & XFS_ATTR_NOACL)) { | ||
565 | if (mp->m_flags & XFS_MOUNT_RDONLY) | ||
566 | return -EROFS; | ||
567 | |||
568 | if (XFS_FORCED_SHUTDOWN(mp)) | ||
569 | return -EIO; | ||
570 | |||
571 | error = inode_change_ok(inode, iattr); | ||
572 | if (error) | ||
573 | return error; | ||
574 | } | ||
575 | |||
576 | ASSERT((mask & ATTR_SIZE) == 0); | 585 | ASSERT((mask & ATTR_SIZE) == 0); |
577 | 586 | ||
578 | /* | 587 | /* |
@@ -743,8 +752,27 @@ out_dqrele: | |||
743 | return error; | 752 | return error; |
744 | } | 753 | } |
745 | 754 | ||
755 | int | ||
756 | xfs_vn_setattr_nonsize( | ||
757 | struct dentry *dentry, | ||
758 | struct iattr *iattr) | ||
759 | { | ||
760 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); | ||
761 | int error; | ||
762 | |||
763 | trace_xfs_setattr(ip); | ||
764 | |||
765 | error = xfs_vn_change_ok(dentry, iattr); | ||
766 | if (error) | ||
767 | return error; | ||
768 | return xfs_setattr_nonsize(ip, iattr, 0); | ||
769 | } | ||
770 | |||
746 | /* | 771 | /* |
747 | * Truncate file. Must have write permission and not be a directory. | 772 | * Truncate file. Must have write permission and not be a directory. |
773 | * | ||
774 | * Caution: The caller of this function is responsible for calling | ||
775 | * inode_change_ok() or otherwise verifying the change is fine. | ||
748 | */ | 776 | */ |
749 | int | 777 | int |
750 | xfs_setattr_size( | 778 | xfs_setattr_size( |
@@ -759,18 +787,6 @@ xfs_setattr_size( | |||
759 | uint lock_flags = 0; | 787 | uint lock_flags = 0; |
760 | bool did_zeroing = false; | 788 | bool did_zeroing = false; |
761 | 789 | ||
762 | trace_xfs_setattr(ip); | ||
763 | |||
764 | if (mp->m_flags & XFS_MOUNT_RDONLY) | ||
765 | return -EROFS; | ||
766 | |||
767 | if (XFS_FORCED_SHUTDOWN(mp)) | ||
768 | return -EIO; | ||
769 | |||
770 | error = inode_change_ok(inode, iattr); | ||
771 | if (error) | ||
772 | return error; | ||
773 | |||
774 | ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); | 790 | ASSERT(xfs_isilocked(ip, XFS_IOLOCK_EXCL)); |
775 | ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); | 791 | ASSERT(xfs_isilocked(ip, XFS_MMAPLOCK_EXCL)); |
776 | ASSERT(S_ISREG(inode->i_mode)); | 792 | ASSERT(S_ISREG(inode->i_mode)); |
@@ -942,16 +958,32 @@ out_trans_cancel: | |||
942 | goto out_unlock; | 958 | goto out_unlock; |
943 | } | 959 | } |
944 | 960 | ||
961 | int | ||
962 | xfs_vn_setattr_size( | ||
963 | struct dentry *dentry, | ||
964 | struct iattr *iattr) | ||
965 | { | ||
966 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); | ||
967 | int error; | ||
968 | |||
969 | trace_xfs_setattr(ip); | ||
970 | |||
971 | error = xfs_vn_change_ok(dentry, iattr); | ||
972 | if (error) | ||
973 | return error; | ||
974 | return xfs_setattr_size(ip, iattr); | ||
975 | } | ||
976 | |||
945 | STATIC int | 977 | STATIC int |
946 | xfs_vn_setattr( | 978 | xfs_vn_setattr( |
947 | struct dentry *dentry, | 979 | struct dentry *dentry, |
948 | struct iattr *iattr) | 980 | struct iattr *iattr) |
949 | { | 981 | { |
950 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); | ||
951 | int error; | 982 | int error; |
952 | 983 | ||
953 | if (iattr->ia_valid & ATTR_SIZE) { | 984 | if (iattr->ia_valid & ATTR_SIZE) { |
954 | uint iolock = XFS_IOLOCK_EXCL; | 985 | struct xfs_inode *ip = XFS_I(d_inode(dentry)); |
986 | uint iolock = XFS_IOLOCK_EXCL; | ||
955 | 987 | ||
956 | xfs_ilock(ip, iolock); | 988 | xfs_ilock(ip, iolock); |
957 | error = xfs_break_layouts(d_inode(dentry), &iolock, true); | 989 | error = xfs_break_layouts(d_inode(dentry), &iolock, true); |
@@ -959,11 +991,11 @@ xfs_vn_setattr( | |||
959 | xfs_ilock(ip, XFS_MMAPLOCK_EXCL); | 991 | xfs_ilock(ip, XFS_MMAPLOCK_EXCL); |
960 | iolock |= XFS_MMAPLOCK_EXCL; | 992 | iolock |= XFS_MMAPLOCK_EXCL; |
961 | 993 | ||
962 | error = xfs_setattr_size(ip, iattr); | 994 | error = xfs_vn_setattr_size(dentry, iattr); |
963 | } | 995 | } |
964 | xfs_iunlock(ip, iolock); | 996 | xfs_iunlock(ip, iolock); |
965 | } else { | 997 | } else { |
966 | error = xfs_setattr_nonsize(ip, iattr, 0); | 998 | error = xfs_vn_setattr_nonsize(dentry, iattr); |
967 | } | 999 | } |
968 | 1000 | ||
969 | return error; | 1001 | return error; |
diff --git a/fs/xfs/xfs_iops.h b/fs/xfs/xfs_iops.h index a0f84abb0d09..0259a383721a 100644 --- a/fs/xfs/xfs_iops.h +++ b/fs/xfs/xfs_iops.h | |||
@@ -33,6 +33,7 @@ extern ssize_t xfs_vn_listxattr(struct dentry *, char *data, size_t size); | |||
33 | extern void xfs_setattr_time(struct xfs_inode *ip, struct iattr *iattr); | 33 | extern void xfs_setattr_time(struct xfs_inode *ip, struct iattr *iattr); |
34 | extern int xfs_setattr_nonsize(struct xfs_inode *ip, struct iattr *vap, | 34 | extern int xfs_setattr_nonsize(struct xfs_inode *ip, struct iattr *vap, |
35 | int flags); | 35 | int flags); |
36 | extern int xfs_setattr_size(struct xfs_inode *ip, struct iattr *vap); | 36 | extern int xfs_vn_setattr_nonsize(struct dentry *dentry, struct iattr *vap); |
37 | extern int xfs_vn_setattr_size(struct dentry *dentry, struct iattr *vap); | ||
37 | 38 | ||
38 | #endif /* __XFS_IOPS_H__ */ | 39 | #endif /* __XFS_IOPS_H__ */ |