linux-erofs.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
       [not found] <20200618111936.19845-1-hsiangkao.ref@aol.com>
@ 2020-06-18 11:19 ` Gao Xiang via Linux-erofs
  2020-06-18 23:43   ` [PATCH v2] " Gao Xiang via Linux-erofs
  0 siblings, 1 reply; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2020-06-18 11:19 UTC (permalink / raw)
  To: linux-erofs, Chao Yu; +Cc: LKML, Hongyu Jin, stable

From: Gao Xiang <hsiangkao@redhat.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@unisoc.com>
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Cc: <stable@vger.kernel.org> # 4.19+
Signed-off-by: Gao Xiang <hsiangkao@redhat.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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
  2020-06-18 11:19 ` [PATCH] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup Gao Xiang via Linux-erofs
@ 2020-06-18 23:43   ` Gao Xiang via Linux-erofs
  2020-06-19  9:00     ` 金红宇 (Hongyu Jin)
                       ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Gao Xiang via Linux-erofs @ 2020-06-18 23:43 UTC (permalink / raw)
  To: linux-erofs, Chao Yu; +Cc: LKML, Hongyu Jin, stable

From: Gao Xiang <hsiangkao@redhat.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@unisoc.com>
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Cc: <stable@vger.kernel.org> # 4.19+
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
---
change since v1:
 move .v assignment out since it doesn't need for every loop;

 fs/erofs/zdata.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h
index 7824f5563a55..9b66c28b3ae9 100644
--- a/fs/erofs/zdata.h
+++ b/fs/erofs/zdata.h
@@ -144,22 +144,22 @@ 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;
-repeat:
-	p = &page_private(page);
-	o = READ_ONCE(*p);
+	union z_erofs_onlinepage_converter u = { .v = &page_private(page) };
+	int orig, orig_index, val;
 
-	id = o >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
-	if (id) {
+repeat:
+	orig = atomic_read(u.o);
+	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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
  2020-06-18 23:43   ` [PATCH v2] " Gao Xiang via Linux-erofs
@ 2020-06-19  9:00     ` 金红宇 (Hongyu Jin)
  2020-06-19  9:13     ` 金红宇 (Hongyu Jin)
  2020-06-24  1:42     ` Chao Yu
  2 siblings, 0 replies; 5+ messages in thread
From: 金红宇 (Hongyu Jin) @ 2020-06-19  9:00 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Chao Yu; +Cc: LKML, stable

Hi xiang:

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.

Tested-by: hongyu.jin@unisoc.com

it's ok.
________________________________________
发件人: Gao Xiang <hsiangkao@aol.com>
发送时间: 2020年6月19日 7:43
收件人: linux-erofs@lists.ozlabs.org; Chao Yu
抄送: Chao Yu; Li Guifu; Fang Wei; LKML; Gao Xiang; 金红宇 (Hongyu Jin); stable@vger.kernel.org
主题: [PATCH v2] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup

From: Gao Xiang <hsiangkao@redhat.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@unisoc.com>
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Cc: <stable@vger.kernel.org> # 4.19+
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
---
change since v1:
 move .v assignment out since it doesn't need for every loop;

 fs/erofs/zdata.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h
index 7824f5563a55..9b66c28b3ae9 100644
--- a/fs/erofs/zdata.h
+++ b/fs/erofs/zdata.h
@@ -144,22 +144,22 @@ 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;
-repeat:
-       p = &page_private(page);
-       o = READ_ONCE(*p);
+       union z_erofs_onlinepage_converter u = { .v = &page_private(page) };
+       int orig, orig_index, val;

-       id = o >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
-       if (id) {
+repeat:
+       orig = atomic_read(u.o);
+       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

________________________________
 This email (including its attachments) is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. Unauthorized use, dissemination, distribution or copying of this email or the information herein or taking any action in reliance on the contents of this email or the information herein, by anyone other than the intended recipient, or an employee or agent responsible for delivering the message to the intended recipient, is strictly prohibited. If you are not the intended recipient, please do not read, copy, use or disclose any part of this e-mail to others. Please notify the sender immediately and permanently delete this e-mail and any attachments if you received it in error. Internet communications cannot be guaranteed to be timely, secure, error-free or virus-free. The sender does not accept liability for any errors or omissions.
本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* RE: [PATCH v2] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
  2020-06-18 23:43   ` [PATCH v2] " Gao Xiang via Linux-erofs
  2020-06-19  9:00     ` 金红宇 (Hongyu Jin)
@ 2020-06-19  9:13     ` 金红宇 (Hongyu Jin)
  2020-06-24  1:42     ` Chao Yu
  2 siblings, 0 replies; 5+ messages in thread
From: 金红宇 (Hongyu Jin) @ 2020-06-19  9:13 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs, Chao Yu; +Cc: LKML, stable

Hi xiang:

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.

Tested-by: hongyu.jin@unisoc.com

It's ok.

-----Original Message-----
From: Gao Xiang [mailto:hsiangkao@aol.com]
Sent: Friday, June 19, 2020 7:44 AM
To: linux-erofs@lists.ozlabs.org; Chao Yu <yuchao0@huawei.com>
Cc: Chao Yu <chao@kernel.org>; Li Guifu <bluce.liguifu@huawei.com>; Fang Wei <fangwei1@huawei.com>; LKML <linux-kernel@vger.kernel.org>; Gao Xiang <hsiangkao@redhat.com>; 金红宇 (Hongyu Jin) <hongyu.jin@unisoc.com>; stable@vger.kernel.org
Subject: [PATCH v2] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup

From: Gao Xiang <hsiangkao@redhat.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@unisoc.com>
Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
Cc: <stable@vger.kernel.org> # 4.19+
Signed-off-by: Gao Xiang <hsiangkao@redhat.com>
---
change since v1:
 move .v assignment out since it doesn't need for every loop;

 fs/erofs/zdata.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/erofs/zdata.h b/fs/erofs/zdata.h index 7824f5563a55..9b66c28b3ae9 100644
--- a/fs/erofs/zdata.h
+++ b/fs/erofs/zdata.h
@@ -144,22 +144,22 @@ 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;
-repeat:
-p = &page_private(page);
-o = READ_ONCE(*p);
+union z_erofs_onlinepage_converter u = { .v = &page_private(page) };
+int orig, orig_index, val;

-id = o >> Z_EROFS_ONLINEPAGE_INDEX_SHIFT;
-if (id) {
+repeat:
+orig = atomic_read(u.o);
+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

________________________________
 This email (including its attachments) is intended only for the person or entity to which it is addressed and may contain information that is privileged, confidential or otherwise protected from disclosure. Unauthorized use, dissemination, distribution or copying of this email or the information herein or taking any action in reliance on the contents of this email or the information herein, by anyone other than the intended recipient, or an employee or agent responsible for delivering the message to the intended recipient, is strictly prohibited. If you are not the intended recipient, please do not read, copy, use or disclose any part of this e-mail to others. Please notify the sender immediately and permanently delete this e-mail and any attachments if you received it in error. Internet communications cannot be guaranteed to be timely, secure, error-free or virus-free. The sender does not accept liability for any errors or omissions.
本邮件及其附件具有保密性质,受法律保护不得泄露,仅发送给本邮件所指特定收件人。严禁非经授权使用、宣传、发布或复制本邮件或其内容。若非该特定收件人,请勿阅读、复制、 使用或披露本邮件的任何内容。若误收本邮件,请从系统中永久性删除本邮件及所有附件,并以回复邮件的方式即刻告知发件人。无法保证互联网通信及时、安全、无误或防毒。发件人对任何错漏均不承担责任。

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup
  2020-06-18 23:43   ` [PATCH v2] " Gao Xiang via Linux-erofs
  2020-06-19  9:00     ` 金红宇 (Hongyu Jin)
  2020-06-19  9:13     ` 金红宇 (Hongyu Jin)
@ 2020-06-24  1:42     ` Chao Yu
  2 siblings, 0 replies; 5+ messages in thread
From: Chao Yu @ 2020-06-24  1:42 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs; +Cc: LKML, Hongyu Jin, stable

On 2020/6/19 7:43, Gao Xiang wrote:
> From: Gao Xiang <hsiangkao@redhat.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@unisoc.com>
> Fixes: 3883a79abd02 ("staging: erofs: introduce VLE decompression support")
> Cc: <stable@vger.kernel.org> # 4.19+
> Signed-off-by: Gao Xiang <hsiangkao@redhat.com>

Reviewed-by: Chao Yu <yuchao0@huawei.com>

Thanks,

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-24  1:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200618111936.19845-1-hsiangkao.ref@aol.com>
2020-06-18 11:19 ` [PATCH] erofs: fix partially uninitialized misuse in z_erofs_onlinepage_fixup Gao Xiang via Linux-erofs
2020-06-18 23:43   ` [PATCH v2] " Gao Xiang via Linux-erofs
2020-06-19  9:00     ` 金红宇 (Hongyu Jin)
2020-06-19  9:13     ` 金红宇 (Hongyu Jin)
2020-06-24  1:42     ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).