linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ext2: fix potential use after free
@ 2018-11-25  0:58 Pan Bian
  2018-11-27  9:19 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2018-11-25  0:58 UTC (permalink / raw)
  To: Jan Kara; +Cc: linux-ext4, linux-kernel, Pan Bian

The function ext2_xattr_set calls brelse(bh) to drop the reference count
of bh. After that, bh may be freed. However, following brelse(bh),
it reads bh->b_data via macro HDR(bh). This may result in a
use-after-free bug. This patch moves brelse(bh) after reading field.

Signed-off-by: Pan Bian <bianpan2016@163.com>
---
 fs/ext2/xattr.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
index 62d9a659a..dd8f10d 100644
--- a/fs/ext2/xattr.c
+++ b/fs/ext2/xattr.c
@@ -612,9 +612,9 @@ bad_block:		ext2_error(sb, "ext2_xattr_set",
 	}
 
 cleanup:
-	brelse(bh);
 	if (!(bh && header == HDR(bh)))
 		kfree(header);
+	brelse(bh);
 	up_write(&EXT2_I(inode)->xattr_sem);
 
 	return error;
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] ext2: fix potential use after free
  2018-11-25  0:58 [PATCH] ext2: fix potential use after free Pan Bian
@ 2018-11-27  9:19 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2018-11-27  9:19 UTC (permalink / raw)
  To: Pan Bian; +Cc: Jan Kara, linux-ext4, linux-kernel

On Sun 25-11-18 08:58:02, Pan Bian wrote:
> The function ext2_xattr_set calls brelse(bh) to drop the reference count
> of bh. After that, bh may be freed. However, following brelse(bh),
> it reads bh->b_data via macro HDR(bh). This may result in a
> use-after-free bug. This patch moves brelse(bh) after reading field.
> 
> Signed-off-by: Pan Bian <bianpan2016@163.com>

Thanks for the fix! I've added the patch to my tree.

								Honza

> ---
>  fs/ext2/xattr.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
> index 62d9a659a..dd8f10d 100644
> --- a/fs/ext2/xattr.c
> +++ b/fs/ext2/xattr.c
> @@ -612,9 +612,9 @@ bad_block:		ext2_error(sb, "ext2_xattr_set",
>  	}
>  
>  cleanup:
> -	brelse(bh);
>  	if (!(bh && header == HDR(bh)))
>  		kfree(header);
> +	brelse(bh);
>  	up_write(&EXT2_I(inode)->xattr_sem);
>  
>  	return error;
> -- 
> 2.7.4
> 
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-11-27  9:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-25  0:58 [PATCH] ext2: fix potential use after free Pan Bian
2018-11-27  9:19 ` 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).