* [PATCH] ext2: Fix memory leak when truncate races ext2_get_blocks
@ 2017-06-24 0:37 Ernesto A. Fernández
2017-07-13 11:46 ` Jan Kara
0 siblings, 1 reply; 3+ messages in thread
From: Ernesto A. Fernández @ 2017-06-24 0:37 UTC (permalink / raw)
To: jack, linux-ext4
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.
Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
---
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(+)
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 2dcbd56..30163d0 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -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));
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH] ext2: Fix memory leak when truncate races ext2_get_blocks
@ 2017-07-05 23:08 Ernesto A. Fernández
0 siblings, 0 replies; 3+ messages in thread
From: Ernesto A. Fernández @ 2017-07-05 23:08 UTC (permalink / raw)
To: Jan Kara, linux-ext4
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.
Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
---
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(+)
diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
index 2dcbd56..30163d0 100644
--- a/fs/ext2/inode.c
+++ b/fs/ext2/inode.c
@@ -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));
--
2.1.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] ext2: Fix memory leak when truncate races ext2_get_blocks
2017-06-24 0:37 Ernesto A. Fernández
@ 2017-07-13 11:46 ` Jan Kara
0 siblings, 0 replies; 3+ messages in thread
From: Jan Kara @ 2017-07-13 11:46 UTC (permalink / raw)
To: Ernesto A. Fernández; +Cc: jack, linux-ext4
On Fri 23-06-17 21:37:21, Ernesto A. Fernández wrote:
> 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.
>
> Signed-off-by: Ernesto A. Fernández <ernesto.mnd.fernandez@gmail.com>
> ---
> 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
>
> fs/ext2/inode.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c
> index 2dcbd56..30163d0 100644
> --- a/fs/ext2/inode.c
> +++ b/fs/ext2/inode.c
> @@ -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));
> --
> 2.1.4
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-13 11:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-05 23:08 [PATCH] ext2: Fix memory leak when truncate races ext2_get_blocks Ernesto A. Fernández
-- strict thread matches above, loose matches on Subject: below --
2017-06-24 0:37 Ernesto A. Fernández
2017-07-13 11:46 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).