提交 e052a18d 编写于 作者: D Darrick J. Wong 提交者: Jialin Zhang

xfs: use XFS_IFORK_Q to determine the presence of an xattr fork

mainline inclusion
from mainline-v5.19-rc5
commit e45d7cb2
category: bugfix
bugzilla: 187164, https://gitee.com/openeuler/kernel/issues/I4KIAO
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e45d7cb2356e6b59fe64da28324025cc6fcd3fbd

--------------------------------

Modify xfs_ifork_ptr to return a NULL pointer if the caller asks for the
attribute fork but i_forkoff is zero.  This eliminates the ambiguity
between i_forkoff and i_af.if_present, which should make it easier to
understand the lifetime of attr forks.

While we're at it, remove the if_present checks around calls to
xfs_idestroy_fork and xfs_ifork_zap_attr since they can both handle attr
forks that have already been torn down.
Signed-off-by: NDarrick J. Wong <djwong@kernel.org>
Reviewed-by: NDave Chinner <dchinner@redhat.com>

conflicts:
	fs/xfs/libxfs/xfs_attr.h
	fs/xfs/libxfs/xfs_inode_fork.c
	fs/xfs/libxfs/xfs_inode_fork.h
	fs/xfs/xfs_icache.c
	fs/xfs/xfs_inode.c
Signed-off-by: NLong Li <leo.lilong@huawei.com>
Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
上级 a29e5f83
...@@ -65,8 +65,6 @@ xfs_inode_hasattr( ...@@ -65,8 +65,6 @@ xfs_inode_hasattr(
{ {
if (!XFS_IFORK_Q(ip)) if (!XFS_IFORK_Q(ip))
return 0; return 0;
if (!ip->i_af.if_present)
return 0;
if (ip->i_af.if_format == XFS_DINODE_FMT_EXTENTS && if (ip->i_af.if_format == XFS_DINODE_FMT_EXTENTS &&
ip->i_af.if_nextents == 0) ip->i_af.if_nextents == 0)
return 0; return 0;
......
...@@ -1089,7 +1089,6 @@ xfs_bmap_add_attrfork( ...@@ -1089,7 +1089,6 @@ xfs_bmap_add_attrfork(
error = xfs_bmap_set_attrforkoff(ip, size, &version); error = xfs_bmap_set_attrforkoff(ip, size, &version);
if (error) if (error)
goto trans_cancel; goto trans_cancel;
ASSERT(!ip->i_af.if_present);
xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0); xfs_ifork_init_attr(ip, XFS_DINODE_FMT_EXTENTS, 0);
ip->i_af.if_flags = XFS_IFEXTENTS; ip->i_af.if_flags = XFS_IFEXTENTS;
......
...@@ -198,7 +198,6 @@ xfs_inode_from_disk( ...@@ -198,7 +198,6 @@ xfs_inode_from_disk(
xfs_failaddr_t fa; xfs_failaddr_t fa;
ASSERT(ip->i_cowfp == NULL); ASSERT(ip->i_cowfp == NULL);
ASSERT(!ip->i_af.if_present);
fa = xfs_dinode_verify(ip->i_mount, ip->i_ino, from); fa = xfs_dinode_verify(ip->i_mount, ip->i_ino, from);
if (fa) { if (fa) {
......
...@@ -287,9 +287,6 @@ xfs_ifork_init_attr( ...@@ -287,9 +287,6 @@ xfs_ifork_init_attr(
enum xfs_dinode_fmt format, enum xfs_dinode_fmt format,
xfs_extnum_t nextents) xfs_extnum_t nextents)
{ {
ASSERT(!ip->i_af.if_present);
ip->i_af.if_present = 1;
ip->i_af.if_format = format; ip->i_af.if_format = format;
ip->i_af.if_nextents = nextents; ip->i_af.if_nextents = nextents;
} }
...@@ -298,7 +295,6 @@ void ...@@ -298,7 +295,6 @@ void
xfs_ifork_zap_attr( xfs_ifork_zap_attr(
struct xfs_inode *ip) struct xfs_inode *ip)
{ {
ASSERT(ip->i_af.if_present);
ASSERT(ip->i_af.if_broot == NULL); ASSERT(ip->i_af.if_broot == NULL);
ASSERT(ip->i_af.if_u1.if_data == NULL); ASSERT(ip->i_af.if_u1.if_data == NULL);
ASSERT(ip->i_af.if_height == 0); ASSERT(ip->i_af.if_height == 0);
...@@ -697,7 +693,6 @@ xfs_ifork_init_cow( ...@@ -697,7 +693,6 @@ xfs_ifork_init_cow(
ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_zone, ip->i_cowfp = kmem_cache_zalloc(xfs_ifork_zone,
GFP_NOFS | __GFP_NOFAIL); GFP_NOFS | __GFP_NOFAIL);
ip->i_cowfp->if_present = 1;
ip->i_cowfp->if_flags = XFS_IFEXTENTS; ip->i_cowfp->if_flags = XFS_IFEXTENTS;
ip->i_cowfp->if_format = XFS_DINODE_FMT_EXTENTS; ip->i_cowfp->if_format = XFS_DINODE_FMT_EXTENTS;
} }
...@@ -737,7 +732,7 @@ xfs_ifork_verify_local_attr( ...@@ -737,7 +732,7 @@ xfs_ifork_verify_local_attr(
struct xfs_ifork *ifp = &ip->i_af; struct xfs_ifork *ifp = &ip->i_af;
xfs_failaddr_t fa; xfs_failaddr_t fa;
if (!ifp->if_present) if (!XFS_IFORK_Q(ip))
fa = __this_address; fa = __this_address;
else else
fa = xfs_attr_shortform_verify(ip); fa = xfs_attr_shortform_verify(ip);
......
...@@ -25,7 +25,6 @@ struct xfs_ifork { ...@@ -25,7 +25,6 @@ struct xfs_ifork {
unsigned char if_flags; /* per-fork flags */ unsigned char if_flags; /* per-fork flags */
int8_t if_format; /* format of this fork */ int8_t if_format; /* format of this fork */
xfs_extnum_t if_nextents; /* # of extents in this fork */ xfs_extnum_t if_nextents; /* # of extents in this fork */
int8_t if_present; /* 1 if present */
}; };
/* /*
......
...@@ -360,12 +360,11 @@ xfs_attr_inactive( ...@@ -360,12 +360,11 @@ xfs_attr_inactive(
/* /*
* Invalidate and truncate the attribute fork extents. Make sure the * Invalidate and truncate the attribute fork extents. Make sure the
* fork actually has attributes as otherwise the invalidation has no * fork actually has xattr blocks as otherwise the invalidation has no
* blocks to read and returns an error. In this case, just do the fork * blocks to read and returns an error. In this case, just do the fork
* removal below. * removal below.
*/ */
if (xfs_inode_hasattr(dp) && if (dp->i_af.if_nextents > 0) {
dp->i_af.if_format != XFS_DINODE_FMT_LOCAL) {
error = xfs_attr3_root_inactive(&trans, dp); error = xfs_attr3_root_inactive(&trans, dp);
if (error) if (error)
goto out_cancel; goto out_cancel;
...@@ -386,10 +385,8 @@ xfs_attr_inactive( ...@@ -386,10 +385,8 @@ xfs_attr_inactive(
xfs_trans_cancel(trans); xfs_trans_cancel(trans);
out_destroy_fork: out_destroy_fork:
/* kill the in-core attr fork before we drop the inode lock */ /* kill the in-core attr fork before we drop the inode lock */
if (dp->i_af.if_present) {
xfs_idestroy_fork(&dp->i_af); xfs_idestroy_fork(&dp->i_af);
xfs_ifork_zap_attr(dp); xfs_ifork_zap_attr(dp);
}
if (lock_mode) if (lock_mode)
xfs_iunlock(dp, lock_mode); xfs_iunlock(dp, lock_mode);
return error; return error;
......
...@@ -60,7 +60,6 @@ xfs_attr_shortform_list( ...@@ -60,7 +60,6 @@ xfs_attr_shortform_list(
int sbsize, nsbuf, count, i; int sbsize, nsbuf, count, i;
int error = 0; int error = 0;
ASSERT(dp->i_af.if_present);
sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data; sf = (struct xfs_attr_shortform *)dp->i_af.if_u1.if_data;
ASSERT(sf != NULL); ASSERT(sf != NULL);
if (!sf->hdr.count) if (!sf->hdr.count)
......
...@@ -109,7 +109,6 @@ xfs_inode_alloc( ...@@ -109,7 +109,6 @@ xfs_inode_alloc(
memset(&ip->i_af, 0, sizeof(ip->i_af)); memset(&ip->i_af, 0, sizeof(ip->i_af));
ip->i_af.if_format = XFS_DINODE_FMT_EXTENTS; ip->i_af.if_format = XFS_DINODE_FMT_EXTENTS;
memset(&ip->i_df, 0, sizeof(ip->i_df)); memset(&ip->i_df, 0, sizeof(ip->i_df));
ip->i_df.if_present = 1;
ip->i_flags = 0; ip->i_flags = 0;
ip->i_delayed_blks = 0; ip->i_delayed_blks = 0;
memset(&ip->i_d, 0, sizeof(ip->i_d)); memset(&ip->i_d, 0, sizeof(ip->i_d));
...@@ -137,10 +136,9 @@ xfs_inode_free_callback( ...@@ -137,10 +136,9 @@ xfs_inode_free_callback(
break; break;
} }
if (ip->i_af.if_present) {
xfs_idestroy_fork(&ip->i_af); xfs_idestroy_fork(&ip->i_af);
xfs_ifork_zap_attr(ip); xfs_ifork_zap_attr(ip);
}
if (ip->i_cowfp) { if (ip->i_cowfp) {
xfs_idestroy_fork(ip->i_cowfp); xfs_idestroy_fork(ip->i_cowfp);
kmem_cache_free(xfs_ifork_zone, ip->i_cowfp); kmem_cache_free(xfs_ifork_zone, ip->i_cowfp);
......
...@@ -124,7 +124,7 @@ xfs_ilock_attr_map_shared( ...@@ -124,7 +124,7 @@ xfs_ilock_attr_map_shared(
{ {
uint lock_mode = XFS_ILOCK_SHARED; uint lock_mode = XFS_ILOCK_SHARED;
if (ip->i_af.if_present && if (XFS_IFORK_Q(ip) &&
ip->i_af.if_format == XFS_DINODE_FMT_BTREE && ip->i_af.if_format == XFS_DINODE_FMT_BTREE &&
(ip->i_af.if_flags & XFS_IFEXTENTS) == 0) (ip->i_af.if_flags & XFS_IFEXTENTS) == 0)
lock_mode = XFS_ILOCK_EXCL; lock_mode = XFS_ILOCK_EXCL;
...@@ -1927,7 +1927,6 @@ xfs_inactive( ...@@ -1927,7 +1927,6 @@ xfs_inactive(
goto out; goto out;
} }
ASSERT(!ip->i_af.if_present);
ASSERT(ip->i_d.di_forkoff == 0); ASSERT(ip->i_d.di_forkoff == 0);
/* /*
...@@ -3644,7 +3643,7 @@ xfs_iflush( ...@@ -3644,7 +3643,7 @@ xfs_iflush(
if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL && if (ip->i_df.if_format == XFS_DINODE_FMT_LOCAL &&
xfs_ifork_verify_local_data(ip)) xfs_ifork_verify_local_data(ip))
goto flush_out; goto flush_out;
if (ip->i_af.if_present && if (XFS_IFORK_Q(ip) &&
ip->i_af.if_format == XFS_DINODE_FMT_LOCAL && ip->i_af.if_format == XFS_DINODE_FMT_LOCAL &&
xfs_ifork_verify_local_attr(ip)) xfs_ifork_verify_local_attr(ip))
goto flush_out; goto flush_out;
......
...@@ -76,7 +76,7 @@ xfs_ifork_ptr( ...@@ -76,7 +76,7 @@ xfs_ifork_ptr(
case XFS_DATA_FORK: case XFS_DATA_FORK:
return &ip->i_df; return &ip->i_df;
case XFS_ATTR_FORK: case XFS_ATTR_FORK:
if (!ip->i_af.if_present) if (!XFS_IFORK_Q(ip))
return NULL; return NULL;
return &ip->i_af; return &ip->i_af;
case XFS_COW_FORK: case XFS_COW_FORK:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册