Skip to content

Commit 9338093

Browse files
jenswi-linarogregkh
authored andcommitted
tee: fix register_shm_helper()
commit d5cf5b3 upstream. 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: 7bdee41 ("tee: Use iov_iter to better support shared buffer registration") Signed-off-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c9b6d78 commit 9338093

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/tee/tee_shm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags,
321321
if (unlikely(len <= 0)) {
322322
ret = len ? ERR_PTR(len) : ERR_PTR(-ENOMEM);
323323
goto err_free_shm_pages;
324+
} else if (DIV_ROUND_UP(len + off, PAGE_SIZE) != num_pages) {
325+
/*
326+
* If we only got a few pages, update to release the
327+
* correct amount below.
328+
*/
329+
shm->num_pages = len / PAGE_SIZE;
330+
ret = ERR_PTR(-ENOMEM);
331+
goto err_put_shm_pages;
324332
}
325333

326334
/*

0 commit comments

Comments
 (0)