From: Sumit Garg <sumit.garg@kernel.org>
To: Jens Wiklander <jens.wiklander@linaro.org>
Cc: linux-kernel@vger.kernel.org, op-tee@lists.trustedfirmware.org,
Jerome Forissier <jerome.forissier@linaro.org>,
stable@vger.kernel.org, Masami Ichikawa <masami256@gmail.com>
Subject: Re: [PATCH v2] tee: fix register_shm_helper()
Date: Mon, 22 Sep 2025 14:20:14 +0530 [thread overview]
Message-ID: <aNENxpvdpW7ItjgT@sumit-X1> (raw)
In-Reply-To: <20250922083211.3341508-2-jens.wiklander@linaro.org>
On Mon, Sep 22, 2025 at 10:31:58AM +0200, Jens Wiklander wrote:
> In register_shm_helper(), fix incorrect error handling for a call to
> iov_iter_extract_pages(). A case is missing for when
> iov_iter_extract_pages() only got some pages and return a number larger
> than 0, but not the requested amount.
>
> This fixes a possible NULL pointer dereference following a bad input from
> ioctl(TEE_IOC_SHM_REGISTER) where parts of the buffer isn't mapped.
>
> Cc: stable@vger.kernel.org
> Reported-by: Masami Ichikawa <masami256@gmail.com>
> Closes: https://lore.kernel.org/op-tee/CACOXgS-Bo2W72Nj1_44c7bntyNYOavnTjJAvUbEiQfq=u9W+-g@mail.gmail.com/
> Tested-by: Masami Ichikawa <masami256@gmail.com>
> Fixes: 7bdee4157591 ("tee: Use iov_iter to better support shared buffer registration")
> Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org>
> ---
> Changes from v1
> - Refactor the if statement as requested by Sumit
> - Adding Tested-by: Masami Ichikawa <masami256@gmail.com
> - Link to v1:
> https://lore.kernel.org/op-tee/20250919124217.2934718-1-jens.wiklander@linaro.org/
> ---
> drivers/tee/tee_shm.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
Reviewed-by: Sumit Garg <sumit.garg@oss.qualcomm.com>
-Sumit
>
> diff --git a/drivers/tee/tee_shm.c b/drivers/tee/tee_shm.c
> index daf6e5cfd59a..76c54e1dc98c 100644
> --- a/drivers/tee/tee_shm.c
> +++ b/drivers/tee/tee_shm.c
> @@ -319,6 +319,14 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags,
> if (unlikely(len <= 0)) {
> ret = len ? ERR_PTR(len) : ERR_PTR(-ENOMEM);
> goto err_free_shm_pages;
> + } else if (DIV_ROUND_UP(len + off, PAGE_SIZE) != num_pages) {
> + /*
> + * If we only got a few pages, update to release the
> + * correct amount below.
> + */
> + shm->num_pages = len / PAGE_SIZE;
> + ret = ERR_PTR(-ENOMEM);
> + goto err_put_shm_pages;
> }
>
> /*
> --
> 2.43.0
>
next prev parent reply other threads:[~2025-09-22 8:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-22 8:31 [PATCH v2] tee: fix register_shm_helper() Jens Wiklander
2025-09-22 8:50 ` Sumit Garg [this message]
2025-09-24 8:28 ` 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=aNENxpvdpW7ItjgT@sumit-X1 \
--to=sumit.garg@kernel.org \
--cc=jens.wiklander@linaro.org \
--cc=jerome.forissier@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=masami256@gmail.com \
--cc=op-tee@lists.trustedfirmware.org \
--cc=stable@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox