From: Jens Axboe <axboe@kernel.dk>
To: op-tee@lists.trustedfirmware.org
Subject: Re: [PATCH v4] tee: Use iov_iter to better support shared buffer registration
Date: Mon, 04 Dec 2023 09:40:48 -0700 [thread overview]
Message-ID: <cf00a996-c262-4457-93de-ca7960ad6df6@kernel.dk> (raw)
In-Reply-To: <438a8b44-ea5f-4e13-bd7e-e1c2e2a481c4@kernel.dk>
[-- Attachment #1: Type: text/plain, Size: 1558 bytes --]
On 12/4/23 9:36 AM, Jens Axboe wrote:
> On 12/4/23 5:42 AM, Sumit Garg wrote:
>> IMO, access_ok() should be the first thing that import_ubuf() or
>> import_single_range() should do, something as follows:
>>
>> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
>> index 8ff6824a1005..4aee0371824c 100644
>> --- a/lib/iov_iter.c
>> +++ b/lib/iov_iter.c
>> @@ -1384,10 +1384,10 @@ EXPORT_SYMBOL(import_single_range);
>>
>> int import_ubuf(int rw, void __user *buf, size_t len, struct iov_iter *i)
>> {
>> - if (len > MAX_RW_COUNT)
>> - len = MAX_RW_COUNT;
>> if (unlikely(!access_ok(buf, len)))
>> return -EFAULT;
>> + if (len > MAX_RW_COUNT)
>> + len = MAX_RW_COUNT;
>>
>> iov_iter_ubuf(i, rw, buf, len);
>> return 0;
>>
>> Jens A., Al Viro,
>>
>> Was there any particular reason which I am unaware of to perform
>> access_ok() check on modified input length?
>
> This change makes sense to me, and seems consistent with what is done
> elsewhere too.
For some reason I missed import_single_range(), which does it the same
way as import_ubuf() currently does - cap the range before the
access_ok() check. The vec variants sum as they go, but access_ok()
before the range.
I think part of the issue here is that the single range imports return 0
for success and -ERROR otherwise. This means that the caller does not
know if the full range was imported or not. OTOH, we always cap any data
transfer at MAX_RW_COUNT, so may make more sense to fix up the caller
here.
--
Jens Axboe
WARNING: multiple messages have this Message-ID (diff)
From: Jens Axboe <axboe@kernel.dk>
To: Sumit Garg <sumit.garg@linaro.org>,
Arnaud POULIQUEN <arnaud.pouliquen@foss.st.com>,
Al Viro <viro@zeniv.linux.org.uk>
Cc: Jens Wiklander <jens.wiklander@linaro.org>,
Christoph Hellwig <hch@infradead.org>,
op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4] tee: Use iov_iter to better support shared buffer registration
Date: Mon, 4 Dec 2023 09:40:48 -0700 [thread overview]
Message-ID: <cf00a996-c262-4457-93de-ca7960ad6df6@kernel.dk> (raw)
In-Reply-To: <438a8b44-ea5f-4e13-bd7e-e1c2e2a481c4@kernel.dk>
On 12/4/23 9:36 AM, Jens Axboe wrote:
> On 12/4/23 5:42 AM, Sumit Garg wrote:
>> IMO, access_ok() should be the first thing that import_ubuf() or
>> import_single_range() should do, something as follows:
>>
>> diff --git a/lib/iov_iter.c b/lib/iov_iter.c
>> index 8ff6824a1005..4aee0371824c 100644
>> --- a/lib/iov_iter.c
>> +++ b/lib/iov_iter.c
>> @@ -1384,10 +1384,10 @@ EXPORT_SYMBOL(import_single_range);
>>
>> int import_ubuf(int rw, void __user *buf, size_t len, struct iov_iter *i)
>> {
>> - if (len > MAX_RW_COUNT)
>> - len = MAX_RW_COUNT;
>> if (unlikely(!access_ok(buf, len)))
>> return -EFAULT;
>> + if (len > MAX_RW_COUNT)
>> + len = MAX_RW_COUNT;
>>
>> iov_iter_ubuf(i, rw, buf, len);
>> return 0;
>>
>> Jens A., Al Viro,
>>
>> Was there any particular reason which I am unaware of to perform
>> access_ok() check on modified input length?
>
> This change makes sense to me, and seems consistent with what is done
> elsewhere too.
For some reason I missed import_single_range(), which does it the same
way as import_ubuf() currently does - cap the range before the
access_ok() check. The vec variants sum as they go, but access_ok()
before the range.
I think part of the issue here is that the single range imports return 0
for success and -ERROR otherwise. This means that the caller does not
know if the full range was imported or not. OTOH, we always cap any data
transfer at MAX_RW_COUNT, so may make more sense to fix up the caller
here.
--
Jens Axboe
next prev parent reply other threads:[~2023-12-04 16:40 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] < <CAFA6WYPGkpVN-XP7eAzLXMReRi7FBp3boKzhMfasasuE=XWBow@mail.gmail.com>
2023-12-04 16:36 ` [PATCH v4] tee: Use iov_iter to better support shared buffer registration Jens Axboe
2023-12-04 16:36 ` Jens Axboe
2023-12-04 16:40 ` Jens Axboe [this message]
2023-12-04 16:40 ` Jens Axboe
2023-12-04 17:02 ` Arnaud POULIQUEN
2023-12-04 17:02 ` Arnaud POULIQUEN
2023-12-04 17:13 ` Jens Axboe
2023-12-04 17:13 ` Jens Axboe
2023-12-05 16:55 ` Arnaud POULIQUEN
2023-12-05 16:55 ` Arnaud POULIQUEN
2023-12-05 17:50 ` Jens Axboe
2023-12-05 17:50 ` Jens Axboe
2023-12-06 11:38 ` David Laight
2023-12-06 11:39 ` David Laight
2023-12-05 12:07 ` Sumit Garg
2023-12-05 12:07 ` Sumit Garg
[not found] < <CAFA6WYMi52WTWho5y=967fm8utqtdq9fuCjVJFA9G0MaHtNYgg@mail.gmail.com>
2023-12-05 13:45 ` Arnaud POULIQUEN
2023-12-05 13:45 ` Arnaud POULIQUEN
2023-11-29 16:44 Arnaud Pouliquen
2023-11-29 16:45 ` Arnaud Pouliquen
2023-11-30 7:54 ` Sumit Garg
2023-11-30 7:54 ` Sumit Garg
2023-11-30 9:08 ` Arnaud POULIQUEN
2023-11-30 9:08 ` Arnaud POULIQUEN
2023-11-30 12:00 ` Sumit Garg
2023-11-30 12:00 ` Sumit Garg
2023-11-30 13:18 ` Arnaud POULIQUEN
2023-11-30 13:18 ` Arnaud POULIQUEN
2023-12-04 12:42 ` Sumit Garg
2023-12-04 12:42 ` Sumit Garg
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=cf00a996-c262-4457-93de-ca7960ad6df6@kernel.dk \
--to=axboe@kernel.dk \
--cc=op-tee@lists.trustedfirmware.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.