All of lore.kernel.org
 help / color / mirror / Atom feed
* V3 minixfs bug
@ 2009-07-02 21:13 Doug Graham
  2009-07-02 21:27 ` Alan Cox
  0 siblings, 1 reply; 2+ messages in thread
From: Doug Graham @ 2009-07-02 21:13 UTC (permalink / raw)
  To: linux-kernel

Is anybody interested in bugs in the minixfs V3 support that probably
only turn up on big-endian machines, or on filesystems with more than
64K inodes?

The problem is that that there are a few places (three that I've found)
where the "inode" field of a minix_dir_entry is used without checking
first to see if the dirent is really a minix3_dir_entry.  The inode number
in a V1/V2 dirent is 16 bits, whereas that in a V3 dirent is 32 bits.  
Accessing
it as a 16 bit field when it really should be accessed as a 32 bit field
probably kinda sorta works on a little-endian machine, but leads to some
rather odd behaviour on big-endian machines.

Here's a patch:

--- linux-2.6.29.2/fs/minix/dir.c       2009/07/02 21:05:33     1.1
+++ linux-2.6.29.2/fs/minix/dir.c       2009/07/02 21:10:31
@@ -311,14 +311,18 @@
        struct inode *inode = (struct inode*)mapping->host;
        char *kaddr = page_address(page);
        loff_t pos = page_offset(page) + (char*)de - kaddr;
-       unsigned len = minix_sb(inode->i_sb)->s_dirsize;
+       struct minix_sb_info *sbi = minix_sb(inode->i_sb);
+       unsigned len = sbi->s_dirsize;
        int err;

        lock_page(page);
        err = __minix_write_begin(NULL, mapping, pos, len,
                                        AOP_FLAG_UNINTERRUPTIBLE, &page, 
NULL);
        if (err == 0) {
-               de->inode = 0;
+               if (sbi->s_version == MINIX_V3)
+                       ((minix3_dirent *) de)->inode = 0;
+               else
+                       de->inode = 0;
                err = dir_commit_chunk(page, pos, len);
        } else {
                unlock_page(page);
@@ -443,7 +447,10 @@
        err = __minix_write_begin(NULL, mapping, pos, sbi->s_dirsize,
                                        AOP_FLAG_UNINTERRUPTIBLE, &page, 
NULL);
        if (err == 0) {
-               de->inode = inode->i_ino;
+               if (sbi->s_version == MINIX_V3)
+                       ((minix3_dirent *) de)->inode = inode->i_ino;
+               else
+                       de->inode = inode->i_ino;
                err = dir_commit_chunk(page, pos, sbi->s_dirsize);
        } else {
                unlock_page(page);
@@ -473,7 +480,14 @@
        ino_t res = 0;

        if (de) {
-               res = de->inode;
+               struct address_space *mapping = page->mapping;
+               struct inode *inode = (struct inode*)mapping->host;
+               struct minix_sb_info *sbi = minix_sb(inode->i_sb);
+
+               if (sbi->s_version == MINIX_V3)
+                       res = ((minix3_dirent *) de)->inode;
+               else
+                       res = de->inode;
                dir_put_page(page);
        }
        return res;


--Doug


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

* Re: V3 minixfs bug
  2009-07-02 21:13 V3 minixfs bug Doug Graham
@ 2009-07-02 21:27 ` Alan Cox
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Cox @ 2009-07-02 21:27 UTC (permalink / raw)
  To: Doug Graham; +Cc: linux-kernel

On Thu, 02 Jul 2009 17:13:42 -0400
"Doug Graham" <dgraham@nortel.com> wrote:

> Is anybody interested in bugs in the minixfs V3 support that probably
> only turn up on big-endian machines, or on filesystems with more than
> 64K inodes?

If you've found them then yes.

> The problem is that that there are a few places (three that I've found)
> where the "inode" field of a minix_dir_entry is used without checking
> first to see if the dirent is really a minix3_dir_entry.  The inode number
> in a V1/V2 dirent is 16 bits, whereas that in a V3 dirent is 32 bits.  
> Accessing
> it as a 16 bit field when it really should be accessed as a 32 bit field
> probably kinda sorta works on a little-endian machine, but leads to some
> rather odd behaviour on big-endian machines.
> 
> Here's a patch:

The one thing this needs for application is a Signed-off-by: line (see
Documentation/SubmittingPatches). 

Alan

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

end of thread, other threads:[~2009-07-02 21:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-02 21:13 V3 minixfs bug Doug Graham
2009-07-02 21:27 ` Alan Cox

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.