* [PATCH v2] ext4: Fix rec_len verify error
@ 2023-07-31 1:01 zhangshida
2023-07-31 12:30 ` Zhang Yi
2023-07-31 15:41 ` Darrick J. Wong
0 siblings, 2 replies; 4+ messages in thread
From: zhangshida @ 2023-07-31 1:01 UTC (permalink / raw)
To: tytso, adilger.kernel; +Cc: linux-ext4, linux-kernel, zhangshida, starzhangzsd
From: Shida Zhang <zhangshida@kylinos.cn>
With the configuration PAGE_SIZE 64k and filesystem blocksize 64k,
a problem occurred when more than 13 million files were directly created
under a directory:
EXT4-fs error (device xx): ext4_dx_csum_set:492: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
EXT4-fs error (device xx): ext4_dx_csum_verify:463: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
EXT4-fs error (device xx): dx_probe:856: inode #xxxx: block 8188: comm xxxxx: Directory index failed checksum
When enough files are created, the fake_dirent->reclen will be 0xffff.
it doesn't equal to the blocksize 65536, i.e. 0x10000.
But it is not the same condition when blocksize equals to 4k.
when enough file are created, the fake_dirent->reclen will be 0x1000.
it equals to the blocksize 4k, i.e. 0x1000.
The problem seems to be related to the limitation of the 16-bit field
when the blocksize is set to 64k. To address this, Modify the check so
as to handle it properly.
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
v1->v2:
Use a better way to check the condition, as suggested by Andreas.
fs/ext4/namei.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 0caf6c730ce3..fffed95f8531 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -445,8 +445,9 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
struct ext4_dir_entry *dp;
struct dx_root_info *root;
int count_offset;
+ int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
- if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
+ if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == blocksize)
count_offset = 8;
else if (le16_to_cpu(dirent->rec_len) == 12) {
dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ext4: Fix rec_len verify error
2023-07-31 1:01 [PATCH v2] ext4: Fix rec_len verify error zhangshida
@ 2023-07-31 12:30 ` Zhang Yi
2023-07-31 15:41 ` Darrick J. Wong
1 sibling, 0 replies; 4+ messages in thread
From: Zhang Yi @ 2023-07-31 12:30 UTC (permalink / raw)
To: zhangshida, tytso, adilger.kernel; +Cc: linux-ext4, linux-kernel, zhangshida
On 2023/7/31 9:01, zhangshida wrote:
> From: Shida Zhang <zhangshida@kylinos.cn>
>
> With the configuration PAGE_SIZE 64k and filesystem blocksize 64k,
> a problem occurred when more than 13 million files were directly created
> under a directory:
>
> EXT4-fs error (device xx): ext4_dx_csum_set:492: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
> EXT4-fs error (device xx): ext4_dx_csum_verify:463: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
> EXT4-fs error (device xx): dx_probe:856: inode #xxxx: block 8188: comm xxxxx: Directory index failed checksum
>
> When enough files are created, the fake_dirent->reclen will be 0xffff.
> it doesn't equal to the blocksize 65536, i.e. 0x10000.
>
> But it is not the same condition when blocksize equals to 4k.
> when enough file are created, the fake_dirent->reclen will be 0x1000.
> it equals to the blocksize 4k, i.e. 0x1000.
>
> The problem seems to be related to the limitation of the 16-bit field
> when the blocksize is set to 64k. To address this, Modify the check so
> as to handle it properly.
>
Thanks for the patch. It works and looks good to me.
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
> Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> ---
> v1->v2:
> Use a better way to check the condition, as suggested by Andreas.
>
> fs/ext4/namei.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 0caf6c730ce3..fffed95f8531 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -445,8 +445,9 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
> struct ext4_dir_entry *dp;
> struct dx_root_info *root;
> int count_offset;
> + int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
>
> - if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
> + if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == blocksize)
> count_offset = 8;
> else if (le16_to_cpu(dirent->rec_len) == 12) {
> dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ext4: Fix rec_len verify error
2023-07-31 1:01 [PATCH v2] ext4: Fix rec_len verify error zhangshida
2023-07-31 12:30 ` Zhang Yi
@ 2023-07-31 15:41 ` Darrick J. Wong
2023-08-01 2:26 ` Stephen Zhang
1 sibling, 1 reply; 4+ messages in thread
From: Darrick J. Wong @ 2023-07-31 15:41 UTC (permalink / raw)
To: zhangshida; +Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, zhangshida
On Mon, Jul 31, 2023 at 09:01:04AM +0800, zhangshida wrote:
> From: Shida Zhang <zhangshida@kylinos.cn>
>
> With the configuration PAGE_SIZE 64k and filesystem blocksize 64k,
> a problem occurred when more than 13 million files were directly created
> under a directory:
>
> EXT4-fs error (device xx): ext4_dx_csum_set:492: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
> EXT4-fs error (device xx): ext4_dx_csum_verify:463: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
> EXT4-fs error (device xx): dx_probe:856: inode #xxxx: block 8188: comm xxxxx: Directory index failed checksum
>
> When enough files are created, the fake_dirent->reclen will be 0xffff.
> it doesn't equal to the blocksize 65536, i.e. 0x10000.
>
> But it is not the same condition when blocksize equals to 4k.
> when enough file are created, the fake_dirent->reclen will be 0x1000.
> it equals to the blocksize 4k, i.e. 0x1000.
>
> The problem seems to be related to the limitation of the 16-bit field
> when the blocksize is set to 64k. To address this, Modify the check so
> as to handle it properly.
urughghahrhrhr<shudder>
Sorry that I missed that rec_len is an encoded number, not a plain le16
integer...
> Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> ---
> v1->v2:
> Use a better way to check the condition, as suggested by Andreas.
>
> fs/ext4/namei.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> index 0caf6c730ce3..fffed95f8531 100644
> --- a/fs/ext4/namei.c
> +++ b/fs/ext4/namei.c
> @@ -445,8 +445,9 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
> struct ext4_dir_entry *dp;
> struct dx_root_info *root;
> int count_offset;
> + int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
>
> - if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
> + if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == blocksize)
> count_offset = 8;
> else if (le16_to_cpu(dirent->rec_len) == 12) {
...but what about all the other le16_to_cpu(ext4_dir_entry{,_2}.rec_len)
accesses in this file? Don't those also need to be converted to
ext4_rec_len_from_disk calls?
Also,
Fixes: dbe89444042ab ("ext4: Calculate and verify checksums for htree nodes")
--D
> dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
> --
> 2.27.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] ext4: Fix rec_len verify error
2023-07-31 15:41 ` Darrick J. Wong
@ 2023-08-01 2:26 ` Stephen Zhang
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Zhang @ 2023-08-01 2:26 UTC (permalink / raw)
To: Darrick J. Wong
Cc: tytso, adilger.kernel, linux-ext4, linux-kernel, zhangshida
Darrick J. Wong <djwong@kernel.org> 于2023年7月31日周一 23:41写道:
>
> On Mon, Jul 31, 2023 at 09:01:04AM +0800, zhangshida wrote:
> > From: Shida Zhang <zhangshida@kylinos.cn>
> >
> > With the configuration PAGE_SIZE 64k and filesystem blocksize 64k,
> > a problem occurred when more than 13 million files were directly created
> > under a directory:
> >
> > EXT4-fs error (device xx): ext4_dx_csum_set:492: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
> > EXT4-fs error (device xx): ext4_dx_csum_verify:463: inode #xxxx: comm xxxxx: dir seems corrupt? Run e2fsck -D.
> > EXT4-fs error (device xx): dx_probe:856: inode #xxxx: block 8188: comm xxxxx: Directory index failed checksum
> >
> > When enough files are created, the fake_dirent->reclen will be 0xffff.
> > it doesn't equal to the blocksize 65536, i.e. 0x10000.
> >
> > But it is not the same condition when blocksize equals to 4k.
> > when enough file are created, the fake_dirent->reclen will be 0x1000.
> > it equals to the blocksize 4k, i.e. 0x1000.
> >
> > The problem seems to be related to the limitation of the 16-bit field
> > when the blocksize is set to 64k. To address this, Modify the check so
> > as to handle it properly.
>
> urughghahrhrhr<shudder>
>
> Sorry that I missed that rec_len is an encoded number, not a plain le16
> integer...
>
Yep, that's really a point that is easy to forget...
> > Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> > ---
> > v1->v2:
> > Use a better way to check the condition, as suggested by Andreas.
> >
> > fs/ext4/namei.c | 3 ++-
> > 1 file changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> > index 0caf6c730ce3..fffed95f8531 100644
> > --- a/fs/ext4/namei.c
> > +++ b/fs/ext4/namei.c
> > @@ -445,8 +445,9 @@ static struct dx_countlimit *get_dx_countlimit(struct inode *inode,
> > struct ext4_dir_entry *dp;
> > struct dx_root_info *root;
> > int count_offset;
> > + int blocksize = EXT4_BLOCK_SIZE(inode->i_sb);
> >
> > - if (le16_to_cpu(dirent->rec_len) == EXT4_BLOCK_SIZE(inode->i_sb))
> > + if (ext4_rec_len_from_disk(dirent->rec_len, blocksize) == blocksize)
> > count_offset = 8;
> > else if (le16_to_cpu(dirent->rec_len) == 12) {
>
> ...but what about all the other le16_to_cpu(ext4_dir_entry{,_2}.rec_len)
> accesses in this file? Don't those also need to be converted to
> ext4_rec_len_from_disk calls?
>
> Also,
> Fixes: dbe89444042ab ("ext4: Calculate and verify checksums for htree nodes")
>
Thanks for your suggestion, I will try to add all the other conversion
in this file for the next v3.
Cheers,
Shida
> --D
>
> > dp = (struct ext4_dir_entry *)(((void *)dirent) + 12);
> > --
> > 2.27.0
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-01 2:27 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-31 1:01 [PATCH v2] ext4: Fix rec_len verify error zhangshida
2023-07-31 12:30 ` Zhang Yi
2023-07-31 15:41 ` Darrick J. Wong
2023-08-01 2:26 ` Stephen Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox