Skip to content

[libc][startup] fix main thread TLS unmapped with wrong value #102009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

SchrodingerZhu
Copy link
Contributor

We have been unmapping a wrong address all the time.

munmap(0x704cffebb000, 41048)           = 0
munmap(0x704cffec6000, 69632)           = 0
munmap(0x704cffe9f000, 41048)           = 0
munmap(0x704cffeaa000, 69632)           = 0
munmap(0x704cffe83000, 41048)           = 0
munmap(0x704cffe8e000, 69632)           = 0
munmap(0x704cffe67000, 41048)           = 0
munmap(0x704cffe72000, 69632)           = 0
munmap(0x704cffe4b000, 41048)           = 0
munmap(0x704cffe56000, 69632)           = 0
munmap(0x704cffe2f000, 41048)           = 0
munmap(0x704cffe3a000, 69632)           = 0
munmap(0x704cfff51028, 41048)           = -1 EINVAL (Invalid argument)

@llvmbot
Copy link
Member

llvmbot commented Aug 5, 2024

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

We have been unmapping a wrong address all the time.

munmap(0x704cffebb000, 41048)           = 0
munmap(0x704cffec6000, 69632)           = 0
munmap(0x704cffe9f000, 41048)           = 0
munmap(0x704cffeaa000, 69632)           = 0
munmap(0x704cffe83000, 41048)           = 0
munmap(0x704cffe8e000, 69632)           = 0
munmap(0x704cffe67000, 41048)           = 0
munmap(0x704cffe72000, 69632)           = 0
munmap(0x704cffe4b000, 41048)           = 0
munmap(0x704cffe56000, 69632)           = 0
munmap(0x704cffe2f000, 41048)           = 0
munmap(0x704cffe3a000, 69632)           = 0
munmap(0x704cfff51028, 41048)           = -1 EINVAL (Invalid argument)

Full diff: https://github.com/llvm/llvm-project/pull/102009.diff

1 Files Affected:

  • (modified) libc/startup/linux/do_start.cpp (+1-1)
diff --git a/libc/startup/linux/do_start.cpp b/libc/startup/linux/do_start.cpp
index 824c0e1cf8f26..72060b4adb214 100644
--- a/libc/startup/linux/do_start.cpp
+++ b/libc/startup/linux/do_start.cpp
@@ -133,7 +133,7 @@ static ThreadAttributes main_thread_attrib;
   // We register the cleanup_tls function to be the last atexit callback to be
   // invoked. It will tear down the TLS. Other callbacks may depend on TLS (such
   // as the stack protector canary).
-  atexit([]() { cleanup_tls(tls.tp, tls.size); });
+  atexit([]() { cleanup_tls(tls.addr, tls.size); });
   // We want the fini array callbacks to be run after other atexit
   // callbacks are run. So, we register them before running the init
   // array callbacks as they can potentially register their own atexit

@SchrodingerZhu SchrodingerZhu merged commit 72c9e24 into llvm:main Aug 5, 2024
6 of 7 checks passed
@SchrodingerZhu SchrodingerZhu deleted the libc/fix-tls-leakage branch August 5, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants