Skip to contentSkip to conversation

Bug fix for ext2.c

PATCH In review Bean 4 participants 11 messages Mar 14, 2009 – Mar 21, 2009 VFS

lore
Share & tools
lore

Bean

author
#0 lore raw

PATCH 1/1 Bug fix for ext2.c

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

Signature · 1 line
Bean
fs/ext2.c +6 -6
index ac0757e..aad1384 100644
@@ -548,17 +548,14 @@ grub_ext2_mount (grub_disk_t disk)
 
   /* Make sure this is an ext2 filesystem.  */
   if (grub_le_to_cpu16 (data->sblock.magic) != EXT2_MAGIC)
-    {
-      grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem");
-      goto fail;
-    }
+    goto fail;
   
   /* Check the FS doesn't have feature bits enabled that we don't support. */
   if (grub_le_to_cpu32 (data->sblock.feature_incompat)
         & ~(EXT2_DRIVER_SUPPORTED_INCOMPAT | EXT2_DRIVER_IGNORED_INCOMPAT))
     {
       grub_error (GRUB_ERR_BAD_FS, "filesystem has unsupported incompatible features");
-      goto fail;
+      goto fail_1;
     }
     
   
@@ -576,7 +573,10 @@ grub_ext2_mount (grub_disk_t disk)
   
   return data;
 
- fail:
+fail:
+  grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem");
+ 
+fail_1:
   grub_free (data);
   return 0;
 }
#1 lore raw
Quoted 7 lines · Bean

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

I think current behaviour is correct. If a failure is triggered by grub_disk_read(), from grub_fs_probe perspective it means something is fucked up other than just "this is not the FS we're looking for", so it should be aware of the difference.

Or is grub_ext2_read_inode() failure the one that's causing trouble for you?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#2 lore raw
Quoted 9 lines · Robert Millan
Quoted 7 lines · Bean

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

Quoted 7 lines

I think current behaviour is correct.  If a failure is triggered by grub_disk_read(), from grub_fs_probe perspective it means something is fucked up other than just "this is not the FS we're looking for", so it should be aware of the difference.

Or is grub_ext2_read_inode() failure the one that's causing trouble for you?

Hi,

ext2 only reads the first two sectors in mount, which is normally ok , but there are exceptions. For example, cpio filesystem could be less one sector. Also, hostfs always return error in its read function, which would cause ext2 to fail. The effect can be seen in grub-fstest. hostfs is the first fs driver to register, and the last to query. When accessing the (host) device, ext2 cause it to fail before hostfs has a chance to see it.

Signature · 1 line
Bean
#3 lore raw
Quoted 15 lines · Bean
Quoted 14 lines · Robert Millan
Quoted 7 lines · Bean

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

I think current behaviour is correct.  If a failure is triggered by grub_disk_read(), from grub_fs_probe perspective it means something is fucked up other than just "this is not the FS we're looking for", so it should be aware of the difference.

Quoted 8 lines
Quoted 2 lines

Or is grub_ext2_read_inode() failure the one that's causing trouble for you?

Hi,

ext2 only reads the first two sectors in mount, which is normally ok , but there are exceptions. For example, cpio filesystem could be less one sector.

I don't understand what you mean here. If grub_disk_read failed, this indicates something's broken down in the disk layer doesn't it? How is the number of sectors related to this?

Quoted 5 lines

Also, hostfs always return error in its read function, which would cause ext2 to fail. The effect can be seen in grub-fstest. hostfs is the first fs driver to register, and the last to query. When accessing the (host) device, ext2 cause it to fail before hostfs has a chance to see it.

Why does hostfs fail? Is this intentional?

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#4 lore raw
Quoted 21 lines · Robert Millan
Quoted 20 lines · Bean
Quoted 9 lines · Robert Millan
Quoted 7 lines · Bean

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

Quoted 7 lines

I think current behaviour is correct.  If a failure is triggered by grub_disk_read(), from grub_fs_probe perspective it means something is fucked up other than just "this is not the FS we're looking for", so it should be aware of the difference.

Or is grub_ext2_read_inode() failure the one that's causing trouble for you?

Hi,

Quoted 8 lines
Quoted 3 lines

ext2 only reads the first two sectors in mount, which is normally ok , but there are exceptions. For example, cpio filesystem could be less one sector.

I don't understand what you mean here.  If grub_disk_read failed, this indicates something's broken down in the disk layer doesn't it?  How is the number of sectors related to this?

Hi,

grub_disk_read checks for disk limit. For example, cpio file system can be one sector long, trying to read two sectors would cause a out of range error.

Quoted 7 lines
Quoted 5 lines

Also, hostfs always return error in its read function, which would cause ext2 to fail. The effect can be seen in grub-fstest. hostfs is the first fs driver to register, and the last to query. When accessing the (host) device, ext2 cause it to fail before hostfs has a chance to see it.

Why does hostfs fail?  Is this intentional?

Yes, it's intentional. Reading raw sectors from (host) doesn't make much sense. The (host) device is a place holder for hostfs filesystem.

Signature · 1 line
Bean
#5 lore raw
In reply to Bean
Quoted 7 lines · On Sunday 15 March 2009 01:16:23 Bean wrote:

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

This patch ignores any kind of failure. That's a problem. If you only convert GRUB_ERR_OUT_OF_RANGE to GRUB_ERR_BAD_FS, I agree.

Regards,
Okuji

author
#6 lore raw
Quoted 11 lines · Yoshinori K. Okuji
Quoted 7 lines · On Sunday 15 March 2009 01:16:23 Bean wrote:

Hi,

I've discovered a bug in ext2.c, inside grub_ext2_mount. The mount function must return GRUB_ERR_BAD_FS if something goes wrong, because grub_fs_probe would stop as soon as it sees a non-GRUB_ERR_BAD_FS error, thus preventing other fs driver from detecting the correct fs type. This patch fixes the problem.

This patch ignores any kind of failure. That's a problem. If you only convert GRUB_ERR_OUT_OF_RANGE to GRUB_ERR_BAD_FS, I agree.

Hi,

Oh right, this one should be ok.

Signature · 1 line
Bean
fs/ext2.c +3 -0
index ac0757e..1c29885 100644
@@ -577,6 +577,9 @@ grub_ext2_mount (grub_disk_t disk)
   return data;
 
  fail:
+  if (grub_errno == GRUB_ERR_OUT_OF_RANGE)
+    grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem");
+
   grub_free (data);
   return 0;
 }
#7 lore raw

Am Sonntag, den 15.03.2009, 14:00 +0800 schrieb Bean:

Quoted 1 line

Hi,

Hi Bean,

Quoted 1 line

Oh right, this one should be ok.

+ grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem");
This should probable be `not an ext2 filesystem' :)

Signature · 1 line
Felix Zielcke
#8 lore raw
Quoted 10 lines · Felix Zielcke

Am Sonntag, den 15.03.2009, 14:00 +0800 schrieb Bean:

Quoted 1 line

Hi,

Hi Bean,

Quoted 1 line

Oh right, this one should be ok.

+ grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem");
This should probable be `not an ext2 filesystem' :)

Why override grub_errmsg anyway? "not ext2" isn't going to be more useful than a "read out of range" text when displayed to the user.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."
author
#9 lore raw
Quoted 7 lines · Robert Millan
Quoted 6 lines · Felix Zielcke

Am Sonntag, den 15.03.2009, 14:00 +0800 schrieb Bean:

Quoted 1 line

Hi,

Hi Bean,

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Oh right, this one should be ok.

+    grub_error (GRUB_ERR_BAD_FS, "not an xfs filesystem"); This should probable be `not an ext2 filesystem' :)

Why override grub_errmsg anyway?  "not ext2" isn't going to be more useful than a "read out of range" text when displayed to the user.

Hi,

I think the ext2 error message is better. The "read out of range" error is such a general message, it tells us little about where it goes wrong, while with "not ext2 filesystem",. we know that the error is generated in grub_ext2_mount.

Although, a more informative way is to write it like this:

if (grub_errno == GRUB_ERR_OUT_OF_RANGE)

    grub_error (GRUB_ERR_BAD_FS, "not an ext2 filesystem (out of range)");

But that seems a little overdo for me. Besides, fs drivers such as xfs.c, hfsplus.c use simple message for out of range error.

Signature · 1 line
Bean
author
#10 lore raw

Committed.

Signature · 1 line
Bean