Skip to content

Commit b35bb8a

Browse files
JunPiaoHWgregkh
authored andcommitted
ocfs2/acl: use 'ip_xattr_sem' to protect getting extended attribute
[ Upstream commit 16c8d56 ] The race between *set_acl and *get_acl will cause getting incomplete xattr data as below: processA processB ocfs2_set_acl ocfs2_xattr_set __ocfs2_xattr_set_handle ocfs2_get_acl_nolock ocfs2_xattr_get_nolock: processB may get incomplete xattr data if processA hasn't set_acl done. So we should use 'ip_xattr_sem' to protect getting extended attribute in ocfs2_get_acl_nolock(), as other processes could be changing it concurrently. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Jun Piao <[email protected]> Reviewed-by: Alex Chen <[email protected]> Cc: Mark Fasheh <[email protected]> Cc: Joel Becker <[email protected]> Cc: Junxiao Bi <[email protected]> Cc: Joseph Qi <[email protected]> Cc: Changwei Ge <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d55cd57 commit b35bb8a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

fs/ocfs2/acl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,9 @@ struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, int type)
314314
return ERR_PTR(ret);
315315
}
316316

317+
down_read(&OCFS2_I(inode)->ip_xattr_sem);
317318
acl = ocfs2_get_acl_nolock(inode, type, di_bh);
319+
up_read(&OCFS2_I(inode)->ip_xattr_sem);
318320

319321
ocfs2_inode_unlock(inode, 0);
320322
brelse(di_bh);
@@ -333,7 +335,9 @@ int ocfs2_acl_chmod(struct inode *inode, struct buffer_head *bh)
333335
if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
334336
return 0;
335337

338+
down_read(&OCFS2_I(inode)->ip_xattr_sem);
336339
acl = ocfs2_get_acl_nolock(inode, ACL_TYPE_ACCESS, bh);
340+
up_read(&OCFS2_I(inode)->ip_xattr_sem);
337341
if (IS_ERR(acl) || !acl)
338342
return PTR_ERR(acl);
339343
ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
@@ -364,8 +368,10 @@ int ocfs2_init_acl(handle_t *handle,
364368

365369
if (!S_ISLNK(inode->i_mode)) {
366370
if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
371+
down_read(&OCFS2_I(dir)->ip_xattr_sem);
367372
acl = ocfs2_get_acl_nolock(dir, ACL_TYPE_DEFAULT,
368373
dir_bh);
374+
up_read(&OCFS2_I(dir)->ip_xattr_sem);
369375
if (IS_ERR(acl))
370376
return PTR_ERR(acl);
371377
}

fs/ocfs2/xattr.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,11 @@ int ocfs2_calc_xattr_init(struct inode *dir,
639639
si->value_len);
640640

641641
if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
642+
down_read(&OCFS2_I(dir)->ip_xattr_sem);
642643
acl_len = ocfs2_xattr_get_nolock(dir, dir_bh,
643644
OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT,
644645
"", NULL, 0);
646+
up_read(&OCFS2_I(dir)->ip_xattr_sem);
645647
if (acl_len > 0) {
646648
a_size = ocfs2_xattr_entry_real_size(0, acl_len);
647649
if (S_ISDIR(mode))

0 commit comments

Comments
 (0)