Skip to content

Commit 4deb69c

Browse files
committed
[3.13] gh-151544: Fixes CVE-2026-12003 by removing the fallback to %VPATH%/Modules/Setup.local for discovering sources in getpath.py (GH-151545)
1 parent 3e25640 commit 4deb69c

5 files changed

Lines changed: 14 additions & 12 deletions

File tree

.github/workflows/reusable-wasi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ubuntu-24.04
1616
timeout-minutes: 60
1717
env:
18-
WASMTIME_VERSION: 22.0.0
18+
WASMTIME_VERSION: 38.0.3
1919
WASI_SDK_VERSION: 24
2020
WASI_SDK_PATH: /opt/wasi-sdk
2121
CROSS_BUILD_PYTHON: cross-build/build

Makefile.pre.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,6 +1452,8 @@ Programs/_bootstrap_python.o: Programs/_bootstrap_python.c $(BOOTSTRAP_HEADERS)
14521452
_bootstrap_python: $(LIBRARY_OBJS_OMIT_FROZEN) Programs/_bootstrap_python.o Modules/getpath.o Modules/Setup.local
14531453
$(LINKCC) $(PY_LDFLAGS_NOLTO) -o $@ $(LIBRARY_OBJS_OMIT_FROZEN) \
14541454
Programs/_bootstrap_python.o Modules/getpath.o $(LIBS) $(MODLIBS) $(SYSLIBS)
1455+
# Dummy pybuilddir.txt is needed for _bootstrap_python to be runnable
1456+
@echo "none" > ./pybuilddir.txt
14551457

14561458

14571459
############################################################################
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
:file:`Modules/Setup.local` is no longer used as a landmark to discover
2+
whether Python is running in a source tree, as it could potentially affect
3+
actual installs. The :file:`pybuilddir.txt` file is now the sole indicator
4+
of running in a source tree.

Modules/getpath.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@
129129
# checked by looking for the BUILDDIR_TXT file, which contains the
130130
# relative path to the platlib dir. The executable_dir value is
131131
# derived from joining the VPATH preprocessor variable to the
132-
# directory containing pybuilddir.txt. If it is not found, the
133-
# BUILD_LANDMARK file is found, which is part of the source tree.
132+
# directory containing pybuilddir.txt.
134133
# prefix is then found by searching up for a file that should only
135134
# exist in the source tree, and the stdlib dir is set to prefix/Lib.
136135

@@ -177,7 +176,6 @@
177176

178177
if os_name == 'posix' or os_name == 'darwin':
179178
BUILDDIR_TXT = 'pybuilddir.txt'
180-
BUILD_LANDMARK = 'Modules/Setup.local'
181179
DEFAULT_PROGRAM_NAME = f'python{VERSION_MAJOR}'
182180
STDLIB_SUBDIR = f'{platlibdir}/python{VERSION_MAJOR}.{VERSION_MINOR}{ABI_THREAD}'
183181
STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}/os.py', f'{STDLIB_SUBDIR}/os.pyc']
@@ -190,7 +188,6 @@
190188

191189
elif os_name == 'nt':
192190
BUILDDIR_TXT = 'pybuilddir.txt'
193-
BUILD_LANDMARK = f'{VPATH}\\Modules\\Setup.local'
194191
DEFAULT_PROGRAM_NAME = f'python'
195192
STDLIB_SUBDIR = 'Lib'
196193
STDLIB_LANDMARKS = [f'{STDLIB_SUBDIR}\\os.py', f'{STDLIB_SUBDIR}\\os.pyc']
@@ -500,13 +497,9 @@ def search_up(prefix, *landmarks, test=isfile):
500497
platstdlib_dir = real_executable_dir
501498
build_prefix = joinpath(real_executable_dir, VPATH)
502499
except (FileNotFoundError, PermissionError):
503-
if isfile(joinpath(real_executable_dir, BUILD_LANDMARK)):
504-
build_prefix = joinpath(real_executable_dir, VPATH)
505-
if os_name == 'nt':
506-
# QUIRK: Windows builds need platstdlib_dir to be the executable
507-
# dir. Normally the builddir marker handles this, but in this
508-
# case we need to correct manually.
509-
platstdlib_dir = real_executable_dir
500+
# We used to check for an alternate landmark here, but now we require
501+
# BUILDDIR_TXT to exist. (gh-151544; CVE-2026-12003)
502+
pass
510503

511504
if build_prefix:
512505
if os_name == 'nt':

Tools/wasm/wasi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def configure_wasi_python(context, working_dir):
255255
"ENV_VAR_NAME": "PYTHONPATH",
256256
"ENV_VAR_VALUE": f"/{sysconfig_data}",
257257
"PYTHON_WASM": working_dir / "python.wasm",
258+
"ARGV0": wasi_build_dir / "python.wasm",
258259
}
259260
# Check dynamically for wasmtime in case it was specified manually via
260261
# `--host-runner`.
@@ -344,6 +345,8 @@ def main():
344345
"--wasm max-wasm-stack=8388608 "
345346
# Use WASI 0.2 primitives.
346347
"--wasi preview2 "
348+
# Explicitly set the argv[0] value
349+
"--argv0 {ARGV0} "
347350
# Enable thread support; causes use of preview1.
348351
# "--wasm threads=y --wasi threads=y "
349352
# Map the checkout to / to load the stdlib from /Lib.

0 commit comments

Comments
 (0)