Protection of call stack
Abstract
A first memory page in a memory of the computer is allocated as a first stack to buffer meta data for function calls in the program. A memory protection key for the first memory page is generated. A second memory page in the memory is allocated as a second stack to buffer user data for function calls in the program.
Interactive Citation Constellation Global Citation Ranking
Interactive SVG Citation Constellation renders in Rust/WebAssembly. Prior art cited: 13 · Forward citations: 0.
Claims (19 — 3 Independent, 16 Dependent)
- Claim 1Independent Claim
A method for executing a program in a computer, comprising: allocating, by one or more processing units, a first memory page in a memory of the computer as a first stack to buffer function meta data for function calls of a function in the program; generating, by the one or more processing units, a memory protection key for the first memory page; and allocating, by the one or more processing units, a second memory page in the memory as a second stack to buffer function user data for the function calls of the function in the program, wherein the function is configured to call at least one callee function of the function and the allocating the first stack buffers meta data for the callee function and the allocating the second stack buffers user data for the function calls of the callee function.
- Claim 2Depends on #1
The method of claim 1, further comprising: in response to the function being invoked, obtaining, by the one or more processing units, via a prologue of the function, the memory protection key; and saving, by the one or more processing units, via the prologue of the function, meta data of the function to a stack frame in the first stack by using the memory protection key, the meta data comprising context information of a caller invoking the function.
- Claim 3Depends on #2
The method of claim 2, further comprising: storing, by the one or more processing units, user data of the function to a stack frame in the second stack, the user data being generated during execution of the function.
- Claim 4Depends on #3
The method of claim 3, further comprising: in response to the execution of the function being completed: obtaining, by the one or more processing units, via an epilogue of the function, the memory protection key; retrieving, by the one or more processing units, via the epilogue, the meta data of the function from a stack frame in the first stack by using the memory protection key; and restoring, by the one or more processing units, via the epilogue, the context information for the caller with the meta data.
- Claim 5Depends on #4
The method of claim 4, further comprising: releasing, by the one or more processing units, the stack frame in the first stack and a second stack frame in the second stack from the memory upon exiting of the function.
- Claim 6Depends on #1
The method of claim 1, wherein the first stack and the second stack are First-In Last Out stacks.
- Claim 7Depends on #1
The method of claim 1, wherein the memory protection key is used for a second function of the program.
- Claim 8Independent Claim
A system, comprising: one or more processors; and one or more computer-readable storage media storing program instructions which, when executed by the one or more processors, are configured to cause the one or more processors to perform the following operations: allocating a first memory page in a memory of a computer as a first stack to buffer function meta data for function calls of a function in the program; generating a memory protection key for the first memory page; and allocating a second memory page in the memory as a second stack to buffer function user data for the function calls of the function in the program, wherein the function is configured to call at least one callee function of the function and the allocating the first stack buffers meta data for the callee function and the allocating the second stack buffers user data for the function calls of the callee function.
- Claim 9Depends on #8
The system of claim 8, the program instructions being further configured to perform the following operations in response to the function being invoked: obtaining, via a prologue of the function, the memory protection key; and saving, via the prologue of the function, meta data of the function to a stack frame in the first stack by using the memory protection key, the meta data comprising context information of a caller invoking the function.
- Claim 10Depends on #9
The system of claim 9, the program instructions being further configured to perform the following operation: storing, by one or more processing units, user data of the function to a stack frame in the second stack, the user data being generated during execution of the function.
- Claim 11Depends on #10
The system of claim 10, the program instructions being further configured to perform the following operations in response to the execution of the function being completed: obtaining, via an epilogue of the function, the memory protection key; retrieving, via the epilogue, the meta data of the function from a stack frame in the first stack by using the memory protection key; and restoring, via the epilogue, the context information for the caller with the meta data.
- Claim 12Depends on #10
The system of claim 10, the program instructions being further configured to perform the following operation: releasing, via an epilogue of the function, the stack frame in the first stack and a second stack frame in the second stack from the memory upon exiting of the function.
- Claim 13Depends on #8
The system of claim 8, wherein the first stack and second stack are First-In Last Out stacks.
- Claim 14Independent Claim
A computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by processing means, so as to cause the processing means to perform the following operations: allocating a first memory page in a memory of the computer as a first stack to buffer function meta data for a first execution of function calls of a function in the program; generating a memory protection key for the first memory page; and allocating a second memory page in the memory as a second stack to buffer function user data for the first execution of the function calls of the function in the program.
- Claim 15Depends on #14
The computer program product of claim 14, the program instructions being further configured to cause the processing means perform the following operations in response to the function being invoked: obtaining, via a prologue of the function, the memory protection key; and saving, via the prologue of the function, meta data of the function to a stack frame in the first stack by using the memory protection key, the meta data comprising context information of a caller invoking the function.
- Claim 16Depends on #15
The computer program product of claim 15, the program instructions being further configured to cause the processing means perform the following operation: storing, by one or more processing units, user data of the function to a stack frame in the second stack, the user data being generated during execution of the function.
- Claim 17Depends on #16
The computer program product of claim 16, the program instructions being further configured to cause the processing means perform the following operations in response to the execution of the function being completed: obtaining, via an epilogue of the function, the memory protection key; retrieving, via the epilogue, the meta data of the function from a stack frame in the first stack by using the memory protection key; and restoring, via the epilogue, the context information for the caller with the meta data.
- Claim 18Depends on #16
The computer program product of claim 16, further configured to cause the processing means perform the following operation: releasing, via an epilogue of the function, the stack frame in the first stack and a second stack frame in the second stack from the memory upon exiting of the function.
- Claim 19Depends on #14
The computer program product of claim 14, wherein the first stack and second stack are First-In Last Out stacks.
Technical Overview & Description
BACKGROUND The present disclosure generally relates to memory security, and more specifically, to protection of call stack. Memory buffer overflow attack is a common threat to computer systems and especially to memory security. Buffer overflow attacks take advantage of the memory buffer configuration that both user data and meta data of an invoked function are stored in the same stack frame. If a function is invoked by a caller function in a program, the callee function may write over-sized data in user data segments of a stack frame. The writing of over-sized data will cause buffer overflow, overwriting meta data segments of the same stack frame. The meta data segments contain critical data, such as return address in the caller function. If the return address is overwritten by an address of a malicious application, the malicious application will take control of program flow. SUMMARY According to embodiments, disclosed are a method, system, and computer program product. According to one embodiment of the present disclosure, there is provided a method for executing a program in a computer, comprising: allocating a first memory page in a memory of the computer as a first stack to buffer meta data for function calls in the program; generating a memory protection key for the first memory page; and allocating a second memory page in the memory as a second stack to buffer user data for function calls in the program. According to another embodiment of the present disclosure, there is provided a system comprising one or more processors and one or more computer-readable storage media storing program instructions. The program instructions, when executed by the one or more processors, are configured to cause the one or more processors to perform the following operation: allocating a first memory page in a memory of the computer as a first stack to buffer meta data for function calls in the program; generating a memory protection key for the first memory page; and allocating a
Cited By — Indexed Forward Citations (0 of 0 total)
No indexed citing patents in this generation yet. Ingest USPTO/PatentsView bulk citation tables via patents-ingest to expand the local forward citation graph.
References Cited — Backward Prior Art (13)
Non-Patent Literature (10)
- Zhao et al.,
- “
- MPTEE: Bringing Flexible and Efficient Memory Protection to Intel SGX,
- ”
- EuroSys '20, Apr. 27-30, 2020, Heraklion, Greece, 15 pages, https://doi.org/10.1145/3342195.3387536.
- Jin et al.,
- “
- BoundShield: Comprehensive Mitigation for Memory Disclosure Attacks via Secret Region Isolation,
- ”
- IEEE Access, May 14, 2018, 13 pages, doi. 10.1109/ACCESS.2018.2835838.