Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to make the Linux process run on the fixed heap

Shulou Source: shulou.com Published: 2022-06-02 06:47:52 10月01日 Update

This article focuses on "how to make the Linux process run in a fixed heap". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to make the Linux process run on a fixed heap.

We know that the address of the program is different every time it runs, and the reason why linux has such a design may be for security reasons, which is not conducive to hackers' attacks.

Let's look at a simple program:

# include

# include

Int main (int argc, char* argv [])

{

Int first = 0

Int * p = malloc (1024)

Printf ("paired% p\ n", p)

Return 0

}

Obviously, the address of the program is different every time!

Is there any way to make the same program run at the same address every time?

When you see here, you may ask why you let the program run at the same address every time. Does this not go against the original intention of OS design? Yes, this does go against the original intention of the linux kernel design. However, it is inevitable that strange requirements will not be encountered in the actual project. For example, some app needs to be run on the specified address due to historical reasons, so you need to turn off the randomization of the address space. For example, if you encounter a random address crash problem, you can also use this method to debug.

To cut the crap, let's take a look at the way address space is randomized and turned off.

Echo 0 > / proc/sys/kernel/randomize_va_space

Or

Sudo sysctl-w kernel.randomize_va_space=0

After turning it off, let's take a look at the test results of the program:

At this point, I believe you have a deeper understanding of "how to make the Linux process run on the fixed heap". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Run address program process method design content original intention actual space learning practical deeper same security this is not the reason interest kernel method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno Linux Shulou Technology Apple