[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200618111936.19845-1-hsiangkao@aol.com>
Date: Thu, 18 Jun 2020 19:19:36 +0800
From: Gao Xiang <hsiangkao@....com>
To: linux-erofs@...ts.ozlabs.org, Chao Yu <yuchao0@...wei.com>
Cc: Chao Yu <chao@...nel.org>, Li Guifu <bluce.liguifu@...wei.com>,
Fang Wei <fangwei1@...wei.com>,
LKML <linux-kernel@...r.kernel.org>,
Gao Xiang <hsiangkao@...hat.com>,
Hongyu Jin <hongyu.jin@...soc.com>, stable@...r.kernel.org
Subject: [PATCH] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
From: Gao Xiang <hsiangkao@...hat.com>
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-by: Hongyu Jin <hongyu.jin@...soc.com>
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Cc: <stable@...r.kernel.org> # 4.19+
Signed-off-by: Gao Xiang <hsiangkao@...hat.com>
---
fs/erofs/zdata.h | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h
index 7824f5563a55..92fbc0f0ba85 100644
--- a/fs/erofs/zdata.h
+++ b/fs/erofs/zdata.h
@@ -144,22 +144,24 @@ static inline void z_erofs_onlinepage_init(struct page *page)
static inline void z_erofs_onlinepage_fixup(struct page *page,
uintptr_t index, bool down)
{
- unsigned long *p, o, v, id;
+ union z_erofs_onlinepage_converter u;
+ int orig, orig_index, val;
+
repeat:
- p = &page_private(page);
- o = READ_ONCE(*p);
+ u.v = &page_private(page);
+ orig = atomic_read(u.o);
- id = o >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
- if (id) {
+ orig_index = orig >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
+ if (orig_index) {
if (!index)
return;
- DBG_BUGON(id != index);
+ DBG_BUGON(orig_index != index);
}
- v = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) |
- ((o & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down);
- if (cmpxchg(p, o, v) != o)
+ val = (index << Z_EROFS_ONLINEPAGE_INDEX_SHIFT) |
+ ((orig & Z_EROFS_ONLINEPAGE_COUNT_MASK) + (unsigned int)down);
+ if (atomic_cmpxchg(u.o, orig, val) != orig)
goto repeat;
}
--
2.24.0
Powered by blists - more mailing lists