Skip to content

Commit 586ce09

Browse files
author
Al Viro
committed
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>
1 parent 9179746 commit 586ce09

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎fs/compat.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,9 @@ compat_sys_preadv(unsigned long fd, const struct compat_iovec __user *vec,
12281228
file = fget_light(fd, &fput_needed);
12291229
if (!file)
12301230
return -EBADF;
1231-
ret = compat_readv(file, vec, vlen, &pos);
1231+
ret = -ESPIPE;
1232+
if (file->f_mode & FMODE_PREAD)
1233+
ret = compat_readv(file, vec, vlen, &pos);
12321234
fput_light(file, fput_needed);
12331235
return ret;
12341236
}
@@ -1285,7 +1287,9 @@ compat_sys_pwritev(unsigned long fd, const struct compat_iovec __user *vec,
12851287
file = fget_light(fd, &fput_needed);
12861288
if (!file)
12871289
return -EBADF;
1288-
ret = compat_writev(file, vec, vlen, &pos);
1290+
ret = -ESPIPE;
1291+
if (file->f_mode & FMODE_PWRITE)
1292+
ret = compat_writev(file, vec, vlen, &pos);
12891293
fput_light(file, fput_needed);
12901294
return ret;
12911295
}

0 commit comments

Comments
 (0)