lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 22 Dec 2014 12:48:35 +0100
From:	Dongsu Park <dongsu.park@...fitbricks.com>
To:	linux-kernel@...r.kernel.org
Cc:	Jens Axboe <axboe@...nel.dk>, Kent Overstreet <kmo@...erainc.com>,
	Ming Lin <mlin@...ggr.net>,
	Dongsu Park <dongsu.park@...fitbricks.com>,
	Al Viro <viro@...iv.linux.org.uk>
Subject: [RFC PATCH 08/17] block: refactor __bio_copy_iov()

From: Kent Overstreet <kmo@...erainc.com>

Rewrite __bio_copy_iov() to use copy_page_to_iter() or
copy_page_from_iter(), according to Al Viro's suggestions.

This commit should contain only literal replacements, without
functional changes.

Signed-off-by: Kent Overstreet <kmo@...erainc.com>
[dpark: add more description in commit message]
Signed-off-by: Dongsu Park <dongsu.park@...fitbricks.com>
Cc: Jens Axboe <axboe@...nel.dk>
Cc: Al Viro <viro@...iv.linux.org.uk>
---
 block/bio.c | 62 +++++++++++++++++++++++++------------------------------------
 1 file changed, 25 insertions(+), 37 deletions(-)

diff --git a/block/bio.c b/block/bio.c
index 4731c4a..524b401 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -1022,45 +1022,34 @@ static struct bio_map_data *bio_alloc_map_data(unsigned int iov_count,
 }
 
 static int __bio_copy_iov(struct bio *bio, const struct iov_iter *iter,
-			  int to_user, int from_user, int do_free_page)
+			  int to_iov)
 {
-	int ret = 0, i;
+	int i;
 	struct bio_vec *bvec;
 	struct iov_iter iov_iter = *iter;
 
 	bio_for_each_segment_all(bvec, bio, i) {
-		char *bv_addr = page_address(bvec->bv_page);
-		unsigned int bv_len = bvec->bv_len;
-
-		while (bv_len && iov_iter.count) {
-			struct iovec iov = iov_iter_iovec(&iov_iter);
-			unsigned int bytes = min_t(unsigned int, bv_len,
-						   iov.iov_len);
-
-			if (!ret) {
-				if (to_user)
-					ret = copy_to_user(iov.iov_base,
-							   bv_addr, bytes);
-
-				if (from_user)
-					ret = copy_from_user(bv_addr,
-							     iov.iov_base,
-							     bytes);
-
-				if (ret)
-					ret = -EFAULT;
-			}
-
-			bv_len -= bytes;
-			bv_addr += bytes;
-			iov_iter_advance(&iov_iter, bytes);
-		}
+		ssize_t ret;
+
+		if (to_iov == WRITE)
+			ret = copy_page_to_iter(bvec->bv_page,
+						bvec->bv_offset,
+						bvec->bv_len,
+						&iov_iter);
+		else
+			ret = copy_page_from_iter(bvec->bv_page,
+						  bvec->bv_offset,
+						  bvec->bv_len,
+						  &iov_iter);
+
+		if (!iov_iter_count(&iov_iter))
+			break;
 
-		if (do_free_page)
-			__free_page(bvec->bv_page);
+		if (ret < bvec->bv_len)
+			return -EFAULT;
 	}
 
-	return ret;
+	return 0;
 }
 
 /**
@@ -1081,11 +1070,10 @@ int bio_uncopy_user(struct bio *bio)
 		 * if we're in a workqueue, the request is orphaned, so
 		 * don't copy into a random user address space, just free.
 		 */
-		if (current->mm)
-			ret = __bio_copy_iov(bio, &bmd->iter,
-					     bio_data_dir(bio) == READ,
-					     0, bmd->is_our_pages);
-		else if (bmd->is_our_pages)
+		if (current->mm && bio_data_dir(bio) == READ)
+			ret = __bio_copy_iov(bio, &bmd->iter, WRITE);
+
+		if (bmd->is_our_pages)
 			bio_for_each_segment_all(bvec, bio, i)
 				__free_page(bvec->bv_page);
 	}
@@ -1208,7 +1196,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
 	 */
 	if ((!write_to_vm && (!map_data || !map_data->null_mapped)) ||
 	    (map_data && map_data->from_user)) {
-		ret = __bio_copy_iov(bio, iter, 0, 1, 0);
+		ret = __bio_copy_iov(bio, iter, READ);
 		if (ret)
 			goto cleanup;
 	}
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists