* [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled
@ 2020-06-01 9:11 Zhihao Cheng
2020-06-02 9:23 ` Sascha Hauer
0 siblings, 1 reply; 3+ messages in thread
From: Zhihao Cheng @ 2020-06-01 9:11 UTC (permalink / raw)
To: linux-mtd, linux-kernel; +Cc: richard, s.hauer, yi.zhang
Following process triggers a memleak caused by forgetting to release the
initial anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled):
1. attach -> __erase_worker -> produce the initial anchor PEB
2. detach -> ubi_fastmap_close (Do nothing, it should have released the
initial anchor PEB)
Don't produce the initial anchor PEB in __erase_worker() when fastmap
is disabled.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs")
Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com
---
drivers/mtd/ubi/wl.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 5146cce5fe32..5ebe1084a8e7 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1079,13 +1079,19 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
if (!err) {
spin_lock(&ubi->wl_lock);
- if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
+#ifdef CONFIG_MTD_UBI_FASTMAP
+ if (!ubi->fm_disabled && !ubi->fm_anchor &&
+ e->pnum < UBI_FM_MAX_START) {
ubi->fm_anchor = e;
ubi->fm_do_produce_anchor = 0;
} else {
wl_tree_add(e, &ubi->free);
ubi->free_count++;
}
+#else
+ wl_tree_add(e, &ubi->free);
+ ubi->free_count++;
+#endif
spin_unlock(&ubi->wl_lock);
--
2.25.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled
2020-06-01 9:11 [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled Zhihao Cheng
@ 2020-06-02 9:23 ` Sascha Hauer
2020-06-02 11:11 ` Zhihao Cheng
0 siblings, 1 reply; 3+ messages in thread
From: Sascha Hauer @ 2020-06-02 9:23 UTC (permalink / raw)
To: Zhihao Cheng; +Cc: linux-mtd, linux-kernel, richard, yi.zhang
Hi,
On Mon, Jun 01, 2020 at 05:11:34PM +0800, Zhihao Cheng wrote:
> Following process triggers a memleak caused by forgetting to release the
> initial anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled):
> 1. attach -> __erase_worker -> produce the initial anchor PEB
> 2. detach -> ubi_fastmap_close (Do nothing, it should have released the
> initial anchor PEB)
>
> Don't produce the initial anchor PEB in __erase_worker() when fastmap
> is disabled.
>
> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
> Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs")
> Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com
> ---
> drivers/mtd/ubi/wl.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
> index 5146cce5fe32..5ebe1084a8e7 100644
> --- a/drivers/mtd/ubi/wl.c
> +++ b/drivers/mtd/ubi/wl.c
> @@ -1079,13 +1079,19 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
> if (!err) {
> spin_lock(&ubi->wl_lock);
>
> - if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
> +#ifdef CONFIG_MTD_UBI_FASTMAP
> + if (!ubi->fm_disabled && !ubi->fm_anchor &&
> + e->pnum < UBI_FM_MAX_START) {
Rather than introducing another #ifdef you could do a
if (IS_ENABLED(CONFIG_MTD_UBI_FASTMAP) &&
!ubi->fm_disabled && !ubi->fm_anchor &&
e->pnum < UBI_FM_MAX_START)
And I am not sure if the IS_ENABLED(CONFIG_MTD_UBI_FASTMAP) is necessary
at all because we do a ubi->fm_disabled = 1 when fastmap is disabled.
Regards,
Sascha
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled
2020-06-02 9:23 ` Sascha Hauer
@ 2020-06-02 11:11 ` Zhihao Cheng
0 siblings, 0 replies; 3+ messages in thread
From: Zhihao Cheng @ 2020-06-02 11:11 UTC (permalink / raw)
To: Sascha Hauer; +Cc: linux-mtd, linux-kernel, richard, yi.zhang
在 2020/6/2 17:23, Sascha Hauer 写道:
> Hi,
>
> On Mon, Jun 01, 2020 at 05:11:34PM +0800, Zhihao Cheng wrote:
>> Following process triggers a memleak caused by forgetting to release the
>> initial anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled):
>> 1. attach -> __erase_worker -> produce the initial anchor PEB
>> 2. detach -> ubi_fastmap_close (Do nothing, it should have released the
>> initial anchor PEB)
>>
>> Don't produce the initial anchor PEB in __erase_worker() when fastmap
>> is disabled.
>>
>> Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
>> Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs")
>> Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com
>> ---
>> drivers/mtd/ubi/wl.c | 8 +++++++-
>> 1 file changed, 7 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
>> index 5146cce5fe32..5ebe1084a8e7 100644
>> --- a/drivers/mtd/ubi/wl.c
>> +++ b/drivers/mtd/ubi/wl.c
>> @@ -1079,13 +1079,19 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
>> if (!err) {
>> spin_lock(&ubi->wl_lock);
>>
>> - if (!ubi->fm_anchor && e->pnum < UBI_FM_MAX_START) {
>> +#ifdef CONFIG_MTD_UBI_FASTMAP
>> + if (!ubi->fm_disabled && !ubi->fm_anchor &&
>> + e->pnum < UBI_FM_MAX_START) {
> Rather than introducing another #ifdef you could do a
>
> if (IS_ENABLED(CONFIG_MTD_UBI_FASTMAP) &&
> !ubi->fm_disabled && !ubi->fm_anchor &&
> e->pnum < UBI_FM_MAX_START)
>
> And I am not sure if the IS_ENABLED(CONFIG_MTD_UBI_FASTMAP) is necessary
> at all because we do a ubi->fm_disabled = 1 when fastmap is disabled.
>
> Regards,
> Sascha
>
Agree.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-02 11:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 9:11 [PATCH] ubi: fastmap: Don't produce the initial anchor PEB when fastmap is disabled Zhihao Cheng
2020-06-02 9:23 ` Sascha Hauer
2020-06-02 11:11 ` Zhihao Cheng
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).