Skip to contentSkip to conversation

tee: shm: don't warn on an oversized page array in register_shm_helper()

PATCH In review Georgiy Osokin 3 participants 4 messages Oct 23 – Nov 5

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

Fixes 033ddf12bcf5 ("tee: add register user memory")
---
 drivers/tee/tee_shm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tee/tee_shm.c +2 -1
index 6742b35..d539988 100644
@@ -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
#1 lore raw

Hi,

Quoted 34 lines · Georgiy Osokin

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.

Fixes 033ddf12bcf5 ("tee: add register user memory")
---
 drivers/tee/tee_shm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tee/tee_shm.c +2 -1
index 6742b35..d539988 100644
@@ -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

reviewer Reviewed-by
#2 lore raw
Quoted 37 lines · Jens Wiklander

Hi,

Quoted 34 lines · Georgiy Osokin

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.

Fixes 033ddf12bcf5 ("tee: add register user memory")
---
 drivers/tee/tee_shm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tee/tee_shm.c +2 -1
index 6742b35..d539988 100644
@@ -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.0

Looks good. Sumit, do you agree?

Yeah, feel free to add:

-Sumit

#3 lore raw
Quoted 46 lines · Sumit Garg
Quoted 37 lines · Jens Wiklander

Hi,

Quoted 34 lines · Georgiy Osokin

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.

Fixes 033ddf12bcf5 ("tee: add register user memory")
---
 drivers/tee/tee_shm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tee/tee_shm.c +2 -1
index 6742b35..d539988 100644
@@ -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.0

Looks good. Sumit, do you agree?

Quoted 3 lines

Yeah, feel free to add:

I'm picking this up.

Cheers,
Jens