* ext4: avoid drop reference to iloc.bh twice
@ 2019-04-18 8:31 Pan Bian
2019-04-18 12:35 ` Jan Kara
0 siblings, 1 reply; 3+ messages in thread
From: Pan Bian @ 2019-04-18 8:31 UTC (permalink / raw)
To: Theodore Ts'o, Andreas Dilger; +Cc: linux-ext4, linux-kernel, Pan Bian
The reference to iloc.bh has been dropped in ext4_mark_iloc_dirty.
However, the reference is dropped again if error occurs during
ext4_handle_dirty_metadata, which may result in use-after-free bugs.
Fixes: fb265c9cb49e("ext4: add ext4_sb_bread() to disambiguate ENOMEM
cases")
Signed-off-by: Pan Bian <bianpan2016@163.com>
---
fs/ext4/resize.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index e7ae26e..4d5c0fc 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -874,6 +874,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh);
if (unlikely(err)) {
ext4_std_error(sb, err);
+ iloc.bh = NULL;
goto errout;
}
brelse(dind);
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: ext4: avoid drop reference to iloc.bh twice
2019-04-18 8:31 ext4: avoid drop reference to iloc.bh twice Pan Bian
@ 2019-04-18 12:35 ` Jan Kara
2019-04-25 15:48 ` Theodore Ts'o
0 siblings, 1 reply; 3+ messages in thread
From: Jan Kara @ 2019-04-18 12:35 UTC (permalink / raw)
To: Pan Bian; +Cc: Theodore Ts'o, Andreas Dilger, linux-ext4, linux-kernel
On Thu 18-04-19 16:31:18, Pan Bian wrote:
> The reference to iloc.bh has been dropped in ext4_mark_iloc_dirty.
> However, the reference is dropped again if error occurs during
> ext4_handle_dirty_metadata, which may result in use-after-free bugs.
>
> Fixes: fb265c9cb49e("ext4: add ext4_sb_bread() to disambiguate ENOMEM
> cases")
>
> Signed-off-by: Pan Bian <bianpan2016@163.com>
Thanks for the patch! Good spotting. You can add:
Reviewed-by: Jan Kara <jack@suse.cz>
I'm just wondering: Ted, shouldn't we make ext4_mark_iloc_dirty() clear the
iloc.bh pointer on it's own? I believe this is not the first time we had a
bug like this and it would also catch possible use-after-free issues in
case someone tried to use iloc.bh after the reference has been dropped.
Generally the scheme around ext4_get_inode_loc() and
ext4_mark_iloc_dirty() seems to be somewhat error prone. E.g. a quick audit
shows that there's bh leak in ext4_orphan_del() in one of the error paths.
I'll send patches.
Honza
> ---
> fs/ext4/resize.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
> index e7ae26e..4d5c0fc 100644
> --- a/fs/ext4/resize.c
> +++ b/fs/ext4/resize.c
> @@ -874,6 +874,7 @@ static int add_new_gdb(handle_t *handle, struct inode *inode,
> err = ext4_handle_dirty_metadata(handle, NULL, gdb_bh);
> if (unlikely(err)) {
> ext4_std_error(sb, err);
> + iloc.bh = NULL;
> goto errout;
> }
> brelse(dind);
> --
> 2.7.4
>
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ext4: avoid drop reference to iloc.bh twice
2019-04-18 12:35 ` Jan Kara
@ 2019-04-25 15:48 ` Theodore Ts'o
0 siblings, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2019-04-25 15:48 UTC (permalink / raw)
To: Jan Kara; +Cc: Pan Bian, Andreas Dilger, linux-ext4, linux-kernel
On Thu, Apr 18, 2019 at 02:35:19PM +0200, Jan Kara wrote:
> On Thu 18-04-19 16:31:18, Pan Bian wrote:
> > The reference to iloc.bh has been dropped in ext4_mark_iloc_dirty.
> > However, the reference is dropped again if error occurs during
> > ext4_handle_dirty_metadata, which may result in use-after-free bugs.
> >
> > Fixes: fb265c9cb49e("ext4: add ext4_sb_bread() to disambiguate ENOMEM
> > cases")
> >
> > Signed-off-by: Pan Bian <bianpan2016@163.com>
>
> Thanks for the patch! Good spotting. You can add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
Applied, thanks.
> I'm just wondering: Ted, shouldn't we make ext4_mark_iloc_dirty() clear the
> iloc.bh pointer on it's own? I believe this is not the first time we had a
> bug like this and it would also catch possible use-after-free issues in
> case someone tried to use iloc.bh after the reference has been dropped.
>
> Generally the scheme around ext4_get_inode_loc() and
> ext4_mark_iloc_dirty() seems to be somewhat error prone. E.g. a quick audit
> shows that there's bh leak in ext4_orphan_del() in one of the error paths.
> I'll send patches.
Good suggestion!
I agree, the interface is error-prone. Clearing inode.bh afterwards
makes sense.
After we do this, we should also scan the call sites, since there are
some places where we have been calling get_bh(iloc.bh) before-hand, so
that the brelse(iloc.bh) in the cleanup path will work. Other call
paths add iloc.bh = NULL afterwards so that the brelse() will work
correctly. So we'll be able to clean up all of this afterwards.
- Ted
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-25 15:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-18 8:31 ext4: avoid drop reference to iloc.bh twice Pan Bian
2019-04-18 12:35 ` Jan Kara
2019-04-25 15:48 ` Theodore Ts'o
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.