{"abstract":null,"author":"Mark Esler","content":"The same C source gets a stack canary (a guard value checked before a function returns) or not, depending on the image that builds it. chard 0.2.1 read what gcc and clang apply at -O2 with no other flags on 2026-11-29 across 414 configurations: distributions\u0026rsquo; own images, containers, Oracle Cloud images, GitHub\u0026rsquo;s runners, and the build images (manylinux, CI vendors\u0026rsquo; images). Code You Build Yourself Gets the Compiler\u0026rsquo;s Defaults, Not the Distribution\u0026rsquo;s Flags has the method and what four distributions\u0026rsquo; package builds pass beside it.\nThe build images Of 37 build-image configurations (one per image, architecture and build invocation), 24 emit no stack canary. The manylinux images (2014, 2_28 and 2_34, on x86_64 and aarch64) apply no stack canary, no _FORTIFY_SOURCE (bounds-checked libc calls; chard reads it unsupported on 2014 and AWS CodeBuild) and no stack-clash protection, and get only partial RELRO (lazy-binding GOT entries stay writable), with or without CPython\u0026rsquo;s recorded flags. The same holds for the compilers in Docker\u0026rsquo;s official gcc images, GitLab.com\u0026rsquo;s default ruby:3.1 CI image and AWS CodeBuild\u0026rsquo;s standard:6.0 and standard:4.0 images.\nFour images apply a canary, _FORTIFY_SOURCE and stack-clash protection: CircleCI\u0026rsquo;s cimg/base, Heroku\u0026rsquo;s build image, Google\u0026rsquo;s buildpacks builder and GitHub\u0026rsquo;s ubuntu-slim. All four ship Ubuntu 24.04\u0026rsquo;s gcc 13.3.0, whose defaults turn these on. Their shared objects, which is what a wheel holds, still get partial RELRO. On GitHub\u0026rsquo;s hosted Ubuntu runners gcc and clang differ: gcc applies the canary and stack-clash protection on every runner; clang applies no canary, and no stack-clash protection on the five runners where chard reads it. PyPA\u0026rsquo;s musllinux_1_2 images, on Alpine\u0026rsquo;s gcc, emit a canary and full RELRO, shared objects included.\nThe wheels of the 100 most-downloaded PyPI projects that ship a compiled manylinux x86_64 wheel were read with readelf on 2026-11-28; 76 of them also ship a musllinux_1_2 wheel of the same release.\nProjects among the 100 manylinux wheel musllinux wheel ship the wheel 100 76 with non-Rust compiled files of their own 79 61 full RELRO in all of those files 1 of 79 61 of 61 a stack canary in at least one 13 of 79 60 of 61 The rest ship only Rust files, which read full RELRO on both images and import no stack canary; only RELRO and the canary were read. The canary row is a lower bound: a file with no array or address-taken local on its stack imports none. chard did not measure a flag\u0026rsquo;s cost. The current reading for every image is at chard.page.\nThe images inherit their compilers. manylinux2014 is based on CentOS 7 and manylinux_2_28 and 2_34 on AlmaLinux 8 and 9, with Red Hat\u0026rsquo;s toolset compilers; Enterprise Linux hardens its own packages through the package build, so its compiler alone applies no canary, no fortify, no stack-clash protection and only partial RELRO. musllinux is based on Alpine, whose gcc applies a canary and full RELRO itself. Apart from Rust, the wheels mostly carry what the image\u0026rsquo;s upstream compiler applies: 1 of 79 projects\u0026rsquo; manylinux wheels has full RELRO in its non-Rust files, against 61 of 61 on musllinux.\nProof of concept: one wheel, two builds The extension pocdemo has three deliberate bugs, each tied to one flag: a stack buffer overflow (strcpy into a 16-byte buffer), an oversized copy into a known-size buffer (memcpy), and a read of an uninitialized stack variable (one call plants 42 on the stack, the next reads it back). It was built as a manylinux wheel twice (cibuildwheel, the manylinux_2_34 image, setuptools, auditwheel repair), changing nothing but the flags passed through CIBW_ENVIRONMENT. The PoC is not published. chard reads what ended up in each binary:\ncanary fortify RELRO CET (control-flow marking, -fcf-protection) default no none partial no with six of the OpenSSF guide\u0026rsquo;s flags yes __memcpy_chk, __strcpy_chk full yes Installed in a clean CPython 3.13 and called the same way:\ncall default wheel hardened wheel pocdemo.overflow(b\u0026quot;B\u0026quot;*64) segfault; gdb shows the return address overwritten with 0x4242424242424242 *** buffer overflow detected ***, aborted pocdemo.fortify_copy(64) segfault *** buffer overflow detected ***, aborted pocdemo.uninit() 42, left by the previous call 0 Only the flags differ, and they are off by default. With _FORTIFY_SOURCE=3 on, fortify aborts the two overflows at the copy, before the function returns.\nImpact Scope. Defaults being off does not show a wheel is exploitable: that takes a memory-safety bug in the extension and input that reaches it. What the defaults decide is how much a bug, if one exists, gives an attacker. The PoC\u0026rsquo;s bugs are planted.\nThe manylinux images apply no canary, fortify or stack-clash protection by default. In the PoC wheel\u0026rsquo;s default build a stack overflow overwrites the saved return address with the input\u0026rsquo;s bytes; in the hardened build fortify aborts the copy before the return. The remaining mitigations, full RELRO and CET marking, are partial, off or unsupported in those images (per chard). An uninitialized-stack leak that defeats ASLR (address randomization), such as CVE-2024-12085 in rsync (Ubuntu\u0026rsquo;s advisory), is mitigated by a default-off flag, -ftrivial-auto-var-init=zero (Chainguard). Wolfi\u0026rsquo;s default toolchain is the only measured one that initializes stack variables by default. Wheels built on these images install in production and in the CI and build systems that hold credentials and publish artifacts. The fix A request that the manylinux images enable hardening by default, pypa/manylinux#59, has been open since 2016-04-28. A project can opt in. On x86_64 manylinux_2_28 and 2_34 (the PoC used 2_34), a project can set six of the OpenSSF guide\u0026rsquo;s flags through cibuildwheel:\nCIBW_ENVIRONMENT_LINUX=\u0026#39;CFLAGS=\u0026#34;-O3 -DNDEBUG -fno-strict-overflow -fstack-protector-strong -D_FORTIFY_SOURCE=3 -fstack-clash-protection -fcf-protection=full -ftrivial-auto-var-init=zero\u0026#34; LDFLAGS=\u0026#34;-Wl,-z,relro,-z,now\u0026#34;\u0026#39; Setting CFLAGS replaces CPython\u0026rsquo;s own, so the recipe repeats the ones that change the code (-O3 -DNDEBUG -fno-strict-overflow); add back anything else the project relies on. On aarch64, use -mbranch-protection=standard for -fcf-protection=full; manylinux2014\u0026rsquo;s gcc 10 has no -ftrivial-auto-var-init. auditwheel repair keeps your objects\u0026rsquo; flags, so the repaired wheel is the hardened wheel in the table.\nA default in the manylinux images\u0026rsquo; gcc reaches every wheel built on them; a protection in the flags recorded by their CPython builds reaches every build that sets no CFLAGS of its own. Either shows in the image\u0026rsquo;s rows on chard.page.\nCheck your own Look up your CI or wheel image on chard.page, or run chard on it. If it emits no canary, set the flags above (and CXXFLAGS for C++); the OpenSSF guide lists the rest, with the compiler version each needs. Check that the repaired wheel\u0026rsquo;s .so imports __stack_chk_fail (not every extension does).\nEvery musllinux wheel read here has full RELRO; Alpine\u0026rsquo;s gcc applies it with no flag. The companion measurement reads what each distribution\u0026rsquo;s compiler applies on its own.\n","date":"2026-11-30","description":"Python wheels inherit the hardening of the compiler in their build image. manylinux's Enterprise Linux toolchain applies no canary, fortify or stack-clash protection; musllinux's Alpine gcc applies a canary and full RELRO. Not counting Rust, 1 of 79 of the most-downloaded projects' manylinux wheels has full RELRO; on musllinux, 61 of 61 do.","lastmod":"2026-11-30","readingTime":6,"section":"datagrams","title":"Python Wheels Inherit Their Build Image's Hardening","url":"https://hexproof.dev/datagrams/build-images-stack-canary/","wordCount":1091}