Jelajahi Sumber

compat breakage in preadv() and pwritev()

Fix for a dumb preadv()/pwritev() compat bug - unlike the native
variants, compat_... ones forget to check FMODE_P{READ,WRITE}, so e.g.
on pipe the native preadv() will fail with -ESPIPE and compat one will
act as readv() and succeed.  Not critical, but it's a clear bug with trivial
fix.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Al Viro 14 tahun lalu
induk
melakukan
586ce098a2
1 mengubah file dengan 6 tambahan dan 2 penghapusan
  1. 6 2
      fs/compat.c

+ 6 - 2
fs/compat.c

@@ -1228,7 +1228,9 @@ compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec,
 	file = fget_light(fd, &fput_needed);
 	file = fget_light(fd, &fput_needed);
 	if (!file)
 	if (!file)
 		return -EBADF;
 		return -EBADF;
-	ret = compat_readv(file, vec, vlen, &pos);
+	ret = -ESPIPE;
+	if (file->f_mode & FMODE_PREAD)
+		ret = compat_readv(file, vec, vlen, &pos);
 	fput_light(file, fput_needed);
 	fput_light(file, fput_needed);
 	return ret;
 	return ret;
 }
 }
@@ -1285,7 +1287,9 @@ compat_sys_pwritev(unsigned long fd, const struct compat_iovec __user *vec,
 	file = fget_light(fd, &fput_needed);
 	file = fget_light(fd, &fput_needed);
 	if (!file)
 	if (!file)
 		return -EBADF;
 		return -EBADF;
-	ret = compat_writev(file, vec, vlen, &pos);
+	ret = -ESPIPE;
+	if (file->f_mode & FMODE_PWRITE)
+		ret = compat_writev(file, vec, vlen, &pos);
 	fput_light(file, fput_needed);
 	fput_light(file, fput_needed);
 	return ret;
 	return ret;
 }
 }