Skip to content

Commit 3c59728

Browse files
author
Gao Xiang
committed
erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
Hongyu reported "id != index" in z_erofs_onlinepage_fixup() with specific aarch64 environment easily, which wasn't shown before. After digging into that, I found that high 32 bits of page->private was set to 0xaaaaaaaa rather than 0 (due to z_erofs_onlinepage_init behavior with specific compiler options). Actually we only use low 32 bits to keep the page information since page->private is only 4 bytes on most 32-bit platforms. However z_erofs_onlinepage_fixup() uses the upper 32 bits by mistake. Let's fix it now. Reported-and-tested-by: Hongyu Jin <hongyu.jin@unisoc.com> Fixes: 3883a79 ("staging: erofs: introduce VLE decompression support") Cc: <stable@vger.kernel.org> # 4.19+ Reviewed-by: Chao Yu <yuchao0@huawei.com> Link: https://lore.kernel.org/r/20200618234349.22553-1-hsiangkao@aol.com Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
1 parent b3a9e3b commit 3c59728

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

‎fs/erofs/zdata.h‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,22 +144,22 @@ static inline void z_erofs_onlinepage_init(struct page *page)
144144
static inline void z_erofs_onlinepage_fixup(struct page *page,
145145
uintptr_t index, bool down)
146146
{
147-
unsigned long *p, o, v, id;
148-
repeat:
149-
p = &page_private(page);
150-
o = READ_ONCE(*p);
147+
union z_erofs_onlinepage_converter u = { .v = &page_private(page) };
148+
int orig, orig_index, val;
151149

152-
id = o >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
153-
if (id) {
150+
repeat:
151+
orig = atomic_read(u.o);
152+
orig_index = orig >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
153+
if (orig_index) {
154154
if (!index)
155155
return;
156156

157-
DBG_BUGON(id != index);
157+
DBG_BUGON(orig_index != index);
158158
}
159159

160-
v = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) |
161-
((o & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down);
162-
if (cmpxchg(p, o, v) != o)
160+
val = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) |
161+
((orig & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down);
162+
if (atomic_cmpxchg(u.o, orig, val) != orig)
163163
goto repeat;
164164
}
165165

0 commit comments

Comments
 (0)