Skip to content

Commit 89cd35c

Browse files
Christoph HellwigAl Viro
authored andcommitted
iov_iter: transparently handle compat iovecs in import_iovec
Use in compat_syscall to import either native or the compat iovecs, and remove the now superflous compat_import_iovec. This removes the need for special compat logic in most callers, and the remaining ones can still be simplified by using __import_iovec with a bool compat parameter. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent bfdc597 commit 89cd35c

11 files changed

Lines changed: 26 additions & 65 deletions

File tree

‎block/scsi_ioctl.c‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -333,16 +333,8 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk,
333333
struct iov_iter i;
334334
struct iovec *iov = NULL;
335335

336-
#ifdef CONFIG_COMPAT
337-
if (in_compat_syscall())
338-
ret = compat_import_iovec(rq_data_dir(rq),
339-
hdr->dxferp, hdr->iovec_count,
340-
0, &iov, &i);
341-
else
342-
#endif
343-
ret = import_iovec(rq_data_dir(rq),
344-
hdr->dxferp, hdr->iovec_count,
345-
0, &iov, &i);
336+
ret = import_iovec(rq_data_dir(rq), hdr->dxferp,
337+
hdr->iovec_count, 0, &iov, &i);
346338
if (ret < 0)
347339
goto out_free_cdb;
348340

‎drivers/scsi/sg.c‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,14 +1820,7 @@ sg_start_req(Sg_request *srp, unsigned char *cmd)
18201820
struct iovec *iov = NULL;
18211821
struct iov_iter i;
18221822

1823-
#ifdef CONFIG_COMPAT
1824-
if (in_compat_syscall())
1825-
res = compat_import_iovec(rw, hp->dxferp, iov_count,
1826-
0, &iov, &i);
1827-
else
1828-
#endif
1829-
res = import_iovec(rw, hp->dxferp, iov_count,
1830-
0, &iov, &i);
1823+
res = import_iovec(rw, hp->dxferp, iov_count, 0, &iov, &i);
18311824
if (res < 0)
18321825
return res;
18331826

‎fs/aio.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,12 +1489,8 @@ static ssize_t aio_setup_rw(int rw, const struct iocb *iocb,
14891489
*iovec = NULL;
14901490
return ret;
14911491
}
1492-
#ifdef CONFIG_COMPAT
1493-
if (compat)
1494-
return compat_import_iovec(rw, buf, len, UIO_FASTIOV, iovec,
1495-
iter);
1496-
#endif
1497-
return import_iovec(rw, buf, len, UIO_FASTIOV, iovec, iter);
1492+
1493+
return __import_iovec(rw, buf, len, UIO_FASTIOV, iovec, iter, compat);
14981494
}
14991495

15001496
static inline void aio_rw_done(struct kiocb *req, ssize_t ret)

‎fs/io_uring.c‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2846,13 +2846,8 @@ static ssize_t __io_import_iovec(int rw, struct io_kiocb *req,
28462846
return ret;
28472847
}
28482848

2849-
#ifdef CONFIG_COMPAT
2850-
if (req->ctx->compat)
2851-
return compat_import_iovec(rw, buf, sqe_len, UIO_FASTIOV,
2852-
iovec, iter);
2853-
#endif
2854-
2855-
return import_iovec(rw, buf, sqe_len, UIO_FASTIOV, iovec, iter);
2849+
return __import_iovec(rw, buf, sqe_len, UIO_FASTIOV, iovec, iter,
2850+
req->ctx->compat);
28562851
}
28572852

28582853
static ssize_t io_import_iovec(int rw, struct io_kiocb *req,
@@ -4166,8 +4161,9 @@ static int __io_recvmsg_copy_hdr(struct io_kiocb *req,
41664161
sr->len);
41674162
iomsg->iov = NULL;
41684163
} else {
4169-
ret = import_iovec(READ, uiov, iov_len, UIO_FASTIOV,
4170-
&iomsg->iov, &iomsg->msg.msg_iter);
4164+
ret = __import_iovec(READ, uiov, iov_len, UIO_FASTIOV,
4165+
&iomsg->iov, &iomsg->msg.msg_iter,
4166+
false);
41714167
if (ret > 0)
41724168
ret = 0;
41734169
}
@@ -4207,9 +4203,9 @@ static int __io_compat_recvmsg_copy_hdr(struct io_kiocb *req,
42074203
sr->len = iomsg->iov[0].iov_len;
42084204
iomsg->iov = NULL;
42094205
} else {
4210-
ret = compat_import_iovec(READ, uiov, len, UIO_FASTIOV,
4211-
&iomsg->iov,
4212-
&iomsg->msg.msg_iter);
4206+
ret = __import_iovec(READ, (struct iovec __user *)uiov, len,
4207+
UIO_FASTIOV, &iomsg->iov,
4208+
&iomsg->msg.msg_iter, true);
42134209
if (ret < 0)
42144210
return ret;
42154211
}

‎fs/read_write.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,8 @@ static size_t compat_readv(struct file *file,
10781078
struct iov_iter iter;
10791079
ssize_t ret;
10801080

1081-
ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter);
1081+
ret = import_iovec(READ, (const struct iovec __user *)vec, vlen,
1082+
UIO_FASTIOV, &iov, &iter);
10821083
if (ret >= 0) {
10831084
ret = do_iter_read(file, &iter, pos, flags);
10841085
kfree(iov);
@@ -1186,7 +1187,8 @@ static size_t compat_writev(struct file *file,
11861187
struct iov_iter iter;
11871188
ssize_t ret;
11881189

1189-
ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter);
1190+
ret = import_iovec(WRITE, (const struct iovec __user *)vec, vlen,
1191+
UIO_FASTIOV, &iov, &iter);
11901192
if (ret >= 0) {
11911193
file_start_write(file);
11921194
ret = do_iter_write(file, &iter, pos, flags);

‎fs/splice.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ COMPAT_SYSCALL_DEFINE4(vmsplice, int, fd, const struct compat_iovec __user *, io
13871387
if (error)
13881388
return error;
13891389

1390-
error = compat_import_iovec(type, iov32, nr_segs,
1390+
error = import_iovec(type, (struct iovec __user *)iov32, nr_segs,
13911391
ARRAY_SIZE(iovstack), &iov, &iter);
13921392
if (error >= 0) {
13931393
error = do_vmsplice(f.file, &iter, flags);

‎include/linux/uio.h‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,14 +275,6 @@ ssize_t import_iovec(int type, const struct iovec __user *uvec,
275275
ssize_t __import_iovec(int type, const struct iovec __user *uvec,
276276
unsigned nr_segs, unsigned fast_segs, struct iovec **iovp,
277277
struct iov_iter *i, bool compat);
278-
279-
#ifdef CONFIG_COMPAT
280-
struct compat_iovec;
281-
ssize_t compat_import_iovec(int type, const struct compat_iovec __user * uvector,
282-
unsigned nr_segs, unsigned fast_segs,
283-
struct iovec **iov, struct iov_iter *i);
284-
#endif
285-
286278
int import_single_range(int type, void __user *buf, size_t len,
287279
struct iovec *iov, struct iov_iter *i);
288280

‎lib/iov_iter.c‎

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1806,21 +1806,11 @@ ssize_t import_iovec(int type, const struct iovec __user *uvec,
18061806
unsigned nr_segs, unsigned fast_segs,
18071807
struct iovec **iovp, struct iov_iter *i)
18081808
{
1809-
return __import_iovec(type, uvec, nr_segs, fast_segs, iovp, i, false);
1809+
return __import_iovec(type, uvec, nr_segs, fast_segs, iovp, i,
1810+
in_compat_syscall());
18101811
}
18111812
EXPORT_SYMBOL(import_iovec);
18121813

1813-
#ifdef CONFIG_COMPAT
1814-
ssize_t compat_import_iovec(int type, const struct compat_iovec __user *uvec,
1815-
unsigned nr_segs, unsigned fast_segs, struct iovec **iovp,
1816-
struct iov_iter *i)
1817-
{
1818-
return __import_iovec(type, (const struct iovec __user *)uvec, nr_segs,
1819-
fast_segs, iovp, i, true);
1820-
}
1821-
EXPORT_SYMBOL(compat_import_iovec);
1822-
#endif
1823-
18241814
int import_single_range(int rw, void __user *buf, size_t len,
18251815
struct iovec *iov, struct iov_iter *i)
18261816
{

‎mm/process_vm_access.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ compat_process_vm_rw(compat_pid_t pid,
326326
if (flags != 0)
327327
return -EINVAL;
328328

329-
rc = compat_import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter);
329+
rc = import_iovec(dir, (const struct iovec __user *)lvec, liovcnt,
330+
UIO_FASTIOV, &iov_l, &iter);
330331
if (rc < 0)
331332
return rc;
332333
if (!iov_iter_count(&iter))

‎net/compat.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ int get_compat_msghdr(struct msghdr *kmsg,
9898
if (err)
9999
return err;
100100

101-
err = compat_import_iovec(save_addr ? READ : WRITE, compat_ptr(ptr),
102-
len, UIO_FASTIOV, iov, &kmsg->msg_iter);
101+
err = import_iovec(save_addr ? READ : WRITE, compat_ptr(ptr), len,
102+
UIO_FASTIOV, iov, &kmsg->msg_iter);
103103
return err < 0 ? err : 0;
104104
}
105105

0 commit comments

Comments
 (0)