• OGAWA Hirofumi's avatar
    fat: fix VFAT compat ioctls on 64-bit systems · c483bab0
    OGAWA Hirofumi authored
    If you compile and run the below test case in an msdos or vfat directory on
    an x86-64 system with -m32 you'll get garbage in the kernel_dirent struct
    followed by a SIGSEGV.
    
    The patch fixes this.
    
    Reported and initial fix by Bart Oldeman
    
    #include <sys/types.h>
    #include <sys/ioctl.h>
    #include <dirent.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <fcntl.h>
    struct kernel_dirent {
             long            d_ino;
             long		d_off;
             unsigned short  d_reclen;
             char            d_name[256]; /* We must not include limits.h! */
    };
    #define VFAT_IOCTL_READDIR_BOTH  _IOR('r', 1, struct kernel_dirent [2])
    #define VFAT_IOCTL_READDIR_SHORT  _IOR('r', 2, struct kernel_dirent [2])
    
    int main(void)
    {
             int fd = open(".", O_RDONLY);
             struct kernel_dirent de[2];
    
             while (1) {
                     int i = ioctl(fd, VFAT_IOCTL_READDIR_BOTH, (long)de);
                     if (i == -1) break;
                     if (de[0].d_reclen == 0) break;
                     printf("SFN: reclen=%2d off=%d ino=%d, %-12s",
     		       de[0].d_reclen, de[0].d_off, de[0].d_ino, de[0].d_name);
     		if (de[1].d_reclen)
     		  printf("\tLFN: reclen=%2d off=%d ino=%d, %s",
     		    de[1].d_reclen, de[1].d_off, de[1].d_ino, de[1].d_name);
     		printf("\n");
             }
             return 0;
    }
    Signed-off-by: default avatarBart Oldeman <bartoldeman@users.sourceforge.net>
    Signed-off-by: default avatarOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
    Cc: <stable@kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    c483bab0
dir.c 32.8 KB