Linux-Block Archive mirror
 help / color / mirror / Atom feed
From: Mingming Gu <mmgu@volanscomputer.com>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: "Christian A . Ehrhardt" <lk@c--e.de>,
	Jens Axboe <axboe@kernel.dk>,
	Andrew Morton <akpm@linux-foundation.org>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Mingming Gu <mmgu@volanscomputer.com>
Subject: [PATCH] block: fix bio_copy_user_iov() for SG_DXFER_TO_FROM_DEV case
Date: Sat, 13 Apr 2024 11:45:08 +0800	[thread overview]
Message-ID: <1712979908-6132-1-git-send-email-mmgu@volanscomputer.com> (raw)

Commit "block: Fix WARNING in _copy_from_iter" is insufficient to make
SG_IO ioctl with a transfer direction of SG_DXFER_TO_FROM_DEV work;
the passed in iterator should be advanced after bio_copy_from_iter().
Otherwise its caller, blk_rq_map_user_iov(), will return -EINVAL due
to a wrong loop condition.

Instead of using a copy of the passed iterator, save iter->data_source
and restore it after bio_copy_from_iter().

Signed-off-by: Mingming Gu <mmgu@volanscomputer.com>
---
 block/blk-map.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/block/blk-map.c b/block/blk-map.c
index 71210cd..eca02d9 100644
--- a/block/blk-map.c
+++ b/block/blk-map.c
@@ -211,11 +211,12 @@ static int bio_copy_user_iov(struct request *rq, struct rq_map_data *map_data,
 		if (ret)
 			goto cleanup;
 	} else if (map_data && map_data->from_user) {
-		struct iov_iter iter2 = *iter;
+		bool tmp = iter->data_source;
 
 		/* This is the copy-in part of SG_DXFER_TO_FROM_DEV. */
-		iter2.data_source = ITER_SOURCE;
-		ret = bio_copy_from_iter(bio, &iter2);
+		iter->data_source = ITER_SOURCE;
+		ret = bio_copy_from_iter(bio, iter);
+		iter->data_source = tmp;
 		if (ret)
 			goto cleanup;
 	} else {
-- 
2.7.4


                 reply	other threads:[~2024-04-13  3:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1712979908-6132-1-git-send-email-mmgu@volanscomputer.com \
    --to=mmgu@volanscomputer.com \
    --cc=akpm@linux-foundation.org \
    --cc=axboe@kernel.dk \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lk@c--e.de \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).