diff options
author | Gao Xiang <hsiangkao@redhat.com> | 2021-02-09 21:06:18 +0800 |
---|---|---|
committer | Gao Xiang <hsiangkao@redhat.com> | 2021-02-11 11:55:28 +0800 |
commit | ce063129181312f8781a047a50be439c5859747b (patch) | |
tree | 065c18d1f666853330c2a02cc1e0c4fa9a80c646 /fs/erofs/xattr.c | |
parent | bde545295b710bdd13a0fcd4b9fddd2383eeeb3a (diff) | |
download | linux-stable-ce063129181312f8781a047a50be439c5859747b.tar.gz linux-stable-ce063129181312f8781a047a50be439c5859747b.tar.bz2 linux-stable-ce063129181312f8781a047a50be439c5859747b.zip |
erofs: initialized fields can only be observed after bit is set
Currently, although set_bit() & test_bit() pairs are used as a fast-
path for initialized configurations. However, these atomic ops are
actually relaxed forms. Instead, load-acquire & store-release form is
needed to make sure uninitialized fields won't be observed in advance
here (yet no such corresponding bitops so use full barriers instead.)
Link: https://lore.kernel.org/r/20210209130618.15838-1-hsiangkao@aol.com
Fixes: 62dc45979f3f ("staging: erofs: fix race of initializing xattrs of a inode at the same time")
Fixes: 152a333a5895 ("staging: erofs: add compacted compression indexes support")
Cc: <stable@vger.kernel.org> # 5.3+
Reported-by: Huang Jianan <huangjianan@oppo.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
Diffstat (limited to 'fs/erofs/xattr.c')
-rw-r--r-- | fs/erofs/xattr.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c index 5bde77d70852..47314a26767a 100644 --- a/fs/erofs/xattr.c +++ b/fs/erofs/xattr.c @@ -48,8 +48,14 @@ static int init_inode_xattrs(struct inode *inode) int ret = 0; /* the most case is that xattrs of this inode are initialized. */ - if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) + if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) { + /* + * paired with smp_mb() at the end of the function to ensure + * fields will only be observed after the bit is set. + */ + smp_mb(); return 0; + } if (wait_on_bit_lock(&vi->flags, EROFS_I_BL_XATTR_BIT, TASK_KILLABLE)) return -ERESTARTSYS; @@ -137,6 +143,8 @@ static int init_inode_xattrs(struct inode *inode) } xattr_iter_end(&it, atomic_map); + /* paired with smp_mb() at the beginning of the function. */ + smp_mb(); set_bit(EROFS_I_EA_INITED_BIT, &vi->flags); out_unlock: |