Skip to contentSkip to conversation

drm/amd/display: fix the system memory page fault because of copy overflow

PATCH In review Huang Rui 5 participants 8 messages Jan 15, 2021

Subsystems (3)
lore
Share & tools
lore

Huang Rui

author
#0 lore raw

PATCH 1/1 drm/amd/display: fix the system memory page fault because of copy overflow

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data

from the stack to the heap

---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index 69573d67056d..73178978ae74 100644
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
 	DC_LOGGER_INIT(dc_ctx->logger);
 
-	info = kzalloc(sizeof(info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
 	if (!info)
 		goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
 	}
 
 	if (bios->integrated_info)
-		memcpy(info, bios->integrated_info, sizeof(*info));
+		memcpy(info, bios->integrated_info, sizeof(struct integrated_info));
 
 	/* Look for channel mapping corresponding to connector and device tag */
 	for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
Signature · 6 lines
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by on v1 1/1
#1 lore raw

[AMD Official Use Only - Internal Distribution Only]

Regards,
Joe

-----Original Message-----
From: Huang, Ray <[email protected]>
Sent: Saturday, January 16, 2021 2:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Su, Jinzhou (Joe) <[email protected]>; Zhu, Changfeng <[email protected]>; Huang, Ray <[email protected]>; Lee Jones <[email protected]>
Subject: [PATCH] drm/amd/display: fix the system memory page fault because of copy overflow

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data from the stack to the heap
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index 69573d67056d..73178978ae74 100644
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
 	DC_LOGGER_INIT(dc_ctx->logger);
 
-	info = kzalloc(sizeof(info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
 	if (!info)
 		goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
 	}
 
 	if (bios->integrated_info)
-		memcpy(info, bios->integrated_info, sizeof(*info));
+		memcpy(info, bios->integrated_info, sizeof(struct integrated_info));
 
 	/* Look for channel mapping corresponding to connector and device tag */
 	for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {

--
2.25.1
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#2 lore raw
In reply to Huang Rui

Am 15.01.21 um 19:46 schrieb Huang Rui:

Quoted 18 lines

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data

from the stack to the heap

---
  drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -0
index 69573d67056d..73178978ae74 100644

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1383

Quoted 5 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -1
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
  	DC_LOGGER_INIT(dc_ctx->logger);
 
-	info = kzalloc(sizeof(info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);

That should probably be sizeof(*info) instead, we usually try to avoid sizeof(struct ...) in the kernel.

There are some automated scripts in place which will send you a patch to change it otherwise.

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1548

Quoted 9 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -1
  	if (!info)
  		goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
  	}
 
  	if (bios->integrated_info)
-		memcpy(info, bios->integrated_info, sizeof(*info));
+		memcpy(info, bios->integrated_info, sizeof(struct integrated_info));

This can then also stay as it is.

Apart from that good catch.

Regards,
Christian.

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1551

Quoted 3 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -0
  	/* Look for channel mapping corresponding to connector and device tag */
  	for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#3 lore raw
Quoted 22 lines · Christian König

Am 15.01.21 um 19:46 schrieb Huang Rui:

Quoted 21 lines

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data

from the stack to the heap

---
  drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -0
index 69573d67056d..73178978ae74 100644
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
  	DC_LOGGER_INIT(dc_ctx->logger);
 
Quoted 8 lines

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1383

Quoted 2 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -1
-	info = kzalloc(sizeof(info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);

That should probably be sizeof(*info) instead, we usually try to avoid sizeof(struct ...) in the kernel.

There are some automated scripts in place which will send you a patch to change it otherwise.

No problem, just check in the patch before because of urgent fix. I will file another patch to modify this.

Thanks,
Ray

Quoted 13 lines

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1548

Quoted 10 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -1
  	if (!info)
  		goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
  	}
 
  	if (bios->integrated_info)
-		memcpy(info, bios->integrated_info, sizeof(*info));
+		memcpy(info, bios->integrated_info, sizeof(struct integrated_info));

This can then also stay as it is.

Quoted 9 lines

Apart from that good catch.

Regards,
Christian.

Quoted 3 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -0
  	/* Look for channel mapping corresponding to connector and device tag */
  	for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#4 lore raw
In reply to Christian König
Quoted 39 lines · Christian König

Am 15.01.21 um 19:46 schrieb Huang Rui:

Quoted 18 lines

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data

from the stack to the heap

---
  drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -0
index 69573d67056d..73178978ae74 100644

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1381

Quoted 3 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -1
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
  	DC_LOGGER_INIT(dc_ctx->logger);
-	info = kzalloc(sizeof(info), GFP_KERNEL);
+	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);

That should probably be sizeof(*info) instead, we usually try to avoid sizeof(struct ...) in the kernel.

There are some automated scripts in place which will send you a patch to change it otherwise.

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1547

Quoted 7 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -1
  	if (!info)
  		goto create_fail;
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
  	}
  	if (bios->integrated_info)
-		memcpy(info, bios->integrated_info, sizeof(*info));
+		memcpy(info, bios->integrated_info, sizeof(struct integrated_info));

This can then also stay as it is.

Quoted 1 line

Apart from that good catch.

Yes, agreed.

Sorry for the fuss.

Signature · 8 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#5 lore raw
In reply to Huang Rui

[AMD Public Use]

Hi Rui,
Seems the change has violated the kernel coding style😊, please help check.
https://www.kernel.org/doc/html/latest/process/coding-style.html

Allocating memory
......
The preferred form for passing a size of a struct is the following:

p = kmalloc(sizeof(*p), ...);
The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.

Regards,
Jiansong
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Huang Rui
Sent: Saturday, January 16, 2021 2:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Su, Jinzhou (Joe) <[email protected]>; Huang, Ray <[email protected]>; Lee Jones <[email protected]>; Zhu, Changfeng <[email protected]>
Subject: [PATCH] drm/amd/display: fix the system memory page fault because of copy overflow

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data from the stack to the heap
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -2
index 69573d67056d..73178978ae74 100644
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
 DC_LOGGER_INIT(dc_ctx->logger);
 
-info = kzalloc(sizeof(info), GFP_KERNEL);
+info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
 if (!info)
 goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
 }
 
 if (bios->integrated_info)
-memcpy(info, bios->integrated_info, sizeof(*info));
+memcpy(info, bios->integrated_info, sizeof(struct integrated_info));
 
 /* Look for channel mapping corresponding to connector and device tag */
 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {

--
2.25.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CJiansong.Chen%40amd.com%7Caa1f0e0196584ac4145208d8b942ff50%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637463044695608478%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=OhlBMm03tg0JUctjpEtO88hL1Dnu5wxt7Keuojm61NQ%3D&amp;reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

author
#6 lore raw
Quoted 6 lines · Jiansong (Simon)

[AMD Public Use]

Hi Rui,
Seems the change has violated the kernel coding style😊, please help check.
https://www.kernel.org/doc/html/latest/process/coding-style.html

Quoted 6 lines

Allocating memory
......
The preferred form for passing a size of a struct is the following:

p = kmalloc(sizeof(*p), ...);
The alternative form where struct name is spelled out hurts readability and introduces an opportunity for a bug when the pointer variable type is changed but the corresponding sizeof that is passed to a memory allocator is not.

Yes, I see. Thanks.

Ray

Quoted 45 lines

Regards,
Jiansong
-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Huang Rui
Sent: Saturday, January 16, 2021 2:47 AM
To: [email protected]
Cc: Deucher, Alexander <[email protected]>; Su, Jinzhou (Joe) <[email protected]>; Huang, Ray <[email protected]>; Lee Jones <[email protected]>; Zhu, Changfeng <[email protected]>
Subject: [PATCH] drm/amd/display: fix the system memory page fault because of copy overflow

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data from the stack to the heap
---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +2 -3
index 69573d67056d..73178978ae74 100644
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
 DC_LOGGER_INIT(dc_ctx->logger);
 
-info = kzalloc(sizeof(info), GFP_KERNEL);
+info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);
 if (!info)
 goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
 }
 
 if (bios->integrated_info)
-memcpy(info, bios->integrated_info, sizeof(*info));
+memcpy(info, bios->integrated_info, sizeof(struct integrated_info));
 
 /* Look for channel mapping corresponding to connector and device tag */
 for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
--

2.25.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Famd-gfx&amp;data=04%7C01%7CJiansong.Chen%40amd.com%7Caa1f0e0196584ac4145208d8b942ff50%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637463044695608478%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=OhlBMm03tg0JUctjpEtO88hL1Dnu5wxt7Keuojm61NQ%3D&amp;reserved=0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#7 lore raw
In reply to Huang Rui
Quoted 18 lines · Huang Rui

The buffer is allocated with the size of pointer and copy with the size of data structure. Then trigger the system memory page fault. Use the orignal data structure to get the object size.

Fixes a8e30005b drm/amd/display/dc/core/dc_link: Move some local data

from the stack to the heap

---
 drivers/gpu/drm/amd/display/dc/core/dc_link.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -0
index 69573d67056d..73178978ae74 100644

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1383

Quoted 4 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -1
@@ -1380,7 +1380,7 @@ static bool dc_link_construct(struct dc_link *link,
 
 	DC_LOGGER_INIT(dc_ctx->logger);
 
-	info = kzalloc(sizeof(info), GFP_KERNEL);

Ah sorry, this should be (*info).

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1383

Quoted 1 line
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -0
+	info = kzalloc(sizeof(struct integrated_info), GFP_KERNEL);

Using the full name like this is usually discouraged.

drivers/gpu/drm/amd/display/dc/core/dc_link.c static bool dc_link_construct(struct dc_link *link, · line 1548

Quoted 8 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +0 -1
 	if (!info)
 		goto create_fail;
 
@@ -1545,7 +1545,7 @@ static bool dc_link_construct(struct dc_link *link,
 	}
 
 	if (bios->integrated_info)
-		memcpy(info, bios->integrated_info, sizeof(*info));

This should be correct.

Quoted 4 lines
drivers/gpu/drm/amd/display/dc/core/dc_link.c +1 -0
+		memcpy(info, bios->integrated_info, sizeof(struct integrated_info));
 
 	/* Look for channel mapping corresponding to connector and device tag */
 	for (i = 0; i < MAX_NUMBER_OF_EXT_DISPLAY_PATH; i++) {
Signature · 8 lines
Lee Jones [李琼斯]
Senior Technical Lead - Developer Services
Linaro.org │ Open source software for Arm SoCs
Follow Linaro: Facebook | Twitter | Blog
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx