public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] How to guard CAR's stack overflow
@ 2022-09-15  0:50 Tiger Liu(BJ-RD)
  2022-09-15  3:25 ` Ni, Ray
  0 siblings, 1 reply; 6+ messages in thread
From: Tiger Liu(BJ-RD) @ 2022-09-15  0:50 UTC (permalink / raw)
  To: devel@edk2.groups.io

[-- Attachment #1: Type: text/plain, Size: 665 bytes --]

Hi, Experts:
Usually, we use Cache As Ram to setup stack and heap for C language running environment before permanent memory has been initialized.

So, is there a method to guard this phase's stack overflow?

Note:
I find udk has introduced a method to guard stack overflow after memory has been initialized and discovered.

Thanks


?????
?????????????????????????????????????????????????????
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.

[-- Attachment #2: Type: text/html, Size: 3921 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [edk2-devel] How to guard CAR's stack overflow
@ 2022-09-22  3:32 Tiger Liu(BJ-RD)
  2022-09-22 21:06 ` Brian J. Johnson
  0 siblings, 1 reply; 6+ messages in thread
From: Tiger Liu(BJ-RD) @ 2022-09-22  3:32 UTC (permalink / raw)
  To: devel@edk2.groups.io, Ni, Ray, brian.johnson@hpe.com

[-- Attachment #1: Type: text/plain, Size: 3910 bytes --]

Hi, Johnson:
Thanks for your reply!

I tried and found it seemed causing some other problems.

It hang in eary pei stage.

It seems below code could also cause an exception if using expand-down mode in CAR phase’s stack established.
mov eax, ss:[ebx]
 mov eax, [ebp]
  mov eax, [esp]

Thanks
发件人: Brian J. Johnson <brian.johnson@hpe.com<mailto:brian.johnson@hpe.com>>
发送时间: 2022年9月20日 7:10
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; ray.ni@intel.com<mailto:ray.ni@intel.com>; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com<mailto:TigerLiu@zhaoxin.com>>
抄送: Fan, Jeff <fanjianfeng@byosoft.com.cn<mailto:fanjianfeng@byosoft.com.cn>>
主题: Re: [edk2-devel] How to guard CAR's stack overflow

You could also try modifying the Ia32 segment descriptors to mark the stack segment as an "expand down" type with a limit set just below the low end of the stack area.  That should generate a stack-fault exception if the stack overflows, and wouldn't require building page tables.  See sections 5.1 - 5.3 of the Intel SDM, volume 3.

Brian J. Johnson

________________________________
From: Ni, Ray [mailto:ray.ni@intel.com]
Sent: Wednesday, September 14, 2022, 10:25 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io><mailto:devel@edk2.groups.io>, tigerliu@zhaoxin.com<mailto:tigerliu@zhaoxin.com> <tigerliu@zhaoxin.com><mailto:tigerliu@zhaoxin.com>
Cc: Fan, Jeff <fanjianfeng@byosoft.com.cn><mailto:fanjianfeng@byosoft.com.cn>
Subject: [edk2-devel] How to guard CAR's stack overflow

It’s doable.
You need to enable paging and mark the very low 4K area of the stack as not-present.
You could use the UefiCpuPkg/Library/CpuPageTableLib to help you create the 1:1 page table with the specific
4K area as not-present (if you are using x86 processors).

Thanks,
Ray

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io><mailto:devel@edk2.groups.io> On Behalf Of Tiger Liu(BJ-RD)
Sent: Thursday, September 15, 2022 8:50 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Subject: [edk2-devel] How to guard CAR's stack overflow

Hi, Experts:
Usually, we use Cache As Ram to setup stack and heap for C language running environment before permanent memory has been initialized.

So, is there a method to guard this phase’s stack overflow?

Note:
I find udk has introduced a method to guard stack overflow after memory has been initialized and discovered.

Thanks

保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
_._,_._,_
________________________________
Groups.io Links:

You receive all messages sent to this group.

View/Reply Online (#93797)<https://edk2.groups.io/g/devel/message/93797> | | Mute This Topic<https://groups.io/mt/93691088/1761811> | New Topic<https://edk2.groups.io/g/devel/post>
Your Subscription<https://edk2.groups.io/g/devel/editsub/1761811> | Contact Group Owner<mailto:devel+owner@edk2.groups.io> | Unsubscribe<https://edk2.groups.io/g/devel/unsub> [brian.johnson@hpe.com<mailto:brian.johnson@hpe.com>]
_



保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.

[-- Attachment #2: Type: text/html, Size: 17897 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [edk2-devel] How to guard CAR's stack overflow
@ 2022-09-23  0:44 Tiger Liu(BJ-RD)
  0 siblings, 0 replies; 6+ messages in thread
From: Tiger Liu(BJ-RD) @ 2022-09-23  0:44 UTC (permalink / raw)
  To: Brian J. Johnson, devel@edk2.groups.io, Ni, Ray

[-- Attachment #1: Type: text/plain, Size: 6004 bytes --]

Hi, Johnson:
Thanks a lot.

Usually stack locates on top of heap area,
After swapping stack and heap’s location, your method seems ok.

Thanks
发件人: Brian J. Johnson <brian.johnson@hpe.com>
发送时间: 2022年9月23日 5:07
收件人: Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com>; devel@edk2.groups.io; Ni, Ray <ray.ni@intel.com>
主题: Re: [edk2-devel] How to guard CAR's stack overflow

I've never tried protecting the stack like this, so I'm not sure exactly what you're running in to.  The documentation says the base address is specified a bit differently for expand-down descriptors.  It needs to point to the page below the stack (lower addresses.)  The descriptors for the other segments would still need to cover the entire address space (limit 0xFFFF, page-granular, expand-up.)  And you'd need to use a different segment selector (and hence a different GDT entry) for the stack segment (ss register) than for the regular data segments.  Most of the early PEI code I've seen uses the same selector for ds, ef, fs, gs, and ss.

Hope that helps.  This is mostly theoretical.  I don't actually have a lot of experience with x86 segment programming.

Brian J. Johnson
________________________________
From: Tiger Liu(BJ-RD) [mailto:TigerLiu@zhaoxin.com]
Sent: Wednesday, September 21, 2022, 10:32 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io><mailto:devel@edk2.groups.io>, Ni, Ray <ray.ni@intel.com><mailto:ray.ni@intel.com>, brian.johnson@hpe.com<mailto:brian.johnson@hpe.com> <brian.johnson@hpe.com><mailto:brian.johnson@hpe.com>
Subject: [edk2-devel] How to guard CAR's stack overflow

Hi, Johnson:
Thanks for your reply!

I tried and found it seemed causing some other problems.

It hang in eary pei stage.

It seems below code could also cause an exception if using expand-down mode in CAR phase’s stack established.
mov eax, ss:[ebx]
 mov eax, [ebp]
  mov eax, [esp]

Thanks
发件人: Brian J. Johnson <brian.johnson@hpe.com<mailto:brian.johnson@hpe.com>
发送时间: 2022年9月20日 7:10
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; ray.ni@intel.com<mailto:ray.ni@intel.com>; Tiger Liu(BJ-RD) <TigerLiu@zhaoxin.com<mailto:TigerLiu@zhaoxin.com>
抄送: Fan, Jeff <fanjianfeng@byosoft.com.cn<mailto:fanjianfeng@byosoft.com.cn>
主题: Re: [edk2-devel] How to guard CAR's stack overflow

You could also try modifying the Ia32 segment descriptors to mark the stack segment as an "expand down" type with a limit set just below the low end of the stack area.  That should generate a stack-fault exception if the stack overflows, and wouldn't require building page tables.  See sections 5.1 - 5.3 of the Intel SDM, volume 3.

Brian J. Johnson

________________________________
From: Ni, Ray [mailto:ray.ni@intel.com]
Sent: Wednesday, September 14, 2022, 10:25 PM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io><mailto:devel@edk2.groups.io>, tigerliu@zhaoxin.com<mailto:tigerliu@zhaoxin.com> <tigerliu@zhaoxin.com><mailto:tigerliu@zhaoxin.com>
Cc: Fan, Jeff <fanjianfeng@byosoft.com.cn><mailto:fanjianfeng@byosoft.com.cn>
Subject: [edk2-devel] How to guard CAR's stack overflow

It’s doable.
You need to enable paging and mark the very low 4K area of the stack as not-present.
You could use the UefiCpuPkg/Library/CpuPageTableLib to help you create the 1:1 page table with the specific
4K area as not-present (if you are using x86 processors).

Thanks,
Ray

From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io><mailto:devel@edk2.groups.io> On Behalf Of Tiger Liu(BJ-RD)
Sent: Thursday, September 15, 2022 8:50 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
Subject: [edk2-devel] How to guard CAR's stack overflow

Hi, Experts:
Usually, we use Cache As Ram to setup stack and heap for C language running environment before permanent memory has been initialized.

So, is there a method to guard this phase’s stack overflow?

Note:
I find udk has introduced a method to guard stack overflow after memory has been initialized and discovered.

Thanks

保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.
_._,_._,_
________________________________
Groups.io Links:

You receive all messages sent to this group.

View/Reply Online (#93797)<https://edk2.groups.io/g/devel/message/93797> | | Mute This Topic<https://groups.io/mt/93691088/1761811> | New Topic<https://edk2.groups.io/g/devel/post>
Your Subscription<https://edk2.groups.io/g/devel/editsub/1761811> | Contact Group Owner<mailto:devel+owner@edk2.groups.io> | Unsubscribe<https://edk2.groups.io/g/devel/unsub> [brian.johnson@hpe.com<mailto:brian.johnson@hpe.com>]
_


保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.



保密声明:
本邮件含有保密或专有信息,仅供指定收件人使用。严禁对本邮件或其内容做任何未经授权的查阅、使用、复制或转发。
CONFIDENTIAL NOTE:
This email contains confidential or legally privileged information and is for the sole use of its intended recipient. Any unauthorized review, use, copying or forwarding of this email or the content of this email is strictly prohibited.

[-- Attachment #2: Type: text/html, Size: 23545 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-09-23  0:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-15  0:50 [edk2-devel] How to guard CAR's stack overflow Tiger Liu(BJ-RD)
2022-09-15  3:25 ` Ni, Ray
2022-09-19 23:09   ` Brian J. Johnson
  -- strict thread matches above, loose matches on Subject: below --
2022-09-22  3:32 Tiger Liu(BJ-RD)
2022-09-22 21:06 ` Brian J. Johnson
2022-09-23  0:44 Tiger Liu(BJ-RD)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox