Skip to content

Commit a66174e

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 66aaeed commit a66174e

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
@@ -311,7 +311,9 @@ struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, int type)
311311
if (had_lock < 0)
312312
return ERR_PTR(had_lock);
313313

314+
down_read(&OCFS2_I(inode)->ip_xattr_sem);
314315
acl = ocfs2_get_acl_nolock(inode, type, di_bh);
316+
up_read(&OCFS2_I(inode)->ip_xattr_sem);
315317

316318
ocfs2_inode_unlock_tracker(inode, 0, &oh, had_lock);
317319
brelse(di_bh);
@@ -330,7 +332,9 @@ int ocfs2_acl_chmod(struct inode *inode, struct buffer_head *bh)
330332
if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
331333
return 0;
332334

335+
down_read(&OCFS2_I(inode)->ip_xattr_sem);
333336
acl = ocfs2_get_acl_nolock(inode, ACL_TYPE_ACCESS, bh);
337+
up_read(&OCFS2_I(inode)->ip_xattr_sem);
334338
if (IS_ERR(acl) || !acl)
335339
return PTR_ERR(acl);
336340
ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
@@ -361,8 +365,10 @@ int ocfs2_init_acl(handle_t *handle,
361365

362366
if (!S_ISLNK(inode->i_mode)) {
363367
if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
368+
down_read(&OCFS2_I(dir)->ip_xattr_sem);
364369
acl = ocfs2_get_acl_nolock(dir, ACL_TYPE_DEFAULT,
365370
dir_bh);
371+
up_read(&OCFS2_I(dir)->ip_xattr_sem);
366372
if (IS_ERR(acl))
367373
return PTR_ERR(acl);
368374
}

fs/ocfs2/xattr.c

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

640640
if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
641+
down_read(&OCFS2_I(dir)->ip_xattr_sem);
641642
acl_len = ocfs2_xattr_get_nolock(dir, dir_bh,
642643
OCFS2_XATTR_INDEX_POSIX_ACL_DEFAULT,
643644
"", NULL, 0);
645+
up_read(&OCFS2_I(dir)->ip_xattr_sem);
644646
if (acl_len > 0) {
645647
a_size = ocfs2_xattr_entry_real_size(0, acl_len);
646648
if (S_ISDIR(mode))

0 commit comments

Comments
 (0)