* [PATCH] tee: amdtee: fix an IS_ERR() vs NULL bug
@ 2021-11-24 14:54 Dan Carpenter
2021-11-29 8:23 ` Thomas, Rijo-john
0 siblings, 1 reply; 4+ messages in thread
From: Dan Carpenter @ 2021-11-24 14:54 UTC (permalink / raw)
To: op-tee
[-- Attachment #1: Type: text/plain, Size: 945 bytes --]
The __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 <dan.carpenter@oracle.com>
---
drivers/tee/amdtee/core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/tee/amdtee/core.c b/drivers/tee/amdtee/core.c
index da6b88e80dc0..297dc62bca29 100644
--- a/drivers/tee/amdtee/core.c
+++ b/drivers/tee/amdtee/core.c
@@ -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;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* RE: [PATCH] tee: amdtee: fix an IS_ERR() vs NULL bug
2021-11-24 14:54 Dan Carpenter
@ 2021-11-29 8:23 ` Thomas, Rijo-john
0 siblings, 0 replies; 4+ messages in thread
From: Thomas, Rijo-john @ 2021-11-29 8:23 UTC (permalink / raw)
To: op-tee
[-- Attachment #1: Type: text/plain, Size: 1549 bytes --]
[Public]
Acked-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
-----Original Message-----
From: Dan Carpenter <dan.carpenter@oracle.com>
Sent: Wednesday, November 24, 2021 8:24 PM
To: Jens Wiklander <jens.wiklander@linaro.org>; Thomas, Rijo-john <Rijo-john.Thomas@amd.com>
Cc: Sumit Garg <sumit.garg@linaro.org>; Rangasamy, Devaraj <Devaraj.Rangasamy@amd.com>; Herbert Xu <herbert@gondor.apana.org.au>; Gary R Hook <gary.hook@amd.com>; 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.
Fixes: 757cc3e9ff1d ("tee: add AMD-TEE driver")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
drivers/tee/amdtee/core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/tee/amdtee/core.c b/drivers/tee/amdtee/core.c
index da6b88e80dc0..297dc62bca29 100644
--- a/drivers/tee/amdtee/core.c
+++ b/drivers/tee/amdtee/core.c
@@ -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;
}
--
2.20.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] tee: amdtee: fix an IS_ERR() vs NULL bug
[not found] <tencent_F4542B974E00912E031D1999D6D98F8C9006@qq.com>
@ 2021-11-29 8:54 ` Dan Carpenter
0 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2021-11-29 8:54 UTC (permalink / raw)
To: op-tee
[-- Attachment #1: Type: text/plain, Size: 446 bytes --]
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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] tee: amdtee: fix an IS_ERR() vs NULL bug
[not found] <=?utf-8?q?=3CCH0PR12MB5346CA4DBE99A795A1B6CA48CF669=40CH0PR12MB?= =?utf-8?q?5346=2Enamprd12=2Eprod=2Eoutlook=2Ecom=3E?=>
@ 2021-11-30 7:00 ` Jens Wiklander
0 siblings, 0 replies; 4+ messages in thread
From: Jens Wiklander @ 2021-11-30 7:00 UTC (permalink / raw)
To: op-tee
[-- Attachment #1: Type: text/plain, Size: 1837 bytes --]
On Mon, Nov 29, 2021 at 9:24 AM Thomas, Rijo-john
<Rijo-john.Thomas@amd.com> wrote:
>
> [Public]
>
> Acked-by: Rijo Thomas <Rijo-john.Thomas@amd.com>
>
> -----Original Message-----
> From: Dan Carpenter <dan.carpenter@oracle.com>
> Sent: Wednesday, November 24, 2021 8:24 PM
> To: Jens Wiklander <jens.wiklander@linaro.org>; Thomas, Rijo-john <Rijo-john.Thomas@amd.com>
> Cc: Sumit Garg <sumit.garg@linaro.org>; Rangasamy, Devaraj <Devaraj.Rangasamy@amd.com>; Herbert Xu <herbert@gondor.apana.org.au>; Gary R Hook <gary.hook@amd.com>; 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.
>
> Fixes: 757cc3e9ff1d ("tee: add AMD-TEE driver")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> drivers/tee/amdtee/core.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/tee/amdtee/core.c b/drivers/tee/amdtee/core.c
> index da6b88e80dc0..297dc62bca29 100644
> --- a/drivers/tee/amdtee/core.c
> +++ b/drivers/tee/amdtee/core.c
> @@ -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;
> }
Looks good, I'm picking up this.
Thanks,
Jens
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-11-30 7:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <tencent_F4542B974E00912E031D1999D6D98F8C9006@qq.com>
2021-11-29 8:54 ` [PATCH] tee: amdtee: fix an IS_ERR() vs NULL bug Dan Carpenter
[not found] <=?utf-8?q?=3CCH0PR12MB5346CA4DBE99A795A1B6CA48CF669=40CH0PR12MB?= =?utf-8?q?5346=2Enamprd12=2Eprod=2Eoutlook=2Ecom=3E?=>
2021-11-30 7:00 ` Jens Wiklander
2021-11-24 14:54 Dan Carpenter
2021-11-29 8:23 ` Thomas, Rijo-john
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox