linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Filz <ffilzlnx@us.ibm.com>
To: NFS List <linux-nfs@vger.kernel.org>
Cc: ffilz@us.ibm.com
Subject: [PATCH] NFS client has troubles with fileid with bit 31 (or bit 63) set
Date: Wed, 01 Dec 2010 17:03:06 -0800	[thread overview]
Message-ID: <1291251786.5075.6.camel@KPMH461.ibm.com> (raw)




I discovered this problem by accident while doing some testing of the
Ganesha user space server. It was producing garbage fileids that
happened to have bit 31 set (0x80000000).

The telldir special test from cthon04 would fail. Investigating, I found
that it appeared that the getdents() was returning EOVERFLOW. It wasn't
too hard to track that down to the following code:

static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset,
                      u64 ino, unsigned int d_type)
{
        struct readdir_callback * buf = (struct readdir_callback *) __buf;
        struct old_linux_dirent __user * dirent;
        unsigned long d_ino;

        if (buf->result)
                return -EINVAL;
        d_ino = ino;
        if (sizeof(d_ino) < sizeof(ino) && d_ino != ino)
                return -EOVERFLOW;

It took adding some debug code to track the problem down to this
function:

u64 nfs_compat_user_ino64(u64 fileid)
{
        int ino;

        if (enable_ino64)
                return fileid;
        ino = fileid;
        if (sizeof(ino) < sizeof(fileid))
                ino ^= fileid >> (sizeof(fileid)-sizeof(ino)) * 8;
        return ino;
}

In trying to reduce a 64 bit fileid to 32 bits, it produces a SIGNED 32
bit int! When this is passed to fillonedir as a uint64, a negative
number is sign extended. bit 31 of ino will be set if bit 31 OR bit 63
(but not both) is set in the fileid.

Turns out the fix is simple! Change ino to an unsigned int.

In order to test my fix in an orderly fashion, I used a simple process
to modify the fileids produced by the kernel server:

u64 warp_fileid(u64 fileid)
{
        return (fileid & 0xffffffff7fffffefLL) | ((fileid & 0x10LL) << 27) | ((fileid &0x80000000LL) >> 27);
}

This means that every 16 inode numbers, bit 31 will be flipped,
producing plenty of problem fileids. The telldir test case fails with
this hacked kernel server.

Of course if anyone has a real file system with > 2G inodes, they could
see the problem for real, but I don't have a big enough file system...





Signed-off-by: Frank Filz <ffilzlnx@us.ibm.com>
---
diff -X ignore.patcher -ruNp linux-2.6.18-194.el5/fs/nfs/inode.c linux-2.6.18-194.ff/fs/nfs/inode.c
--- linux-2.6.18-194.el5/fs/nfs/inode.c	2010-12-01 15:52:11.000000000 -0800
+++ linux-2.6.18-194.ff/fs/nfs/inode.c	2010-12-01 16:53:28.000000000 -0800
@@ -71,7 +71,7 @@ static kmem_cache_t * nfs_inode_cachep;
  */
 u64 nfs_compat_user_ino64(u64 fileid)
 {
-	int ino;
+	unsigned int ino;
 
 	if (enable_ino64)
 		return fileid;



             reply	other threads:[~2010-12-02  1:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-02  1:03 Frank Filz [this message]
2010-12-02  1:36 ` [PATCH] NFS client has troubles with fileid with bit 31 (or bit 63) set Trond Myklebust
2010-12-02  3:01   ` Frank Filz
2010-12-02  3:13     ` Trond Myklebust
2010-12-02 17:44       ` Frank Filz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1291251786.5075.6.camel@KPMH461.ibm.com \
    --to=ffilzlnx@us.ibm.com \
    --cc=ffilz@us.ibm.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).