* [PATCH v3 0/2] ubi: fastmap: Produce and release fm_anchor peb correctly
@ 2020-07-07 13:40 ` Zhihao Cheng
0 siblings, 0 replies; 6+ messages in thread
From: Zhihao Cheng @ 2020-07-07 13:40 UTC (permalink / raw)
To: linux-mtd, linux-kernel; +Cc: richard, yi.zhang, s.hauer
v1 -> v2:
Adapt Sascha's suggestions for fm_diabled checking in __erase_worker().
v2 -> v3:
Free fm_anchor peb during cloing fastmap.
Zhihao Cheng (2):
ubi: fastmap: Don't produce the initial next anchor PEB when fastmap
is disabled
ubi: fastmap: Free fastmap next anchor peb during detach
drivers/mtd/ubi/fastmap-wl.c | 5 +++++
drivers/mtd/ubi/wl.c | 3 ++-
2 files changed, 7 insertions(+), 1 deletion(-)
--
2.25.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 0/2] ubi: fastmap: Produce and release fm_anchor peb correctly
@ 2020-07-07 13:40 ` Zhihao Cheng
0 siblings, 0 replies; 6+ messages in thread
From: Zhihao Cheng @ 2020-07-07 13:40 UTC (permalink / raw)
To: linux-mtd, linux-kernel; +Cc: richard, s.hauer, yi.zhang
v1 -> v2:
Adapt Sascha's suggestions for fm_diabled checking in __erase_worker().
v2 -> v3:
Free fm_anchor peb during cloing fastmap.
Zhihao Cheng (2):
ubi: fastmap: Don't produce the initial next anchor PEB when fastmap
is disabled
ubi: fastmap: Free fastmap next anchor peb during detach
drivers/mtd/ubi/fastmap-wl.c | 5 +++++
drivers/mtd/ubi/wl.c | 3 ++-
2 files changed, 7 insertions(+), 1 deletion(-)
--
2.25.4
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] ubi: fastmap: Don't produce the initial next anchor PEB when fastmap is disabled
2020-07-07 13:40 ` Zhihao Cheng
@ 2020-07-07 13:41 ` Zhihao Cheng
-1 siblings, 0 replies; 6+ messages in thread
From: Zhihao Cheng @ 2020-07-07 13:41 UTC (permalink / raw)
To: linux-mtd, linux-kernel; +Cc: richard, yi.zhang, s.hauer
Following process triggers a memleak caused by forgetting to release the
initial next anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled):
1. attach -> __erase_worker -> produce the initial next anchor PEB
2. detach -> ubi_fastmap_close (Do nothing, it should have released the
initial next anchor PEB)
Don't produce the initial next anchor PEB in __erase_worker() when fastmap
is disabled.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Suggested-by: Sascha Hauer <s.hauer@pengutronix.de>
Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs")
Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com
---
drivers/mtd/ubi/wl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 27636063ed1b..42cac572f82d 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1086,7 +1086,8 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
if (!err) {
spin_lock(&ubi->wl_lock);
- if (!ubi->fm_next_anchor && e->pnum < UBI_FM_MAX_START) {
+ if (!ubi->fm_disabled && !ubi->fm_next_anchor &&
+ e->pnum < UBI_FM_MAX_START) {
/* Abort anchor production, if needed it will be
* enabled again in the wear leveling started below.
*/
--
2.25.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 1/2] ubi: fastmap: Don't produce the initial next anchor PEB when fastmap is disabled
@ 2020-07-07 13:41 ` Zhihao Cheng
0 siblings, 0 replies; 6+ messages in thread
From: Zhihao Cheng @ 2020-07-07 13:41 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 next anchor PEB (CONFIG_MTD_UBI_FASTMAP is disabled):
1. attach -> __erase_worker -> produce the initial next anchor PEB
2. detach -> ubi_fastmap_close (Do nothing, it should have released the
initial next anchor PEB)
Don't produce the initial next anchor PEB in __erase_worker() when fastmap
is disabled.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Suggested-by: Sascha Hauer <s.hauer@pengutronix.de>
Fixes: f9c34bb529975fe ("ubi: Fix producing anchor PEBs")
Reported-by: syzbot+d9aab50b1154e3d163f5@syzkaller.appspotmail.com
---
drivers/mtd/ubi/wl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 27636063ed1b..42cac572f82d 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -1086,7 +1086,8 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
if (!err) {
spin_lock(&ubi->wl_lock);
- if (!ubi->fm_next_anchor && e->pnum < UBI_FM_MAX_START) {
+ if (!ubi->fm_disabled && !ubi->fm_next_anchor &&
+ e->pnum < UBI_FM_MAX_START) {
/* Abort anchor production, if needed it will be
* enabled again in the wear leveling started below.
*/
--
2.25.4
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] ubi: fastmap: Free fastmap next anchor peb during detach
2020-07-07 13:40 ` Zhihao Cheng
@ 2020-07-07 13:41 ` Zhihao Cheng
-1 siblings, 0 replies; 6+ messages in thread
From: Zhihao Cheng @ 2020-07-07 13:41 UTC (permalink / raw)
To: linux-mtd, linux-kernel; +Cc: richard, yi.zhang, s.hauer
ubi_wl_entry related with the fm_next_anchor PEB is not freed during
detach, which causes a memory leak.
Don't forget to release fm_next_anchor PEB while detaching ubi from
mtd when CONFIG_MTD_UBI_FASTMAP is enabled.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Fixes: 4b68bf9a69d22d ("ubi: Select fastmap anchor PEBs considering...")
---
drivers/mtd/ubi/fastmap-wl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index 83afc00e365a..28f55f9cf715 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -381,6 +381,11 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
ubi->fm_anchor = NULL;
}
+ if (ubi->fm_next_anchor) {
+ return_unused_peb(ubi, ubi->fm_next_anchor);
+ ubi->fm_next_anchor = NULL;
+ }
+
if (ubi->fm) {
for (i = 0; i < ubi->fm->used_blocks; i++)
kfree(ubi->fm->e[i]);
--
2.25.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v3 2/2] ubi: fastmap: Free fastmap next anchor peb during detach
@ 2020-07-07 13:41 ` Zhihao Cheng
0 siblings, 0 replies; 6+ messages in thread
From: Zhihao Cheng @ 2020-07-07 13:41 UTC (permalink / raw)
To: linux-mtd, linux-kernel; +Cc: richard, s.hauer, yi.zhang
ubi_wl_entry related with the fm_next_anchor PEB is not freed during
detach, which causes a memory leak.
Don't forget to release fm_next_anchor PEB while detaching ubi from
mtd when CONFIG_MTD_UBI_FASTMAP is enabled.
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Fixes: 4b68bf9a69d22d ("ubi: Select fastmap anchor PEBs considering...")
---
drivers/mtd/ubi/fastmap-wl.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/mtd/ubi/fastmap-wl.c b/drivers/mtd/ubi/fastmap-wl.c
index 83afc00e365a..28f55f9cf715 100644
--- a/drivers/mtd/ubi/fastmap-wl.c
+++ b/drivers/mtd/ubi/fastmap-wl.c
@@ -381,6 +381,11 @@ static void ubi_fastmap_close(struct ubi_device *ubi)
ubi->fm_anchor = NULL;
}
+ if (ubi->fm_next_anchor) {
+ return_unused_peb(ubi, ubi->fm_next_anchor);
+ ubi->fm_next_anchor = NULL;
+ }
+
if (ubi->fm) {
for (i = 0; i < ubi->fm->used_blocks; i++)
kfree(ubi->fm->e[i]);
--
2.25.4
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-07-07 13:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-07 13:40 [PATCH v3 0/2] ubi: fastmap: Produce and release fm_anchor peb correctly Zhihao Cheng
2020-07-07 13:40 ` Zhihao Cheng
2020-07-07 13:41 ` [PATCH v3 1/2] ubi: fastmap: Don't produce the initial next anchor PEB when fastmap is disabled Zhihao Cheng
2020-07-07 13:41 ` Zhihao Cheng
2020-07-07 13:41 ` [PATCH v3 2/2] ubi: fastmap: Free fastmap next anchor peb during detach Zhihao Cheng
2020-07-07 13:41 ` Zhihao Cheng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.