From: Georgiy Osokin <g.osokin@auroraos.dev>
To: <jens.wiklander@linaro.org>, <op-tee@lists.trustedfirmware.org>
Cc: <sumit.garg@kernel.org>, <linux-kernel@vger.kernel.org>,
<lvc-project@linuxtesting.org>, <s.shtylyov@auroraos.dev>,
Georgiy Osokin <g.osokin@auroraos.dev>, <stable@vger.kernel.org>
Subject: [PATCH] tee: shm: fix shm leak in register_shm_helper()
Date: Wed, 8 Apr 2026 18:52:03 +0300 [thread overview]
Message-ID: <20260408155203.817744-1-g.osokin@auroraos.dev> (raw)
register_shm_helper() allocates shm before calling
iov_iter_npages(). If iov_iter_npages() returns 0, the function
jumps to err_ctx_put and leaks shm.
This can be triggered by TEE_IOC_SHM_REGISTER with
struct tee_ioctl_shm_register_data where length is 0.
Jump to err_free_shm instead.
Fixes: 7bdee4157591 ("tee: Use iov_iter to better support shared buffer registration")
Cc: stable@vger.kernel.org
Cc: lvc-project@linuxtesting.org
Signed-off-by: Georgiy Osokin <g.osokin@auroraos.dev>
---
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 e9ea9f80cfd9..6742b3579c86 100644
--- a/drivers/tee/tee_shm.c
+++ b/drivers/tee/tee_shm.c
@@ -435,7 +435,7 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags,
num_pages = iov_iter_npages(iter, INT_MAX);
if (!num_pages) {
ret = ERR_PTR(-ENOMEM);
- goto err_ctx_put;
+ goto err_free_shm;
}
shm->pages = kzalloc_objs(*shm->pages, num_pages);
--
2.50.1
next reply other threads:[~2026-04-08 16:09 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-08 15:52 Georgiy Osokin [this message]
2026-04-13 9:03 ` [PATCH] tee: shm: fix shm leak in register_shm_helper() 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=20260408155203.817744-1-g.osokin@auroraos.dev \
--to=g.osokin@auroraos.dev \
--cc=jens.wiklander@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=op-tee@lists.trustedfirmware.org \
--cc=s.shtylyov@auroraos.dev \
--cc=stable@vger.kernel.org \
--cc=sumit.garg@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