Can a posix thread modify another thread's stack variable within the same program ?


  • 0
    M

    Is it possible for one thread to corrupt the stack of another thread by directly modifying the stack address ? How are thread local variables implemented to provide access safety ?


  • 0
    M
    This post is deleted!

  • 0
    J

    of course.
    But the child threads stack is different from main thread.
    Child Threads' statck consists of the VMA got from mmap. And the it's protected by mprotect(NONE) when segmentfault
    main thread's stack is protected by kernel when segmentfault.


  • 0

    Nope, all threads share a common heap, however, each thread has a private stack, and a red zone is appended for each stack


  • 0
    R

    Since each thread has individual stack space, it is not possible to modify another thread's stack variable. Each stack is protected by a boundary and it also stores the start address, current stack pointer and few other information-variables location at the edge. which protects the another thread's stackoverflow modifying stack variables.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.