2018-10-20 12:07:31

by Hou Tao

[permalink] [raw]
Subject: [PATCH] jffs2: ensure wbuf_verify is valid before using it.

Now MTD emulated by UBI volumn doesn't allocate wbuf_verify in
jffs2_ubivol_setup(), because UBI can do the verifcation itself,
so when CONFIG_JFFS2_FS_WBUF_VERIFY is enabled and a MTD device
emulated by UBI volumn is used, a Oops will occur as show in the
following trace:

general protection fault: 0000 [#1] SMP KASAN PTI
CPU: 6 PID: 404 Comm: kworker/6:1 Not tainted 4.19.0-rc8
Workqueue: events_long delayed_wbuf_sync
RIP: 0010:ubi_io_read+0x156/0x650
Call Trace:
ubi_eba_read_leb+0x57d/0xba0
ubi_leb_read+0xe5/0x1b0
gluebi_read+0x10c/0x1a0
mtd_read+0x112/0x340
jffs2_verify_write+0xef/0x440
__jffs2_flush_wbuf+0x3fa/0x3540
jffs2_flush_wbuf_gc+0x1b1/0x2e0
process_one_work+0x58b/0x11e0
worker_thread+0x8f/0xfe0
kthread+0x2ae/0x3a0
ret_from_fork+0x35/0x40

Fix the problem by checking the validity of wbuf_verify before
using it in jffs2_verify_write().

Cc: [email protected]
Fixes: 0029da3bf430 ("JFFS2: add UBI support")
Signed-off-by: Hou Tao <[email protected]>
---
fs/jffs2/wbuf.c | 7 +++++++
1 file changed, 7 insertions(+)

diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
index c6821a509481..3de45f4559d1 100644
--- a/fs/jffs2/wbuf.c
+++ b/fs/jffs2/wbuf.c
@@ -234,6 +234,13 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf,
size_t retlen;
char *eccstr;

+ /*
+ * MTD emulated by UBI volume doesn't allocate wbuf_verify,
+ * because it can do the verification itself.
+ */
+ if (!c->wbuf_verify)
+ return 0;
+
ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, c->wbuf_verify);
if (ret && ret != -EUCLEAN && ret != -EBADMSG) {
pr_warn("%s(): Read back of page at %08x failed: %d\n",
--
2.16.2.dirty



2018-12-09 06:37:14

by Hou Tao

[permalink] [raw]
Subject: Re: [PATCH] jffs2: ensure wbuf_verify is valid before using it.

ping ?

On 2018/10/20 20:08, Hou Tao wrote:
> Now MTD emulated by UBI volumn doesn't allocate wbuf_verify in
> jffs2_ubivol_setup(), because UBI can do the verifcation itself,
> so when CONFIG_JFFS2_FS_WBUF_VERIFY is enabled and a MTD device
> emulated by UBI volumn is used, a Oops will occur as show in the
> following trace:
>
> general protection fault: 0000 [#1] SMP KASAN PTI
> CPU: 6 PID: 404 Comm: kworker/6:1 Not tainted 4.19.0-rc8
> Workqueue: events_long delayed_wbuf_sync
> RIP: 0010:ubi_io_read+0x156/0x650
> Call Trace:
> ubi_eba_read_leb+0x57d/0xba0
> ubi_leb_read+0xe5/0x1b0
> gluebi_read+0x10c/0x1a0
> mtd_read+0x112/0x340
> jffs2_verify_write+0xef/0x440
> __jffs2_flush_wbuf+0x3fa/0x3540
> jffs2_flush_wbuf_gc+0x1b1/0x2e0
> process_one_work+0x58b/0x11e0
> worker_thread+0x8f/0xfe0
> kthread+0x2ae/0x3a0
> ret_from_fork+0x35/0x40
>
> Fix the problem by checking the validity of wbuf_verify before
> using it in jffs2_verify_write().
>
> Cc: [email protected]
> Fixes: 0029da3bf430 ("JFFS2: add UBI support")
> Signed-off-by: Hou Tao <[email protected]>
> ---
> fs/jffs2/wbuf.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
> index c6821a509481..3de45f4559d1 100644
> --- a/fs/jffs2/wbuf.c
> +++ b/fs/jffs2/wbuf.c
> @@ -234,6 +234,13 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf,
> size_t retlen;
> char *eccstr;
>
> + /*
> + * MTD emulated by UBI volume doesn't allocate wbuf_verify,
> + * because it can do the verification itself.
> + */
> + if (!c->wbuf_verify)
> + return 0;
> +
> ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, c->wbuf_verify);
> if (ret && ret != -EUCLEAN && ret != -EBADMSG) {
> pr_warn("%s(): Read back of page at %08x failed: %d\n",
>


2018-12-15 13:25:32

by Hou Tao

[permalink] [raw]
Subject: Re: [PATCH] jffs2: ensure wbuf_verify is valid before using it.

ping ?

On 2018/12/9 14:35, Hou Tao wrote:
> ping ?
>
> On 2018/10/20 20:08, Hou Tao wrote:
>> Now MTD emulated by UBI volumn doesn't allocate wbuf_verify in
>> jffs2_ubivol_setup(), because UBI can do the verifcation itself,
>> so when CONFIG_JFFS2_FS_WBUF_VERIFY is enabled and a MTD device
>> emulated by UBI volumn is used, a Oops will occur as show in the
>> following trace:
>>
>> general protection fault: 0000 [#1] SMP KASAN PTI
>> CPU: 6 PID: 404 Comm: kworker/6:1 Not tainted 4.19.0-rc8
>> Workqueue: events_long delayed_wbuf_sync
>> RIP: 0010:ubi_io_read+0x156/0x650
>> Call Trace:
>> ubi_eba_read_leb+0x57d/0xba0
>> ubi_leb_read+0xe5/0x1b0
>> gluebi_read+0x10c/0x1a0
>> mtd_read+0x112/0x340
>> jffs2_verify_write+0xef/0x440
>> __jffs2_flush_wbuf+0x3fa/0x3540
>> jffs2_flush_wbuf_gc+0x1b1/0x2e0
>> process_one_work+0x58b/0x11e0
>> worker_thread+0x8f/0xfe0
>> kthread+0x2ae/0x3a0
>> ret_from_fork+0x35/0x40
>>
>> Fix the problem by checking the validity of wbuf_verify before
>> using it in jffs2_verify_write().
>>
>> Cc: [email protected]
>> Fixes: 0029da3bf430 ("JFFS2: add UBI support")
>> Signed-off-by: Hou Tao <[email protected]>
>> ---
>> fs/jffs2/wbuf.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
>> index c6821a509481..3de45f4559d1 100644
>> --- a/fs/jffs2/wbuf.c
>> +++ b/fs/jffs2/wbuf.c
>> @@ -234,6 +234,13 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf,
>> size_t retlen;
>> char *eccstr;
>>
>> + /*
>> + * MTD emulated by UBI volume doesn't allocate wbuf_verify,
>> + * because it can do the verification itself.
>> + */
>> + if (!c->wbuf_verify)
>> + return 0;
>> +
>> ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, c->wbuf_verify);
>> if (ret && ret != -EUCLEAN && ret != -EBADMSG) {
>> pr_warn("%s(): Read back of page at %08x failed: %d\n",
>>
>
>
> ______________________________________________________
> Linux MTD discussion mailing list
> http://lists.infradead.org/mailman/listinfo/linux-mtd/
>
>


2018-12-17 00:26:21

by Richard Weinberger

[permalink] [raw]
Subject: Re: [PATCH] jffs2: ensure wbuf_verify is valid before using it.

On Sat, Oct 20, 2018 at 2:06 PM Hou Tao <[email protected]> wrote:
>
> Now MTD emulated by UBI volumn doesn't allocate wbuf_verify in
> jffs2_ubivol_setup(), because UBI can do the verifcation itself,
> so when CONFIG_JFFS2_FS_WBUF_VERIFY is enabled and a MTD device
> emulated by UBI volumn is used, a Oops will occur as show in the
> following trace:
>
> general protection fault: 0000 [#1] SMP KASAN PTI
> CPU: 6 PID: 404 Comm: kworker/6:1 Not tainted 4.19.0-rc8
> Workqueue: events_long delayed_wbuf_sync
> RIP: 0010:ubi_io_read+0x156/0x650
> Call Trace:
> ubi_eba_read_leb+0x57d/0xba0
> ubi_leb_read+0xe5/0x1b0
> gluebi_read+0x10c/0x1a0
> mtd_read+0x112/0x340
> jffs2_verify_write+0xef/0x440
> __jffs2_flush_wbuf+0x3fa/0x3540
> jffs2_flush_wbuf_gc+0x1b1/0x2e0
> process_one_work+0x58b/0x11e0
> worker_thread+0x8f/0xfe0
> kthread+0x2ae/0x3a0
> ret_from_fork+0x35/0x40
>
> Fix the problem by checking the validity of wbuf_verify before
> using it in jffs2_verify_write().
>
> Cc: [email protected]
> Fixes: 0029da3bf430 ("JFFS2: add UBI support")
> Signed-off-by: Hou Tao <[email protected]>

Reviewed-by: Richard Weinberger <[email protected]>

BTW: Are you actually using glubi? It is on my list of things I'd like
to kill. :-)

--
Thanks,
//richard