* [PATCH] btrfs: relocation: set trans to be NULL after free
@ 2018-11-23 10:10 Pan Bian
2018-11-23 11:18 ` Qu Wenruo
2018-11-23 12:46 ` David Sterba
0 siblings, 2 replies; 3+ messages in thread
From: Pan Bian @ 2018-11-23 10:10 UTC (permalink / raw)
To: Chris Mason, Josef Bacik, David Sterba
Cc: Wang Shilong, linux-btrfs, linux-kernel, Pan Bian
The function relocate_block_group calls btrfs_end_transaction to release
trans when update_backref_cache returns 1, and then continues the loop
body. If btrfs_block_rsv_refill fails this time, it will jump out the
loop and the freed trans will be accessed. This may result in a
use-after-free bug. The patch assigns NULL to trans after trans is
released so that it will not be accessed.
Fixes: 0647bf564f1("Btrfs: improve forever loop when doing balance
relocation")
Signed-off-by: Pan Bian <bianpan2016@163.com>
---
fs/btrfs/relocation.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 924116f..a3f75b8 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3959,6 +3959,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
restart:
if (update_backref_cache(trans, &rc->backref_cache)) {
btrfs_end_transaction(trans);
+ trans = NULL;
continue;
}
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: relocation: set trans to be NULL after free
2018-11-23 10:10 [PATCH] btrfs: relocation: set trans to be NULL after free Pan Bian
@ 2018-11-23 11:18 ` Qu Wenruo
2018-11-23 12:46 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: Qu Wenruo @ 2018-11-23 11:18 UTC (permalink / raw)
To: Pan Bian, Chris Mason, Josef Bacik, David Sterba
Cc: Wang Shilong, linux-btrfs, linux-kernel
[-- Attachment #1.1: Type: text/plain, Size: 1158 bytes --]
On 2018/11/23 下午6:10, Pan Bian wrote:
> The function relocate_block_group calls btrfs_end_transaction to release
> trans when update_backref_cache returns 1, and then continues the loop
> body. If btrfs_block_rsv_refill fails this time, it will jump out the
> loop and the freed trans will be accessed. This may result in a
> use-after-free bug. The patch assigns NULL to trans after trans is
> released so that it will not be accessed.
>
> Fixes: 0647bf564f1("Btrfs: improve forever loop when doing balance
> relocation")
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Thanks,
Qu
> ---
> fs/btrfs/relocation.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
> index 924116f..a3f75b8 100644
> --- a/fs/btrfs/relocation.c
> +++ b/fs/btrfs/relocation.c
> @@ -3959,6 +3959,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
> restart:
> if (update_backref_cache(trans, &rc->backref_cache)) {
> btrfs_end_transaction(trans);
> + trans = NULL;
> continue;
> }
>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] btrfs: relocation: set trans to be NULL after free
2018-11-23 10:10 [PATCH] btrfs: relocation: set trans to be NULL after free Pan Bian
2018-11-23 11:18 ` Qu Wenruo
@ 2018-11-23 12:46 ` David Sterba
1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2018-11-23 12:46 UTC (permalink / raw)
To: Pan Bian
Cc: Chris Mason, Josef Bacik, David Sterba, Wang Shilong,
linux-btrfs, linux-kernel
On Fri, Nov 23, 2018 at 06:10:15PM +0800, Pan Bian wrote:
> The function relocate_block_group calls btrfs_end_transaction to release
> trans when update_backref_cache returns 1, and then continues the loop
> body. If btrfs_block_rsv_refill fails this time, it will jump out the
> loop and the freed trans will be accessed. This may result in a
> use-after-free bug. The patch assigns NULL to trans after trans is
> released so that it will not be accessed.
>
> Fixes: 0647bf564f1("Btrfs: improve forever loop when doing balance
> relocation")
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
Good catch, thanks.
Reviewed-by: David Sterba <dsterba@suse.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-11-23 12:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-23 10:10 [PATCH] btrfs: relocation: set trans to be NULL after free Pan Bian
2018-11-23 11:18 ` Qu Wenruo
2018-11-23 12:46 ` David Sterba
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).