All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ext4: fix directory index node split corruption
@ 2021-07-30 18:24 Artem Blagodarenko
  2021-08-04 15:15 ` Jan Kara
  0 siblings, 1 reply; 2+ messages in thread
From: Artem Blagodarenko @ 2021-07-30 18:24 UTC (permalink / raw)
  To: linux-ext4; +Cc: adilger.kernel, Artem Blagodarenko, Denis Lukianov

I send patch whose author is Denis Lukianov <denis@voxelsoft.com>
His messages can't reach this list somehow.
I only rebased it ontop of master's HEAD and tested that it fixes
the problem and reviewed.

----

Following commit b5776e7, a trivial sequential write of empty files to
an empty ext4 file system (with large_dir enabled) fails after just
over 26 million files. Depending on luck, file creation will give error
EEXIST or EUCLEAN.

Commit b5776e7 fixed the no-restart condition so that
ext4_handle_dirty_dx_node is always called, but it also broke the
restart condition. This is because when restart=1, the original
implementation correctly skipped do_split() but b5776e7 clobbered the
"if(restart)goto journal_error;" logic.

This complementary change protects do_split() from restart condition,
making it safe from both current and future ordering of goto statements
in earlier sections of the code.

Tested on 5.11.20 with handy testing script:

i = 0
while i <= 32000000:
    print (i)
    with open('tmpmnt/%d' % i, 'wb') as fout:
        i += 1

Google-Bug-Id: 176345532
Fixes: b5776e7 ("ext4: fix potential htree index checksum corruption")
Signed-off-by: Denis Lukianov <denis@voxelsoft.com>
Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
---
 fs/ext4/namei.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 5fd56f616cf0..0bbff03d4167 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -2542,13 +2542,16 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
 			goto journal_error;
 		}
 	}
-	de = do_split(handle, dir, &bh, frame, &fname->hinfo);
-	if (IS_ERR(de)) {
-		err = PTR_ERR(de);
+	if (!restart) {
+		de = do_split(handle, dir, &bh, frame, &fname->hinfo);
+		if (IS_ERR(de)) {
+			err = PTR_ERR(de);
+			goto cleanup;
+		}
+		err = add_dirent_to_buf(handle, fname, dir, inode, de,
+bh);
 		goto cleanup;
 	}
-	err = add_dirent_to_buf(handle, fname, dir, inode, de, bh);
-	goto cleanup;
 
 journal_error:
 	ext4_std_error(dir->i_sb, err); /* this is a no-op if err == 0 */
-- 
2.18.4


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

* Re: [PATCH] ext4: fix directory index node split corruption
  2021-07-30 18:24 [PATCH] ext4: fix directory index node split corruption Artem Blagodarenko
@ 2021-08-04 15:15 ` Jan Kara
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2021-08-04 15:15 UTC (permalink / raw)
  To: Artem Blagodarenko; +Cc: linux-ext4, adilger.kernel, Denis Lukianov

On Fri 30-07-21 14:24:03, Artem Blagodarenko wrote:
> I send patch whose author is Denis Lukianov <denis@voxelsoft.com>
> His messages can't reach this list somehow.
> I only rebased it ontop of master's HEAD and tested that it fixes
> the problem and reviewed.
> 
> ----
> 
> Following commit b5776e7, a trivial sequential write of empty files to
> an empty ext4 file system (with large_dir enabled) fails after just
> over 26 million files. Depending on luck, file creation will give error
> EEXIST or EUCLEAN.
> 
> Commit b5776e7 fixed the no-restart condition so that
> ext4_handle_dirty_dx_node is always called, but it also broke the
> restart condition. This is because when restart=1, the original
> implementation correctly skipped do_split() but b5776e7 clobbered the
> "if(restart)goto journal_error;" logic.
> 
> This complementary change protects do_split() from restart condition,
> making it safe from both current and future ordering of goto statements
> in earlier sections of the code.
> 
> Tested on 5.11.20 with handy testing script:
> 
> i = 0
> while i <= 32000000:
>     print (i)
>     with open('tmpmnt/%d' % i, 'wb') as fout:
>         i += 1
> 
> Google-Bug-Id: 176345532
> Fixes: b5776e7 ("ext4: fix potential htree index checksum corruption")

Please use 12 characters from git commit when identifying it (7 characters 
is likely to become non-unique). Otherwise the fix looks good so feel free
to add:

Reviewed-by: Jan Kara <jack@suse.cz>

Also I think you should include Ted in 'To' or 'CC' to make it more likely
he sees the patch.

								Honza


> Signed-off-by: Denis Lukianov <denis@voxelsoft.com>
> Signed-off-by: Artem Blagodarenko <artem.blagodarenko@gmail.com>
> ---
>  fs/ext4/namei.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 5fd56f616cf0..0bbff03d4167 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -2542,13 +2542,16 @@ static int ext4_dx_add_entry(handle_t *handle, struct ext4_filename *fname,
>  			goto journal_error;
>  		}
>  	}
> -	de = do_split(handle, dir, &bh, frame, &fname->hinfo);
> -	if (IS_ERR(de)) {
> -		err = PTR_ERR(de);
> +	if (!restart) {
> +		de = do_split(handle, dir, &bh, frame, &fname->hinfo);
> +		if (IS_ERR(de)) {
> +			err = PTR_ERR(de);
> +			goto cleanup;
> +		}
> +		err = add_dirent_to_buf(handle, fname, dir, inode, de,
> +bh);
>  		goto cleanup;
>  	}
> -	err = add_dirent_to_buf(handle, fname, dir, inode, de, bh);
> -	goto cleanup;
>  
>  journal_error:
>  	ext4_std_error(dir->i_sb, err); /* this is a no-op if err == 0 */
> -- 
> 2.18.4
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

end of thread, other threads:[~2021-08-04 15:15 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 18:24 [PATCH] ext4: fix directory index node split corruption Artem Blagodarenko
2021-08-04 15:15 ` Jan Kara

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.