tee: amdtee: fix an IS_ERR() vs NULL bug
Subsystems (2)
PATCH 1/1 tee: amdtee: fix an IS_ERR() vs NULL bug
The __get_free_pages() function does not return error pointers it returns NULL so fix this condition to avoid a NULL dereference.
--- drivers/tee/amdtee/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tee/amdtee/core.c +2 -3
@@ -203,9 +203,8 @@ static int copy_ta_binary(struct tee_context *ctx, void *ptr, void **ta, *ta_size =roundup (fw->size,PAGE_SIZE ); *ta = (void *)__get_free_pages (GFP_KERNEL ,get_order (*ta_size)); -if (IS_ERR (*ta)) { -pr_err ("%s: get_free_pages failed 0x%llx\n" , __func__, - (u64)*ta); +if (!*ta) { +pr_err ("%s: get_free_pages failed\n" , __func__); rc = -ENOMEM ; goto rel_fw; }
Signature · 1 line
2.20.1
[Public]
-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Wednesday, November 24, 2021 8:24 PM
To: Jens Wiklander <[email protected]>; Thomas, Rijo-john <[email protected]>
Cc: Sumit Garg <[email protected]>; Rangasamy, Devaraj <[email protected]>; Herbert Xu <[email protected]>; Gary R Hook <[email protected]>; op-tee(a)lists.trustedfirmware.org; linux-kernel(a)vger.kernel.org; kernel-janitors(a)vger.kernel.org
Subject: [PATCH] tee: amdtee: fix an IS_ERR() vs NULL bug
The __get_free_pages() function does not return error pointers it returns NULL so fix this condition to avoid a NULL dereference.
--- drivers/tee/amdtee/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tee/amdtee/core.c +2 -3
@@ -203,9 +203,8 @@ static int copy_ta_binary(struct tee_context *ctx, void *ptr, void **ta, *ta_size =roundup (fw->size,PAGE_SIZE ); *ta = (void *)__get_free_pages (GFP_KERNEL ,get_order (*ta_size)); -if (IS_ERR (*ta)) { -pr_err ("%s: get_free_pages failed 0x%llx\n" , __func__, - (u64)*ta); +if (!*ta) { +pr_err ("%s: get_free_pages failed\n" , __func__); rc = -ENOMEM ; goto rel_fw; }
Signature · 1 line
2.20.1
Quoted 6 lines · On Mon, Nov 29, 2021 at 04:31:51PM +0800, 994605959 wrote:
maybe try this?
- if (IS_ERR(*ta)) {
- pr_err("%s: get_free_pages failed 0x%llx\n", __func__,
- (u64)*ta);
+ if (IS_ERR(ta)) {
+ pr_err("%s: get_free_pages failed %p\n", __func__, ta);No, what you are suggesting is totally wrong. You are checking the wrong variable for the wrong thing.
regards,
dan carpenter
Quoted 27 lines · Rijo-john
[Public]
Acked-by Rijo Thomas <[email protected]>-----Original Message-----
From: Dan Carpenter <[email protected]>
Sent: Wednesday, November 24, 2021 8:24 PM
To: Jens Wiklander <[email protected]>; Thomas, Rijo-john <[email protected]>
Cc: Sumit Garg <[email protected]>; Rangasamy, Devaraj <[email protected]>; Herbert Xu <[email protected]>; Gary R Hook <[email protected]>; op-tee(a)lists.trustedfirmware.org; linux-kernel(a)vger.kernel.org; kernel-janitors(a)vger.kernel.org
Subject: [PATCH] tee: amdtee: fix anIS_ERR()vs NULL bugThe
__get_free_pages()function does not return error pointers it returns NULL so fix this condition to avoid a NULL dereference.Fixes 757cc3e9ff1d ("tee: add AMD-TEE driver")Signed-off-by Dan Carpenter <[email protected]>--- drivers/tee/amdtee/core.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)drivers/tee/amdtee/core.c +0
-0@@ -203,9 +203,8 @@ static int copy_ta_binary(struct tee_context *ctx, void *ptr, void **ta,
drivers/tee/amdtee/core.c static int copy_ta_binary(struct tee_context *ctx, void *ptr, void **ta, · line 210
Quoted 10 lines
drivers/tee/amdtee/core.c +2
-3*ta_size =roundup (fw->size,PAGE_SIZE ); *ta = (void *)__get_free_pages (GFP_KERNEL ,get_order (*ta_size)); -if (IS_ERR (*ta)) { -pr_err ("%s: get_free_pages failed 0x%llx\n" , __func__, - (u64)*ta); +if (!*ta) { +pr_err ("%s: get_free_pages failed\n" , __func__); rc = -ENOMEM ; goto rel_fw; }
Looks good, I'm picking up this.
Thanks,
Jens