Skip to contentSkip to conversation

ubifs: Handle LPT corruption better in ubifs_garbage_collect_leb()

PATCH In review Richard Weinberger 2 participants 3 messages Jul 4, 2018 – Jan 10, 2023

Subsystems (2)
lore
Share & tools
lore

Richard Weinberger

author maintainer
#0 lore raw

PATCH 1/1 ubifs: Handle LPT corruption better in ubifs_garbage_collect_leb()

If ubifs_garbage_collect_leb() notes a LPT problem, empty LEB, but LPT has it makred as used, an ubifs_assert() is not enough. We have to abort GC. Otherwise list_entry() returns an invalid scan object and the kernel crashes.

c: <[email protected]>

Fixes 1e51764a3c2a ("UBIFS: add new flash file system")
---
 fs/ubifs/gc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
fs/ubifs/gc.c +7 -1
index a03a47cf880d..11c09ce3c795 100644
@@ -513,7 +513,13 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
 	if (IS_ERR(sleb))
 		return PTR_ERR(sleb);
 
-	ubifs_assert(!list_empty(&sleb->nodes));
+	if (list_empty(&sleb->nodes)) {
+		ubifs_err(c, "Bad accouting information, LEB %i is marked as used but no nodes found!",
+			  lnum);
+		dump_stack();
+		return -EUCLEAN;
+	}
+
 	snod = list_entry(sleb->nodes.next, struct ubifs_scan_node, list);
 
 	if (snod->type == UBIFS_IDX_NODE) {
Signature · 1 line
2.18.0
#1 lore raw

Hi Richard,

Quoted 11 lines · Richard Weinberger

If ubifs_garbage_collect_leb() notes a LPT problem, empty LEB, but LPT has it makred as used, an ubifs_assert() is not enough. We have to abort GC. Otherwise list_entry() returns an invalid scan object and the kernel crashes.

c: <[email protected]>

Fixes 1e51764a3c2a ("UBIFS: add new flash file system")
---
 fs/ubifs/gc.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

What happened to this patch? It never made it anywhere. I just stumbled over this issue and found this patch afterwards.

Quoted 6 lines
fs/ubifs/gc.c +0 -0
index a03a47cf880d..11c09ce3c795 100644

fs/ubifs/gc.c int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp) · line 521

Quoted 10 lines
fs/ubifs/gc.c +6 -1
@@ -513,7 +513,13 @@ int ubifs_garbage_collect_leb(struct ubifs_info *c, struct ubifs_lprops *lp)
 	if (IS_ERR(sleb))
 		return PTR_ERR(sleb);
 
-	ubifs_assert(!list_empty(&sleb->nodes));
+	if (list_empty(&sleb->nodes)) {
+		ubifs_err(c, "Bad accouting information, LEB %i is marked as used but no nodes found!",
+			  lnum);
+		dump_stack();
+		return -EUCLEAN;
+	}

This changes the behaviour. With ubifs_assert() UBIFS goes readonly, but with this change it stays rw. Is this intended?

Sascha

Signature · 4 lines
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 |
author maintainer
#2 lore raw

Sascha,

----- Ursprüngliche Mail -----

Quoted 2 lines

What happened to this patch? It never made it anywhere. I just stumbled over this issue and found this patch afterwards.

I have withdrawn this patch because it cures only a symptom and not the root cause. The root cause is a LPT corruption.
IIRC I saw the problem while investigating into another problem which caused UBIFS corruptions.

Thanks,
//richard

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/