2018-10-31 19:29:32

by Vasily Averin

[permalink] [raw]
Subject: [PATCH 1/7] ext4: lost brelse in __ext4_read_dirblock()

Fixes dc6982ff4db1 ("ext4: refactor code to read directory blocks ...") # 3.9

Signed-off-by: Vasily Averin <[email protected]>
---
fs/ext4/namei.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index d388cce72db2..1a21e59ede72 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -111,6 +111,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
if (!bh) {
ext4_error_inode(inode, func, line, block,
"Directory hole found");
+ brelse(bh);
return ERR_PTR(-EFSCORRUPTED);
}
dirent = (struct ext4_dir_entry *) bh->b_data;
--
2.17.1



2018-11-07 15:26:37

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH 1/7] ext4: lost brelse in __ext4_read_dirblock()

On Wed, Oct 31, 2018 at 10:12:18PM +0300, Vasily Averin wrote:
> Fixes dc6982ff4db1 ("ext4: refactor code to read directory blocks ...") # 3.9
>
> Signed-off-by: Vasily Averin <[email protected]>
> ---
> fs/ext4/namei.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index d388cce72db2..1a21e59ede72 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -111,6 +111,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
> if (!bh) {
> ext4_error_inode(inode, func, line, block,
> "Directory hole found");
> + brelse(bh);
> return ERR_PTR(-EFSCORRUPTED);
> }
> dirent = (struct ext4_dir_entry *) bh->b_data;

Inside the conditional, bh == NULL, so the brelse isn't needed.

Cheers,

- Ted

2018-11-07 17:19:56

by Vasily Averin

[permalink] [raw]
Subject: Re: [PATCH 1/7] ext4: lost brelse in __ext4_read_dirblock()

I was wrong here, but brelse is lost in next error in this function.
I'll resend new patch.

On 11/7/18 6:25 PM, Theodore Y. Ts'o wrote:
> On Wed, Oct 31, 2018 at 10:12:18PM +0300, Vasily Averin wrote:
>> Fixes dc6982ff4db1 ("ext4: refactor code to read directory blocks ...") # 3.9
>>
>> Signed-off-by: Vasily Averin <[email protected]>
>> ---
>> fs/ext4/namei.c | 1 +
>> 1 file changed, 1 insertion(+)
>>
>> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
>> index d388cce72db2..1a21e59ede72 100644
>> --- a/fs/ext4/namei.c
>> +++ b/fs/ext4/namei.c
>> @@ -111,6 +111,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
>> if (!bh) {
>> ext4_error_inode(inode, func, line, block,
>> "Directory hole found");
>> + brelse(bh);
>> return ERR_PTR(-EFSCORRUPTED);
>> }
>> dirent = (struct ext4_dir_entry *) bh->b_data;
>
> Inside the conditional, bh == NULL, so the brelse isn't needed.
>
> Cheers,
>
> - Ted
>

2018-11-07 17:31:42

by Vasily Averin

[permalink] [raw]
Subject: [PATCH v2] ext4: lost brelse in __ext4_read_dirblock()

Fixes dc6982ff4db1 ("ext4: refactor code to read directory blocks ...")
Cc: [email protected] # 3.9

Signed-off-by: Vasily Averin <[email protected]>
---
fs/ext4/namei.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index d388cce72db2..6a6b90363ef1 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -126,6 +126,7 @@ static struct buffer_head *__ext4_read_dirblock(struct inode *inode,
if (!is_dx_block && type == INDEX) {
ext4_error_inode(inode, func, line, block,
"directory leaf block found instead of index block");
+ brelse(bh);
return ERR_PTR(-EFSCORRUPTED);
}
if (!ext4_has_metadata_csum(inode->i_sb) ||
--
2.17.1


2018-11-08 03:39:08

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH v2] ext4: lost brelse in __ext4_read_dirblock()

On Wed, Nov 07, 2018 at 08:30:17PM +0300, Vasily Averin wrote:
> Fixes dc6982ff4db1 ("ext4: refactor code to read directory blocks ...")
> Cc: [email protected] # 3.9
>
> Signed-off-by: Vasily Averin <[email protected]>

Thanks, applied. I used the commit description:

ext4: fix buffer leak in __ext4_read_dirblock() on error path

- Ted