[PATCH 03/10] UBI: fix some use after free bugs

Sascha Hauer s.hauer at pengutronix.de
Thu Sep 11 08:16:03 PDT 2014


From: Dan Carpenter <dan.carpenter at oracle.com>

Move the kmem_cache_free() calls down a couple lines.

Signed-off-by: Dan Carpenter <dan.carpenter at oracle.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy at linux.intel.com>
---
 drivers/mtd/ubi/fastmap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/ubi/fastmap.c b/drivers/mtd/ubi/fastmap.c
index de68c32..50db661 100644
--- a/drivers/mtd/ubi/fastmap.c
+++ b/drivers/mtd/ubi/fastmap.c
@@ -462,8 +462,8 @@ static int scan_pool(struct ubi_device *ubi, struct ubi_attach_info *ai,
 				}
 			}
 			if (found_orphan) {
-				kfree(tmp_aeb);
 				list_del(&tmp_aeb->u.list);
+				kfree(tmp_aeb);
 			}
 
 			new_aeb = kzalloc(sizeof(*new_aeb), GFP_KERNEL);
@@ -835,16 +835,16 @@ fail_bad:
 	ret = UBI_BAD_FASTMAP;
 fail:
 	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &used, u.list) {
-		free(tmp_aeb);
 		list_del(&tmp_aeb->u.list);
+		free(tmp_aeb);
 	}
 	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &eba_orphans, u.list) {
-		free(tmp_aeb);
 		list_del(&tmp_aeb->u.list);
+		free(tmp_aeb);
 	}
 	list_for_each_entry_safe(tmp_aeb, _tmp_aeb, &lfree, u.list) {
-		free(tmp_aeb);
 		list_del(&tmp_aeb->u.list);
+		free(tmp_aeb);
 	}
 
 	return ret;
-- 
2.1.0




More information about the barebox mailing list