Commit 7c2c01bd authored by Linus Torvalds's avatar Linus Torvalds Committed by Linus Torvalds

Fix getdents64() offset saving bug from -mm merge.

Make old 32-bit getdents() look more like the updated
getdents64 for maintainability.
parent d618d88d
...@@ -134,13 +134,13 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset, ...@@ -134,13 +134,13 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
return -EINVAL; return -EINVAL;
dirent = buf->previous; dirent = buf->previous;
if (dirent) if (dirent)
put_user(offset, &dirent->d_off); __put_user(offset, &dirent->d_off);
dirent = buf->current_dir; dirent = buf->current_dir;
buf->previous = dirent; buf->previous = dirent;
put_user(ino, &dirent->d_ino); __put_user(ino, &dirent->d_ino);
put_user(reclen, &dirent->d_reclen); __put_user(reclen, &dirent->d_reclen);
copy_to_user(dirent->d_name, name, namlen); copy_to_user(dirent->d_name, name, namlen);
put_user(0, dirent->d_name + namlen); __put_user(0, dirent->d_name + namlen);
((char *) dirent) += reclen; ((char *) dirent) += reclen;
buf->current_dir = dirent; buf->current_dir = dirent;
buf->count -= reclen; buf->count -= reclen;
...@@ -154,6 +154,10 @@ asmlinkage long sys_getdents(unsigned int fd, void * dirent, unsigned int count) ...@@ -154,6 +154,10 @@ asmlinkage long sys_getdents(unsigned int fd, void * dirent, unsigned int count)
struct getdents_callback buf; struct getdents_callback buf;
int error; int error;
error = -EFAULT;
if (!access_ok(VERIFY_WRITE, dirent, count))
goto out;
error = -EBADF; error = -EBADF;
file = fget(fd); file = fget(fd);
if (!file) if (!file)
...@@ -211,12 +215,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset, ...@@ -211,12 +215,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
if (reclen > buf->count) if (reclen > buf->count)
return -EINVAL; return -EINVAL;
dirent = buf->previous; dirent = buf->previous;
if (dirent) if (dirent) {
if (__put_user(offset, &dirent->d_off)) if (__put_user(offset, &dirent->d_off))
goto efault; goto efault;
else }
if (__put_user(0, &dirent->d_off))
goto efault;
dirent = buf->current_dir; dirent = buf->current_dir;
buf->previous = dirent; buf->previous = dirent;
if (__put_user(ino, &dirent->d_ino)) if (__put_user(ino, &dirent->d_ino))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment