]> git.karo-electronics.de Git - karo-tx-linux.git/commit
[PATCH] fat: fix VFAT compat ioctls on 64-bit systems
authorOGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Tue, 8 May 2007 07:31:28 +0000 (00:31 -0700)
committerChris Wright <chrisw@sous-sol.org>
Wed, 23 May 2007 21:32:46 +0000 (14:32 -0700)
commit041f08ecb28db5be31e6de339c7abb3fe369ec53
tree60e51330f762248b784ec69f5538a481c8d3f6b2
parentcfc00cc62c33b8a46df9eb3228e142e3f9535711
[PATCH] fat: fix VFAT compat ioctls on 64-bit systems

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: Bart Oldeman <bartoldeman@users.sourceforge.net>
Signed-off-by: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chris Wright <chrisw@sous-sol.org>
fs/fat/dir.c