tee: shm: don't warn on an oversized page array in register_shm_helper()
Subsystems (2)
PATCH 1/1 tee: shm: don't warn on an oversized page array in register_shm_helper()
register_shm_helper() sizes shm->pages from the length passed to TEE_IOC_SHM_REGISTER and allocates it with kzalloc_objs(). A length above 2 GiB makes the array larger than the page allocator can serve in one block (MAX_PAGE_ORDER), so it trips its order warning; on a panic_on_warn kernel that is a panic.
The size comes from userspace and the request fails with -ENOMEM anyway, so pass __GFP_NOWARN. kvzalloc_objs() would not help since kvmalloc warns above INT_MAX as well.
--- drivers/tee/tee_shm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tee/tee_shm.c +2 -1
@@ -438,7 +438,8 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags, goto err_free_shm; } - shm->pages =kzalloc_objs (*shm->pages, num_pages); + shm->pages =kzalloc_objs (*shm->pages, num_pages, +GFP_KERNEL | __GFP_NOWARN);if (!shm->pages) { ret =ERR_PTR (-ENOMEM ); goto err_free_shm;
base-commit: 72d3fcf802c45d00b300f25b848a93c3a2bd7c7e
Signature · 1 line
2.54.0
Hi,
Quoted 34 lines · Georgiy Osokin
register_shm_helper()sizesshm->pagesfrom the length passed toTEE_IOC_SHM_REGISTERand allocates it withkzalloc_objs(). A length above 2 GiB makes the array larger than the page allocator can serve in one block (MAX_PAGE_ORDER), so it trips its order warning; on apanic_on_warnkernel that is a panic.The size comes from userspace and the request fails with
-ENOMEManyway, so pass__GFP_NOWARN.kvzalloc_objs()would not help since kvmalloc warns aboveINT_MAXas well.Fixes 033ddf12bcf5 ("tee: add register user memory")Signed-off-by Georgiy Osokin <[email protected]>--- drivers/tee/tee_shm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tee/tee_shm.c +2
-1@@ -438,7 +438,8 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags, goto err_free_shm; } - shm->pages =kzalloc_objs (*shm->pages, num_pages); + shm->pages =kzalloc_objs (*shm->pages, num_pages, +GFP_KERNEL | __GFP_NOWARN);if (!shm->pages) { ret =ERR_PTR (-ENOMEM ); goto err_free_shm;
Quoted 4 lines
base-commit:
72d3fcf802c45d00b300f25b848a93c3a2bd7c7e--
2.54.0
Looks good. Sumit, do you agree?
Cheers,
Jens
Quoted 37 lines · Jens Wiklander
Hi,
Quoted 34 lines · Georgiy Osokin
register_shm_helper()sizesshm->pagesfrom the length passed toTEE_IOC_SHM_REGISTERand allocates it withkzalloc_objs(). A length above 2 GiB makes the array larger than the page allocator can serve in one block (MAX_PAGE_ORDER), so it trips its order warning; on apanic_on_warnkernel that is a panic.The size comes from userspace and the request fails with
-ENOMEManyway, so pass__GFP_NOWARN.kvzalloc_objs()would not help since kvmalloc warns aboveINT_MAXas well.Fixes 033ddf12bcf5 ("tee: add register user memory")Signed-off-by Georgiy Osokin <[email protected]>--- drivers/tee/tee_shm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tee/tee_shm.c +2
-1@@ -438,7 +438,8 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags, goto err_free_shm; } - shm->pages =kzalloc_objs (*shm->pages, num_pages); + shm->pages =kzalloc_objs (*shm->pages, num_pages, +GFP_KERNEL | __GFP_NOWARN);if (!shm->pages) { ret =ERR_PTR (-ENOMEM ); goto err_free_shm;
Quoted 6 lines
Quoted 4 lines
base-commit:
72d3fcf802c45d00b300f25b848a93c3a2bd7c7e--
2.54.0Looks good. Sumit, do you agree?
Yeah, feel free to add:
-Sumit
Quoted 46 lines · Sumit Garg
Quoted 37 lines · Jens Wiklander
Hi,
Quoted 34 lines · Georgiy Osokin
register_shm_helper()sizesshm->pagesfrom the length passed toTEE_IOC_SHM_REGISTERand allocates it withkzalloc_objs(). A length above 2 GiB makes the array larger than the page allocator can serve in one block (MAX_PAGE_ORDER), so it trips its order warning; on apanic_on_warnkernel that is a panic.The size comes from userspace and the request fails with
-ENOMEManyway, so pass__GFP_NOWARN.kvzalloc_objs()would not help since kvmalloc warns aboveINT_MAXas well.Fixes 033ddf12bcf5 ("tee: add register user memory")Signed-off-by Georgiy Osokin <[email protected]>--- drivers/tee/tee_shm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/tee/tee_shm.c +2
-1@@ -438,7 +438,8 @@ register_shm_helper(struct tee_context *ctx, struct iov_iter *iter, u32 flags, goto err_free_shm; } - shm->pages =kzalloc_objs (*shm->pages, num_pages); + shm->pages =kzalloc_objs (*shm->pages, num_pages, +GFP_KERNEL | __GFP_NOWARN);if (!shm->pages) { ret =ERR_PTR (-ENOMEM ); goto err_free_shm;Quoted 6 lines
Quoted 4 lines
base-commit:
72d3fcf802c45d00b300f25b848a93c3a2bd7c7e--
2.54.0Looks good. Sumit, do you agree?
Quoted 3 lines
Yeah, feel free to add:
Reviewed-by Sumit Garg <[email protected]>
I'm picking this up.
Cheers,
Jens