mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sumit Garg <sumit.garg@kernel.org>
To: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
Cc: Shukai Ni <shukai.ni@kuleuven.be>,
	Sumit Garg <sumit.garg@kernel.org>,
	Jens Wiklander <jenswi@kernel.org>,
	Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>,
	op-tee@lists.trustedfirmware.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/1] tee: fix page count in register_shm_helper() error path
Date: Thu, 5 Nov 2026 17:46:13 +0530	[thread overview]
Message-ID: <auxzjSfifbLjPasI@sumit-xelite> (raw)
In-Reply-To: <CAGgiveUQ9_uZLL=KgGtV0PNiBRbHhRVMqKxWwE3jww2asW98VA@mail.gmail.com>

On Tue, 03 Nov 2026 at 19:11:06 +0100, Jens Wiklander wrote:
>Hi,
>
>On Mon, Aug 31, 2026 at 12:58 PM Shukai Ni <shukai.ni@kuleuven.be> wrote:
>>
>> iov_iter_extract_pages() returns the number of bytes extracted and sets off
>> to the offset into the first page. For the iterator, the number of pages
>> pinned is therefore DIV_ROUND_UP(len + off, PAGE_SIZE).
>>
>> The partial-extraction error path instead records len / PAGE_SIZE. For an
>> unaligned buffer this can undercount by one, causing unpin_user_pages() to
>> leave a page pinned.
>>
>> Fixes: d5cf5b37064b ("tee: fix register_shm_helper()")
>> Cc: stable@vger.kernel.org
>> Co-developed-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
>> Signed-off-by: Jo Van Bulck <jo.vanbulck@cs.kuleuven.be>
>> Signed-off-by: Shukai Ni <shukai.ni@kuleuven.be>
>> ---
>>  drivers/tee/tee_shm.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
>> index 6742b35..fa446e4 100644
>> --- a/drivers/tee/tee_shm.c
>> +++ b/drivers/tee/tee_shm.c
>> @@ -454,7 +454,7 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags,
>>                  * If we only got a few pages, update to release the
>>                  * correct amount below.
>>                  */
>> -               shm->num_pages = len / PAGE_SIZE;
>> +               shm->num_pages = DIV_ROUND_UP(len + off, PAGE_SIZE);
>>                 ret = ERR_PTR(-ENOMEM);
>>                 goto err_put_shm_pages;
>>         }
>> --
>> 2.55.0
>>
>
>Looks good. Sumit, do you agree?

Sounds like a reasonable fix to me, feel free to add:

Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>

-Sumit

  reply	other threads:[~2026-11-05 12:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 10:58 [PATCH 0/1] tee: fix page pin leak in register_shm_helper() Shukai Ni
2026-08-31 10:58 ` [PATCH 1/1] tee: fix page count in register_shm_helper() error path Shukai Ni
2026-11-03 18:11   ` Jens Wiklander
2026-11-05 12:16     ` Sumit Garg [this message]
2026-11-05 15:24       ` Jens Wiklander

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=auxzjSfifbLjPasI@sumit-xelite \
    --to=sumit.garg@kernel.org \
    --cc=jens.wiklander@oss.qualcomm.com \
    --cc=jenswi@kernel.org \
    --cc=jo.vanbulck@cs.kuleuven.be \
    --cc=linux-kernel@vger.kernel.org \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=shukai.ni@kuleuven.be \
    /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

all inboxes | Powered by JetHome®