2009-02-10 22:58:20

by Andrew Morton

[permalink] [raw]
Subject: + ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems.patch added to -mm tree


The patch titled
ext2: fix support for empty directory blocks in 64k blocksize filesystems
has been added to the -mm tree. Its filename is
ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a
reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

See http://userweb.kernel.org/~akpm/stuff/added-to-mm.txt to find
out what to do about this

The current -mm tree may be found at http://userweb.kernel.org/~akpm/mmotm/

------------------------------------------------------
Subject: ext2: fix support for empty directory blocks in 64k blocksize filesystems
From: Wei Yongjun <[email protected]>

The rec_len field in the directory entry is 16 bits, so if the filesystem
is completely empty, rec_len of 0 is used to designate 65536 in e2fsprogs,
for the case where the directory entry takes the entire 64k block.

But if an empty directory is read, an error message will be output by
current kernels. You can use the following commands to reproduce it.

- mkfs.ext2 -b $(( 64 * 1024 )) /dev/sdc1
- mount /dev/sda1 /mnt
- cd /mnt/lost+found
- ll
- tail /var/log/messages
EXT2-fs error (device sdc1): ext2_check_page: bad entry in \
directory #11: : rec_len is smaller than minimal - offset=65536, \
inode=0, rec_len=0, name_len=0
EXT2-fs error (device sdc1): ext2_readdir: bad page in #11

Treat a rec_len of 0 as 65536, as e2fsprogs does.

Signed-off-by: Wei Yongjun <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
---

fs/ext2/dir.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff -puN fs/ext2/dir.c~ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems fs/ext2/dir.c
--- a/fs/ext2/dir.c~ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems
+++ a/fs/ext2/dir.c
@@ -33,7 +33,7 @@ static inline unsigned ext2_rec_len_from
{
unsigned len = le16_to_cpu(dlen);

- if (len == EXT2_MAX_REC_LEN)
+ if (len == EXT2_MAX_REC_LEN || len == 0)
return 1 << 16;
return len;
}
@@ -41,7 +41,7 @@ static inline unsigned ext2_rec_len_from
static inline __le16 ext2_rec_len_to_disk(unsigned len)
{
if (len == (1 << 16))
- return cpu_to_le16(EXT2_MAX_REC_LEN);
+ return cpu_to_le16(0);
else
BUG_ON(len > (1 << 16));
return cpu_to_le16(len);
_

Patches currently in -mm which might be from [email protected] are

linux-next.patch
fs-jffs2-mallocc-kmem_cache_alloc-memset-kmem_cache_zalloc.patch
scsi-used-kmem_cache_zalloc-instead-of-kmem_cache_alloc-memset.patch
ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems.patch
ext3-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems.patch



2009-02-11 15:16:18

by Theodore Ts'o

[permalink] [raw]
Subject: Re: + ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesys tems.patch added to -mm tree

On Tue, Feb 10, 2009 at 02:57:58PM -0800, [email protected] wrote:
>
> The patch titled
> ext2: fix support for empty directory blocks in 64k blocksize filesystems
> has been added to the -mm tree. Its filename is
> ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems.patch

NACK. The commit description is incomplete, we need to discuss more
what's the best way of handling this. See the discussion around the
ext4 patch on linux-ext4 for more details.

This patch is entirely moot for ext2 in any case, since
EXT2_MAX_BLOCK_SIZE was never changed from 4096.

- Ted

2009-02-12 06:28:12

by Wei Yongjun

[permalink] [raw]
Subject: Re: + ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesys tems.patch added to -mm tree

Theodore Tso wrote:
> On Tue, Feb 10, 2009 at 02:57:58PM -0800, [email protected] wrote:
>
>> The patch titled
>> ext2: fix support for empty directory blocks in 64k blocksize filesystems
>> has been added to the -mm tree. Its filename is
>> ext2-fix-support-for-empty-directory-blocks-in-64k-blocksize-filesystems.patch
>>
>
> NACK. The commit description is incomplete, we need to discuss more
> what's the best way of handling this. See the discussion around the
> ext4 patch on linux-ext4 for more details.
>
> This patch is entirely moot for ext2 in any case, since
> EXT2_MAX_BLOCK_SIZE was never changed from 4096.
>

Hi, Ted

If you are right, I think this patch is necessary.

[PATCH] ext2: Fix to check unsupported filesystem blocksize

EXT2-fs defined that the max blocksize is:
#define EXT2_MAX_BLOCK_SIZE 4960
and the min blocksize is:
#define EXT2_MIN_BLOCK_SIZE 1024

But never check this in ext2_fill_super(). So mount will
always success even if the block size is larger than 4096.

This patch fixed the problem.

Signed-off-by: Wei Yongjun <[email protected]>
---
fs/ext2/super.c | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/fs/ext2/super.c b/fs/ext2/super.c
index da8bdea..36cdfd6 100644
--- a/fs/ext2/super.c
+++ b/fs/ext2/super.c
@@ -873,6 +873,14 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)

blocksize = BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);

+ if (blocksize < EXT2_MIN_BLOCK_SIZE ||
+ blocksize > EXT2_MAX_BLOCK_SIZE) {
+ printk(KERN_ERR
+ "EXT2-fs: Unsupported filesystem blocksize %d on %s.\n",
+ blocksize, sb->s_id);
+ goto failed_mount;
+ }
+
if (ext2_use_xip(sb) && blocksize != PAGE_SIZE) {
if (!silent)
printk("XIP: Unsupported blocksize\n");
--
1.5.3.8