Skip to content

RFC Changes to code that reads iovec from userspace

David Laight io-uring lkml netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest12 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/12mm:process_vm_access Call import_iovec() instead of rw_copy_check_uvector()mm/process_vm_access.c+16 -150 replies
2/12fs/io_uring Don't use the return value from import_iovec().fs/io_uring.c+14 -200 replies
2/12fs/io_uring Don't use the return value from import_iovec().+0 -00 replies
3/12fs: Move rw_copy_check_uvector() into lib/iov_iter.c and make static.fs/read_write.c include/linux/compat.h include/linux/fs.h +1 more+178 -1900 replies
4/12lib/iov_iter: Improved function for importing iovec[] from userpace.include/linux/uio.h lib/iov_iter.c+100 -1080 replies
4/12lib/iov_iter: Improved function for importing iovec[] from userpace.+0 -00 replies
5/12scsi: Use iovec_import() instead of import_iovec().block/scsi_ioctl.c drivers/scsi/sg.c+15 -130 replies
6/12security/keys: Use iovec_import() instead of import_iovec().security/keys/compat.c security/keys/keyctl.c+10 -110 replies
7/12mm/process_vm_access: Use iovec_import() instead of import_iovec().mm/process_vm_access.c+42 -390 replies
8/12fs/io_uring: Use iovec_import() not import_iovec().fs/io_uring.c+87 -780 replies
8/12fs/io_uring: Use iovec_import() not import_iovec().+0 -01 reply
9/12fs: Use iovec_import() instead of import_iovec().fs/aio.c fs/read_write.c fs/splice.c+65 -600 replies
10/12net/socket: Use iovec_import() instead of import_iovec().include/linux/socket.h include/net/compat.h net/compat.c +1 more+51 -620 replies
11/12fs:io_uring: Remove #defines added for bisection.fs/io_uring.c+0 -40 replies
11/12fs:io_uring: Remove #defines added for bisection.+0 -00 replies
12/12lib/iov_iter: Remove import_iovec() and compat_import_iovec()include/linux/uio.h lib/iov_iter.c+0 -690 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 00/12] Changes to code that reads iovec from userspace

This is RFC because we seem to be in a merge window.

The canonical code to read iov[] is currently:

	struct iovec iovstack[UIO_FASTIOV];
	struct iovec *iov;
	...
	iov = iovstack;
	rc = import_iovec(..., UIO_FASTIOV, &iov, &iter);
	if (rc < 0)
		return rc;
	...
	kfree(iov);

Note that the 'iov' parameter is used for two different things. On input it is an iov[] can can be used.
On output it is an iov[] array that must be freed.

If 'iovstack' is passed, the count is actually always UIO_FASTIOV (8) although in some places the array definition is in a different file (never mind function) from the constant used.

import_iovec() itself is just a wrapper to rw_copy_check_uvector(). So everything is passed through to a second function. Several items are 'passed by reference' - adding to the code paths.

On success import_iovec() returned the transfer count. Only one caller looks at it, the count is also in iter.count.

The new canonical code is:

	struct iov_cache cache;
	struct iovec *iov;
	...
	iov = iovec_import(..., &cache, &iter);
	if (IS_ERR(iov))
		return PTR_ERR(iov);
	...
	kfree(iov);

Since 'struct iov_cache' is a fixed size there is no need to pass in a length (correct or not!). It can still be NULL (used by the scsi code).

iovec_import() contains the code that used to be in rw_copy_check_uvector() and then sets up the iov_iter.

rw_copy_check_uvector() is no more.
The only other caller was in mm/process_vm_access.c when reading the iov[] for the target process addresses when copying from a differ process. This can extract the iov[] from an extra 'struct iov_iter'.

In passing I noticed an access_ok() call on each fragment. I hope this is just there to bail out early!
It is also skipped in process_vm_rw(). I did a quick look but couldn't see an obvious equivalent check.

Patches 1 and 2 tidy up existing code.
Patches 3 and 4 add the new interface.
Patches 5 through 10 change all the callers.
Patch 11 removes a 'hack' that allowed fs/io_uring be updated before the socket code. Patch 12 removes the old interface.

I suspect the changes need to trickle through a merge window.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)