Questions tagged [stack]

42 questions
21
votes
3 answers

How does stack allocation work in Linux?

Does the OS reserve the fixed amount of valid virtual space for stack or something else? Am I able to produce a stack overflow just by using big local variables? I've wrote a small C program to test my assumption. It's running on X86-64 CentOS…
Amos
  • 472
  • 1
  • 4
  • 14
20
votes
2 answers

What sets fs:[0x28] (stack canary)?

From this post it is shown that FS:[0x28] is a stack-canary. I'm generating that same code using GCC on this function, void foo () { char a[500] = {}; printf("%s", a); } Specifically, I'm getting this assembly.. 0x000006b5 …
Evan Carroll
  • 28,578
  • 45
  • 164
  • 290
14
votes
2 answers

Why on modern Linux, the default stack size is so huge - 8MB (even 10 on some distributions)

For example, on OSX, it's even less than 512k. Is there any recommended size, having in mind, that the app does not use recursion and does not allocate a lot of stack variables? I know the question is too broad and it highly depends on the usage,…
Kiril Kirov
  • 287
  • 1
  • 3
  • 10
12
votes
1 answer

How can I monitor per process/per thread memory consumption (divided into heap, stack, data, code)?

Before jumping in and writing my own code, I want to find out if there is GNU/Linux software that is able to output something similar to QNX's showmem. For each thread of each process that is running, I would like to see the memory consumption…
Alex Dima
  • 121
  • 1
  • 1
  • 5
10
votes
2 answers

How does the ELF loader determine the initial stack size?

I'm studying the ELF specification (http://www.skyfree.org/linux/references/ELF_Format.pdf), and one point that is not clear to me about the program loading process is how the stack is initialized, and what the initial page size is. Here's the test…
Mario Carneiro
  • 225
  • 2
  • 9
5
votes
1 answer

Why does bash's tab completion trigger the stack protector?

I'm using bash 5.0.16 (and bash-completion 2.10) on Manjaro. Today, I absentmindedly hit the tab key while moving some files, and was greeted with an unexpected message: [charles@wirepile some_dir]$ mv ~down*** stack smashing detected ***:
4
votes
2 answers

Why is the stack argument required for the clone wrapper?

I've been carefully reading the linux man page for clone(), and I understand the difference between the clone() wrapper and the "raw" system call. But what I don't understand is why the parent process needs to allocate a stack for the child, even if…
exliontamer
  • 137
  • 6
4
votes
1 answer

program stack size

I learned default stack size for each process is limited to 8MB and mmap_base is calculated based on stack size in rlimit and random value. Code below is mmap_base function which calculates mmap_base address in…
JuHyung Son
  • 197
  • 3
  • 10
4
votes
2 answers

Memory Randomization in Linux

I created a simple C program and every time I load it in GDB, I see the same memory addresses allocated to the instructions of the program. For example, a function what() always loads at memory location 0x000055555555472d. In fact the stack is…
7_R3X
  • 1,134
  • 2
  • 14
  • 28
3
votes
1 answer

Unlimited stack size with pthreads

My default stack size (according to ulimit -s) is 8192 kB, so naturally the code below segfaults when I try to run it. Also, naturally, it works fine if I do a 'ulimit -s 9000'. However, when I do a 'ulimit -s unlimited' the code segfaults again.…
user3856370
  • 237
  • 2
  • 8
3
votes
1 answer

Are stack canaries shared via threads?

As far as I understand, stack canaries work as fllows: Upon program startup a random value is generated and stored in the thread local storage (%fs:0x28). This random value is then pushed onto the stack in each function call to be checked against…
2
votes
1 answer

Is it safe to use the .bss section as a static stack?

(This is in the context of x86-64 Linux.) I am trying to write a high-reliability userland executable, and I have total control over the generated assembly. I don't want to rely on automatic stack allocation, so I would like to put the stack in a…
Mario Carneiro
  • 225
  • 2
  • 9
2
votes
1 answer

pstack not printing stack output

I am running pstack to find function stack for my application running on two machines (both RHEL) In one of my machine it is working as expected [root@civ4cez191 bin]# pstack 22947 Thread 2 (Thread 0x7f63cbe7d700 (LWP 22949)): #0 0x0000003c3640f0cd…
Gaurav
  • 121
  • 1
  • 5
2
votes
0 answers

How can I find the deepest and most stack-hungry call chains in a program?

I have a program written in OCaml that tends to stack-overflow on platforms with small stacks. Rather than ulimiting the program to find and solve stack overflows one by one, I'd like to get a sorted list of the deepest (and/or most stack-hungry)…
Clément
  • 552
  • 1
  • 4
  • 12
2
votes
1 answer

Why must the stack VMA be executable?

I am currently reading Linux Kernel Development by Robert Love. In the chapter "15 The Process Address Space" he prints the memory map of a process. user@machine:~$ pmap 1424 #all the processes mapped memory (skipped for readability) bfffe000 (8KB) …
JDurstberger
  • 135
  • 6
1
2 3