From: Zhihao Cheng <chengzhihao1@huawei.com>
To: Richard Weinberger <richard@nod.at>,
ZhaoLong Wang <wangzhaolong1@huawei.com>
Cc: Miquel Raynal <miquel.raynal@bootlin.com>,
Vignesh Raghavendra <vigneshr@ti.com>,
<dpervushin@embeddedalley.com>,
Artem Bityutskiy <Artem.Bityutskiy@nokia.com>,
linux-mtd <linux-mtd@lists.infradead.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
yi zhang <yi.zhang@huawei.com>, yangerkun <yangerkun@huawei.com>
Subject: Re: [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier
Date: Fri, 20 Oct 2023 10:27:57 +0800 [thread overview]
Message-ID: <891e554b-c133-6378-3a65-836fc9147e54@huawei.com> (raw)
In-Reply-To: <1381458025.20897.1697747248632.JavaMail.zimbra@nod.at>
在 2023/10/20 4:27, Richard Weinberger 写道:
> ----- Ursprüngliche Mail -----
>> Von: "ZhaoLong Wang" <wangzhaolong1@huawei.com>
>> An: "richard" <richard@nod.at>, "Miquel Raynal" <miquel.raynal@bootlin.com>, "Vignesh Raghavendra" <vigneshr@ti.com>,
>> dpervushin@embeddedalley.com, "Artem Bityutskiy" <Artem.Bityutskiy@nokia.com>
>> CC: "linux-mtd" <linux-mtd@lists.infradead.org>, "linux-kernel" <linux-kernel@vger.kernel.org>, "chengzhihao1"
>> <chengzhihao1@huawei.com>, "ZhaoLong Wang" <wangzhaolong1@huawei.com>, "yi zhang" <yi.zhang@huawei.com>, "yangerkun"
>> <yangerkun@huawei.com>
>> Gesendet: Mittwoch, 18. Oktober 2023 14:16:18
>> Betreff: [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier
>
>> If both flt.ko and gluebi.ko are loaded, the notiier of ftl
>> triggers NULL pointer dereference when trying to access
>> ‘gluebi->desc’ in gluebi_read().
>>
>> ubi_gluebi_init
>> ubi_register_volume_notifier
>> ubi_enumerate_volumes
>> ubi_notify_all
>> gluebi_notify nb->notifier_call()
>> gluebi_create
>> mtd_device_register
>> mtd_device_parse_register
>> add_mtd_device
>> blktrans_notify_add not->add()
>> ftl_add_mtd tr->add_mtd()
>> scan_header
>> mtd_read
>> mtd_read
>> mtd_read_oob
>> gluebi_read mtd->read()
>> gluebi->desc - NULL
>>
>> Detailed reproduction information available at the link[1],
>>
>> In the normal case, obtain gluebi->desc in the gluebi_get_device(),
>> and accesses gluebi->desc in the gluebi_read(). However,
>> gluebi_get_device() is not executed in advance in the
>> ftl_add_mtd() process, which leads to NULL pointer dereference.
>>
>> The value of gluebi->desc may also be a negative error code, which
>> triggers the page fault error.
>>
>> This patch has the following modifications:
>>
>> 1. Do not assign gluebi->desc to the error code. Use the NULL instead.
>>
>> 2. Always check the validity of gluebi->desc in gluebi_read() If the
>> gluebi->desc is NULL, try to get MTD device.
>>
>> Such a modification currently works because the mutex "mtd_table_mutex"
>> is held on all necessary paths, including the ftl_add_mtd() call path,
>> open and close paths. Therefore, many race condition can be avoided.
>
> I see the problem, but I'm not really satisfied by the solution.
> Adding this hack to gluebi_read() is not nice at all.
Yes, it's jsut a workaround. At the begining, I prefer that increasing
volume refcnt (by ubi_open_volume) in gluebi_create and releasing volume
refcnt in gluebi_remove. It looks more reasonable that holding a refcnt
of UBI volume when gluebi is alive. After looking through the code, the
creation/destroying of gluebi is triggered by volume
actions(UBI_VOLUME_ADDED/UBI_VOLUME_REMOVED), which means that:
1. gluebi_remove is depended on UBI_VOLUME_REMOVED(triggered by
ubi_remove_volume)
2. ubi_remove_volume won't be executed until the refcnt of volume
becomes 0(released by gluebi_remove)
If we add new ioctls to control creation/destroying of gluebi, then
gluebi mtd won't be automatically created when UBI volume is added. I'm
not certain whether this change will effect existing startup process
that depends on gluebi.
>
> Is there a strong reason why have to defer ubi_open_volume() to
> gluebi_get_device()?
>
> Miquel, what do you think?
>
> Thanks,
> //richard
>
> .
>
next prev parent reply other threads:[~2023-10-20 2:28 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 12:16 ZhaoLong Wang
2023-10-19 1:57 ` Zhihao Cheng
2023-10-19 20:27 ` Richard Weinberger
2023-10-20 2:27 ` Zhihao Cheng [this message]
2023-10-21 16:09 ` Richard Weinberger
2023-10-23 6:41 ` ZhaoLong Wang
2023-10-23 6:46 ` Richard Weinberger
2023-10-23 7:12 ` ZhaoLong Wang
2023-10-23 7:16 ` Richard Weinberger
2023-10-23 7:09 ` Zhihao Cheng
2023-10-23 7:15 ` Richard Weinberger
2023-10-23 7:36 ` Zhihao Cheng
2024-06-17 14:21 Gagan Sidhu
2024-06-17 14:25 Gagan Sidhu
2024-06-17 14:31 ` Richard Weinberger
2024-06-17 15:42 ` Richard Weinberger
[not found] ` <14779870-BA54-4ABF-8ABF-FF1D23D172A7@mac.com>
2024-06-17 16:00 ` Richard Weinberger
2024-06-17 16:05 ` Gagan Sidhu
2024-06-17 16:52 ` Richard Weinberger
[not found] ` <E3E2C13C-1E52-46F2-BE2D-D2592C3369DB@mac.com>
2024-06-17 17:33 ` Gagan Sidhu
2024-06-17 17:48 ` Gagan Sidhu
2024-06-17 18:09 ` Richard Weinberger
2024-06-17 18:18 ` Gagan Sidhu
2024-06-17 18:32 ` Richard Weinberger
2024-06-17 18:46 ` Gagan Sidhu
2024-06-17 18:52 ` Richard Weinberger
2024-06-17 20:29 ` Daniel Golle
2024-06-17 21:22 ` Gagan Sidhu
2024-06-17 22:13 ` Gagan Sidhu
2024-06-18 4:03 ` Zhihao Cheng
2024-06-20 22:06 ` Gagan Sidhu
2024-06-21 1:59 ` Zhihao Cheng
2024-06-21 2:09 ` Gagan Sidhu
2024-06-21 3:03 ` Zhihao Cheng
2024-06-21 4:27 ` Gagan Sidhu
2024-06-21 4:55 ` Zhihao Cheng
2024-06-21 11:36 ` Gagan Sidhu
2024-06-22 2:37 ` Zhihao Cheng
2024-06-22 2:43 ` Gagan Sidhu
2024-06-22 21:07 ` Daniel Golle
2024-06-24 19:00 ` Gagan Sidhu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=891e554b-c133-6378-3a65-836fc9147e54@huawei.com \
--to=chengzhihao1@huawei.com \
--cc=Artem.Bityutskiy@nokia.com \
--cc=dpervushin@embeddedalley.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
--cc=wangzhaolong1@huawei.com \
--cc=yangerkun@huawei.com \
--cc=yi.zhang@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®