Skip to contentSkip to conversation

unbugger ext2_empty_dir()

PATCH In review Al Viro 2 participants 2 messages Nov 26, 2022 – Nov 28, 2022

Subsystems (2)
lore
Share & tools
lore

Al Viro

author maintainer
#0 lore raw

PATCH 1/1 unbugger ext2_empty_dir()

In 27cfa258951a "ext2: fix fs corruption when trying to remove
a non-empty directory with IO error" a funny thing has happened:

- page = ext2_get_page(inode, i, dir_has_error, &page_addr);
+ page = ext2_get_page(inode, i, 0, &page_addr);

- if (IS_ERR(page)) {
- dir_has_error = 1;
- continue;
- }
+ if (IS_ERR(page))
+ goto not_empty;

And at not_empty: we hit ext2_put_page(page, page_addr), which does put_page(page). Which, unless I'm very mistaken, should oops immediately when given ERR_PTR(-E...) as page.

OK, shit happens, insufficiently tested patches included. But when commit in question describes the fault-injection test that exercised that particular failure exit...

Ow.

---

fs/ext2/dir.c +1 -1
index 8f597753ac12..5202eddfc3c0 100644
@@ -679,7 +679,7 @@ int ext2_empty_dir (struct inode * inode)
 		page = ext2_get_page(inode, i, 0, &page_addr);
 
 		if (IS_ERR(page))
-			goto not_empty;
+			return 0;
 
 		kaddr = page_addr;
 		de = (ext2_dirent *)kaddr;
reviewer
#1 lore raw
Quoted 17 lines · Al Viro

In 27cfa258951a "ext2: fix fs corruption when trying to remove
a non-empty directory with IO error" a funny thing has happened:

(quoted diff) +1 -1
-               page = ext2_get_page(inode, i, dir_has_error, &page_addr);
+               page = ext2_get_page(inode, i, 0, &page_addr);
 
 -               if (IS_ERR(page)) {
 -                       dir_has_error = 1;
 -                       continue;
 -               }
 +               if (IS_ERR(page))
 +                       goto not_empty;

And at not_empty: we hit ext2_put_page(page, page_addr), which does put_page(page). Which, unless I'm very mistaken, should oops immediately when given ERR_PTR(-E...) as page.

Quoted 7 lines

OK, shit happens, insufficiently tested patches included. But when commit in question describes the fault-injection test that exercised that particular failure exit...

Ow.

Right. I've clearly missed this when reviewing & merging the fix. And Ye Bin obviously didn't test this with his reproducer ;). Anyway, thanks for catching this! I've merged the patch to my tree.

Honza

Quoted 14 lines

---

fs/ext2/dir.c +1 -1
index 8f597753ac12..5202eddfc3c0 100644
@@ -679,7 +679,7 @@ int ext2_empty_dir (struct inode * inode)
 		page = ext2_get_page(inode, i, 0, &page_addr);
 
 		if (IS_ERR(page))
-			goto not_empty;
+			return 0;
 
 		kaddr = page_addr;
 		de = (ext2_dirent *)kaddr;
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR