Skip to contentSkip to conversation

tee: amdtee: fix an IS_ERR() vs NULL bug

PATCH In review Dan Carpenter 3 participants 4 messages Nov 24, 2021 – Nov 30, 2021 1 message not in the archive

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

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.

Fixes 757cc3e9ff1d ("tee: add AMD-TEE driver")
---
 drivers/tee/amdtee/core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tee/amdtee/core.c +2 -3
index da6b88e80dc0..297dc62bca29 100644
@@ -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
Acked-by on v1 1/1
#1 lore raw

[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.

Fixes 757cc3e9ff1d ("tee: add AMD-TEE driver")
---
 drivers/tee/amdtee/core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tee/amdtee/core.c +2 -3
index da6b88e80dc0..297dc62bca29 100644
@@ -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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw
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

#4 lore raw
In reply to Thomas, Rijo-john
Quoted 27 lines · Rijo-john

[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.

Fixes 757cc3e9ff1d ("tee: add AMD-TEE driver")
---
 drivers/tee/amdtee/core.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/tee/amdtee/core.c +0 -0
index da6b88e80dc0..297dc62bca29 100644
@@ -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