drm/amd/display: fix the system memory page fault because of copy overflow
Subsystems (3)
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.
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
@@ -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
[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.
--- 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
@@ -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
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 datafrom the stack to the heap
Signed-off-by Huang Rui <[email protected]>Cc Lee Jones <[email protected]>--- 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
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
-1if (!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
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 datafrom the stack to the heap
Signed-off-by Huang Rui <[email protected]>Cc Lee Jones <[email protected]>--- 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@@ -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
-1if (!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
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 datafrom the stack to the heap
Signed-off-by Huang Rui <[email protected]>Cc Lee Jones <[email protected]>--- 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
-0drivers/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
-1if (!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
[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.
--- 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
@@ -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&data=04%7C01%7CJiansong.Chen%40amd.com%7Caa1f0e0196584ac4145208d8b942ff50%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637463044695608478%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=OhlBMm03tg0JUctjpEtO88hL1Dnu5wxt7Keuojm61NQ%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
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 overflowThe 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 heapSigned-off-by Huang Rui <[email protected]>Cc Lee Jones <[email protected]>--- 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@@ -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&data=04%7C01%7CJiansong.Chen%40amd.com%7Caa1f0e0196584ac4145208d8b942ff50%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637463044695608478%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=OhlBMm03tg0JUctjpEtO88hL1Dnu5wxt7Keuojm61NQ%3D&reserved=0
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
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 datafrom the stack to the heap
Signed-off-by Huang Rui <[email protected]>Cc Lee Jones <[email protected]>--- 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
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
-1if (!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