Skip to content

__pthread_internal_remap_stack_with_mte: stop setting stack top guard to RW#67

Open
rdevshp wants to merge 1 commit intoGrapheneOS:16-qpr2from
rdevshp:mte_remap
Open

__pthread_internal_remap_stack_with_mte: stop setting stack top guard to RW#67
rdevshp wants to merge 1 commit intoGrapheneOS:16-qpr2from
rdevshp:mte_remap

Conversation

@rdevshp
Copy link
Copy Markdown

@rdevshp rdevshp commented May 5, 2026

pthread_create.cpp __allocate_thread_mapping does the following:

// Layout from the end of the mmap-ed region (before the top PTHREAD_GUARD_SIZE):
//
// [ PTHREAD_GUARD_SIZE ]
// [ libgen_buffers_padded_size (for dedicated page(s) for libgen buffers) ]
// [ static_tls_layout_size ]
// [ thread_page_size (for pthread_internal_t) ]
// [ gap_size (for (random) guard page(s)) ]
// [ stack_size ]
// [ stack_guard_size ]

ThreadMapping result = {};
result.mmap_base = space;
result.mmap_size = mmap_size;
result.mmap_base_unguarded = space + stack_guard_size;
result.mmap_size_unguarded = mmap_size - stack_guard_size - PTHREAD_GUARD_SIZE;

This means that after

mprotect(t->mmap_base_unguarded, t->mmap_size_unguarded,
                 PROT_READ | PROT_WRITE | PROT_MTE)

is executed in __pthread_internal_remap_stack_with_mte, the stack top guard is set to RW.
This PR proposes a fix for this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant