NFS files still accessible from original pathname after being renamed

Solution Verified - Updated -

Issue

  • Directory entries are still accessible via access() and stat() even after they have been renamed.
  • Test program:
int
main(int argc, char **argv)
{
    int rc = 0;
    char *fname1;
    char *fname2;

    if (argc != 3) {
        printf("Usage: %s <file1> <file2>\n", argv[0]);
        exit(1);
    }

    fname1 = argv[1];
    fname2 = argv[2];

    rc = mkdir(fname1, 0666);
    if (rc < 0) {
        perror("mkdir(fname1)");
        exit(1);
    }

    rc = mkdir(fname2, 0666);
    if (rc < 0) {
        perror("mkdir(fname2)");
        exit(1);
    }

    rc = rename(fname1, fname2);
    if (rc < 0) {
        perror("rename");
        exit(1);
    }

    rc = access(fname1, F_OK);
    if (rc < 0) {
        printf("success\n");
        exit(1);
    }

    printf("file %s exists!\n", fname1);

    return 0;
}

The test passes when the source and target directories have less than 32 characters and reproduces the bug if either source or target has 32 or more characters.

# gcc -Wall -o nfs_test nfs_test.c
# mount localhost:/mnt/test /mnt/nfs
# cd /mnt/nfs
# ~/nfs_test a 0123456789012345678901234567890
success
# ~/nfs_test a 01234567890123456789012345678901
file a exists!
# stat a
  File: `a'
  Size: 4096        Blocks: 8          IO Block: 131072 directory
Device: 20h/32d Inode: 315028      Links: 1
Access: (0644/drw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2014-03-25 14:52:01.858764868 +1100
Modify: 2014-03-25 14:52:01.858764868 +1100
Change: 2014-03-25 14:52:01.858764868 +1100
# cat a
cat: a: No such file or directory
  • File 'a' should not exist.

Environment

  • Red Hat Enterprise Linux 6
    • kernel prior to kernel-2.6.32-696.el6
    • Reproduced on 2.6.32-358.23.2.el6
  • NFS v3 and v4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.