Skip to contentSkip to conversation

ext2: Fix memory leak when truncate races ext2_get_blocks

PATCH In review Ernesto A. Fernández 2 participants 2 messages Jun 24, 2017 – Jul 13, 2017 ext2 file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: Fix memory leak when truncate races ext2_get_blocks

Buffer heads referencing indirect blocks may not be released if the file is truncated at the right time. This happens because ext2_get_branch() returns NULL when it finds the whole chain of indirect blocks already set, and when truncate alters the chain this value of NULL is treated as the address of the last head to be released. Handle this in the same way as it's done after the got_it label.

---
Despite trying I haven't actually managed to trigger this race. I tested the patch by inducing regular failures in verify_chain().

 fs/ext2/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/ext2/inode.c +1 -0
index 2dcbd56..30163d0 100644
@@ -659,6 +659,7 @@ static int ext2_get_blocks(struct inode *inode,
 				 */
 				err = -EAGAIN;
 				count = 0;
+				partial = chain + depth - 1;
 				break;
 			}
 			blk = le32_to_cpu(*(chain[depth-1].p + count));
Signature · 1 line
2.1.4
#1 lore raw
Quoted 11 lines · Ernesto A. Fernández

Buffer heads referencing indirect blocks may not be released if the file is truncated at the right time. This happens because ext2_get_branch() returns NULL when it finds the whole chain of indirect blocks already set, and when truncate alters the chain this value of NULL is treated as the address of the last head to be released. Handle this in the same way as it's done after the got_it label.

---
Despite trying I haven't actually managed to trigger this race. I tested the patch by inducing regular failures in verify_chain().

Thanks! I've merged the patch to my tree.

Honza

Quoted 20 lines
 fs/ext2/inode.c | 1 +
 1 file changed, 1 insertion(+)
fs/ext2/inode.c +1 -0
index 2dcbd56..30163d0 100644
@@ -659,6 +659,7 @@ static int ext2_get_blocks(struct inode *inode,
 				 */
 				err = -EAGAIN;
 				count = 0;
+				partial = chain + depth - 1;
 				break;
 			}
 			blk = le32_to_cpu(*(chain[depth-1].p + count));
Signature · 1 line
2.1.4
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR