lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Thu, 4 Oct 2018 13:50:12 +0200
From:   Lukas Czerner <lczerner@...hat.com>
To:     Jan Kara <jack@...e.cz>
Cc:     Ted Tso <tytso@....edu>, linux-ext4@...r.kernel.org,
        stable@...r.kernel.org
Subject: Re: [PATCH] jbd2: Fix use after free in jbd2_log_do_checkpoint()

On Thu, Oct 04, 2018 at 12:46:40PM +0200, Jan Kara wrote:
> The code cleaning transaction's lists of checkpoint buffers has a bug
> where it increases bh refcount only after releasing
> journal->j_list_lock. Thus the following race is possible:
> 
> CPU0					CPU1
> jbd2_log_do_checkpoint()
> 					jbd2_journal_try_to_free_buffers()
> 					  __journal_try_to_free_buffer(bh)
>   ...
>   while (transaction->t_checkpoint_io_list)
>   ...
>     if (buffer_locked(bh)) {
> 
> <-- IO completes now, buffer gets unlocked -->
> 
>       spin_unlock(&journal->j_list_lock);
> 					    spin_lock(&journal->j_list_lock);
> 					    __jbd2_journal_remove_checkpoint(jh);
> 					    spin_unlock(&journal->j_list_lock);
> 					  try_to_free_buffers(page);
>       get_bh(bh) <-- accesses freed bh
> 
> Fix the problem by grabbing bh reference before unlocking
> journal->j_list_lock.

Hi Jan,

nice catch. The patch looks good, you can add

Reviewed-by: Lukas Czerner <lczerner@...hat.com>

Btw, do you by any chance have a reproducer for this ?

-Lukas

> 
> Fixes: dc6e8d669cf5cb3ff84707c372c0a2a8a5e80845
> Fixes: be1158cc615fd723552f0d9912087423c7cadda5
> Reported-by: syzbot+7f4a27091759e2fe7453@...kaller.appspotmail.com
> CC: stable@...r.kernel.org
> Signed-off-by: Jan Kara <jack@...e.cz>
> ---
>  fs/jbd2/checkpoint.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
> index c125d662777c..26f8d7e46462 100644
> --- a/fs/jbd2/checkpoint.c
> +++ b/fs/jbd2/checkpoint.c
> @@ -251,8 +251,8 @@ int jbd2_log_do_checkpoint(journal_t *journal)
>  		bh = jh2bh(jh);
>  
>  		if (buffer_locked(bh)) {
> -			spin_unlock(&journal->j_list_lock);
>  			get_bh(bh);
> +			spin_unlock(&journal->j_list_lock);
>  			wait_on_buffer(bh);
>  			/* the journal_head may have gone by now */
>  			BUFFER_TRACE(bh, "brelse");
> @@ -333,8 +333,8 @@ int jbd2_log_do_checkpoint(journal_t *journal)
>  		jh = transaction->t_checkpoint_io_list;
>  		bh = jh2bh(jh);
>  		if (buffer_locked(bh)) {
> -			spin_unlock(&journal->j_list_lock);
>  			get_bh(bh);
> +			spin_unlock(&journal->j_list_lock);
>  			wait_on_buffer(bh);
>  			/* the journal_head may have gone by now */
>  			BUFFER_TRACE(bh, "brelse");
> -- 
> 2.16.4
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ