Repository navigation
[Aikido] Fix security issue in torch via minor version upgrade from 2.4.0 to 2.13.0 - #2
Open
aikido-autofix[bot] wants to merge 1 commit into
Open
aikido-autofix[bot] wants to merge 1 commit into
aikido-autofix[bot] wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrade PyTorch to fix critical Remote Code Execution vulnerabilities in model loading through unsafe pickle deserialization and weights_only parameter handling.
✅ Code not affected by breaking changes.
✅ After searching through the entire codebase for all breaking changes listed in the torch 2.4.0 => 2.13.0 upgrade changelog, I found that no breaking changes affect this codebase.
The codebase uses torch in the following ways:
torch.no_grad()context manager inmotion-dection-security-camera.pytorch.inference_mode()context manager infootball_tracking.pyand the basketball notebooktorch.cuda.is_available()andtorch.backends.mps.is_available()for device detection infootball_tracking.pytorch.autocast()in the basketball notebookBasic tensor operations like
.cpu()and.numpy()torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)inmotion-dection-security-camera.py(note: this uses the deprecatedpretrainedparameter, but this is a torchvision API issue, not a torch breaking change)None of the breaking changes from the changelog affect these usage patterns:
No usage of
torch.load()(so theweights_onlydefault change doesn't apply)No usage of ONNX export APIs
No usage of named tensors
No usage of
torch.export,torch.hub, quantization APIs, distributed training, custom samplers, or any other deprecated/removed featuresNo C++ extensions or custom operators
The codebase runs on Python 3.10 (as documented in README.md), which meets the minimum Python 3.10 requirement from torch 2.9.0
The MPS backend usage is basic device detection only; the breaking change about unified memory allocation is unlikely to cause issues
The only potential concern is the environment uses Apple M2 Max with MPS backend, and torch 2.9.0 requires MacOS-14 or later. However, this is an environment requirement, not a code-breaking change.
All breaking changes by upgrading torch from version 2.4.0 to 2.13.0 (CHANGELOG)
data_sourceargument from Sampler. Custom samplers using this argument must be updated accordingly.torch.utils.data.datapipes.iter.grouping. Users must importSHARDING_PRIORITIESandShardingFilterIterDataPipefromtorch.utils.data.datapipes.iter.shardinginstead.nn.attention.flex_attention.fallback=Falseis now the default intorch.onnx.export. The exporter now usesdynamo=Trueoption without fallback. To preserve 2.9 behavior, manually setfallback=Truein thetorch.onnx.exportcall.torch.hub.list(),torch.hub.load(), andtorch.hub.help()now defaulttrust_repoparameter to"check"instead ofNone; thetrust_repo=Noneoption has been removedtorch.nn.attention.varlen_attnsignature changed: optional arguments likeis_causal,return_aux, andscalemust now be passed as keyword arguments (keyword-only separator*inserted before optional arguments)is_causalparameter removed fromtorch.nn.attention.varlen_attn; causal attention now expressed throughwindow_sizeparameterDebugInfoWriternow honors$XDG_CACHE_HOMEfor its cache directory in C++ code instead of always using~/.cache/torchDeviceMeshnow stores a process group registry directly; process groups must be initialized before constructing the DeviceMeshDTensor.to_local()backward now convertsPartialplacements toReplicateby default whengrad_placementsis not provided_PhiloxState.seedand_PhiloxState.offsetnow returntorch.Tensorinstead ofinttorch.export.export_for_traininghas been removedfallbackparameter removed fromtorch.onnx.export()custom_translation_tableparameter intorch.onnx.export()no longer accepts a list of functions for each torch op; changed fromdict[Callable, Callable | Sequence[Callable]]todict[Callable, Callable]torch.ao.quantization.pt2eandtorch.ao.quantization.quantizer) removed from PyTorch and migrated to torchaoFindARM.cmakemay reject previously accepted but incorrect SVE configurations during CMake configuration.torch.distributed.nn.functionalops now raiseRuntimeErrorundertorch.compile; users must migrate to the functional collectives API intorch.distributed._functional_collectives.torchrunnow defaults to an OS-assigned free port for single-node training instead of port 29500 when running without specifying--master-portor--standalone.max_autotunelayout-constraint deferral introduced in 2.11 is now opt-in; users who relied on the deferred behavior for fusion opportunities must opt in explicitly viatorch._inductor.config.max_autotune_defer_layout_freezingor environment variable.PyObjectis no longer allowed in operator schemas. Schema strings with barePyObjectarguments or return types now raise a schema parse error.StorageImpl's built-in copy-on-write (COW) materialization is replaced by a pluggable materializer hook. The internal COW entry pointsStorageImpl::is_cow(),StorageImpl::maybe_materialize_cow(), andcow::materialize_cow_storage()have been removed.shared_ptr<Node>tointrusive_ptr<Node>. This changes the signature ofTensor::grad_fnfromstd::shared_ptr<Node>toc10::intrusive_ptr<Node>.Tensor.names,Tensor.rename(),Tensor.refine_names(),Tensor.align_to(),Tensor.align_as(),torch.align_tensors(), thenames=keyword on factory functions, and C++Dimname/DimnameListAPIs.onednn::qconv2d_pointwise.binaryand.binary_tensoroperators no longer alias their input but return fresh tensors. Code relying on in-place mutation of theqaccuminput must now read the returned tensor instead.ProcessGroup.Optionsremoved from ProcessGroup initialization; users must now create ProcessGroup without passing base options and set default backend separately using_set_default_backenddynamic_dim()method for specifying dynamic shapes intorch.export()has been removed; useDimsinsteadtorch._inductor.runtime.runtime_utils.do_bench_gputotorch._inductor.runtime.benchmarking.benchmarker.benchmark_gpuattn_maskpassed tonn.functional.scaled_dot_product_attentionnow yield 0s instead of NANs in outputtorch.onnx.export(except for the first three arguments) are now keyword-onlytorch.onnx._exporthas been removed; usetorch.onnx.exportinsteadop_level_debugoption fromtorch.onnx.ExportOptionshas been removedONNXProgramSerializerclass has been removedSymbolicContextclass has been removed; custom symbolic functions can no longer takectx: torch.onnx.SymbolicContextas first argumentCheckerErrorandInvalidExportOptionsErrorclasses are removedweights_onlyparameter intorch.loadchanged toTrue. Previously serialized objects beyond basic types will fail to load unlessweights_only=Falseis explicitly specified.torch.onnx.export(..., dynamo=True)now creates ONNX models using IR version 10 instead of previous versions. Model consumers must support IR version 10.torch.onnx.ExportTypes, andtorch.onnx.export_to_pretty_string.torch.onnx.ONNXProgramhas been reimplemented with new methods (save(),optimize()). Some legacy methods are no longer available.TORCHINDUCTOR_STACK_ALLOCATIONdeprecated in favor oftorch.compile(options={"aot_inductor.allow_stack_allocation": True}).torch._utils.is_compiling()moved totorch.compiler.is_compiling().aot_inductorprefix:use_minimal_arrayref_interfaceandallow_stack_allocationoptions must be prefixed.py_limited_api=Truenow built with-DPy_LIMITED_APIflag, which may cause custom extensions that set this flag but don't abide by the limited API to fail to buildtorch.Tensor.new_tensor()now creates tensors on the given Tensor's device by default instead of "cpu" devicetorch.onnx.dynamo_exportnow uses ExportedProgram logic path;ExportOptionsfieldsdiagnostic_options,fake_contextandonnx_registryare removed/ignored, onlydynamic_shapesis retainedLRScheduler.print_lr()and theverbosekwarg to the LRScheduler constructor (deprecated since 2.2)capture_pre_autograd_graphdeprecated in favor oftorch.export.exportfor pytorch 2 export quantizationtorch.fx.passes.graph_transform_observer.GraphTransformObserverto enable Node Level provenance tracking;on_node_creationandon_node_erasereplaced withget_node_creation_hook,get_node_erase_hook,get_node_replace_hookandget_deepcopy_hooktorch.ao.quantization.pt2e.graph_utils.get_control_flow_submodulesis no longer public; must use_get_control_flow_submodulesfor private accessNotImplementedErrorinstead ofRuntimeError. Exception handling logic must be updated accordingly.autograd.Functionnow properly raises an error when mutating a view of a leaf requiring grad (previously silently leaked memory).tensordotnow properly throws an error when called with arequires_grad=Truetensor (previously did not error but could not compute gradients).mark_dynamicapplied now correctly errors in certain cases. Workaround is to usemaybe_mark_dynamicinstead ofmark_dynamic.enable_cpp_framelocals_guard_evalno longer has effect,rocm.n_max_profiling_configsdeprecated,autotune_fallback_to_atendeprecated,use_mixed_mmandmixed_mm_choicedeprecated,descriptive_names = Falsedeprecated,custom_op_default_layout_constraintmoved from inductor to functorch config,emit_current_arch_binarydeprecated,aot_inductor.embed_cubinrenamed toaot_inductor.embed_kernel_binary, andaot_inductor.compile_wrapper_with_O0renamed tocompile_wrapper_opt_level.HigherOrderOperators (e.g.cond), which explicitly errors out if alias/mutation among inputs and outputs is unsupported. Affected code must add.clone()to aliased outputs.definitely_true/definitely_falseAPIs have been removed and replaced withguard_or_true/guard_or_false.torch.export.export_for_inferencehas been removed in favor oftorch.export.export_for_training().run_decompositions().strict=Falseintorch.export.exportandexport_for_training(previouslystrict=True). To revert to old behavior, explicitly passstrict=True.torch.onnx.export(whendynamo=False) updated from 17 to 18. Users can setopset_versionexplicitly to select a different version.JitTraceConvertStrategyhas been removed. Support for JIT traced and scripted modules in ONNX exporter whendynamo=Truehas been removed.onnxscript>=0.3.1is now required for thedynamo=Trueoption in ONNX export.torch/types.hinclude fromDispatcher.h, which can cause build errors in C++ code that implicitly relies on this include.DLPackto 1.0, renaming someDLDeviceTypeenum values (e.g.,kDLGPUtokDLCUDA,kDLCPUPinnedtokDLCUDAHost).cmake/public/cuda.cmaketocmake/Dependencies.cmake. Downstream projects that previously got NVTX3 throughcmake/public/cuda.cmakemust now explicitly configure NVTX3 support usingUSE_SYSTEM_NVTX=1.torch.segment_reduce()due to a CUDA bug causing build crashes. Users needing this function must use a different CUDA version.torch.compile(previously undefined behavior)torch.utils.dlpack(e.g.,DLDeviceType)torch.catnow raisesValueError,IndexErrororTypeErrorinstead of genericRuntimeErrorwhere appropriatedynamo=True(usestorch.export.exportpipeline instead of legacy TorchScript exporter)exported_program.module()generates a_guards_fnsubmodule call for input checks (can be disabled withcheck_guards=False)torch.export.draft_exportis no longer auto-invoked on export failures; must opt-in viaTORCH_ONNX_ENABLE_DRAFT_EXPORT=Trueenvironment variabletorch.onnx.dynamo_export(usetorch.onnx.exportinstead)torch.compile(backend="onnxrt"))torch.onnx.enable_fake_modetorch.onnx.verificationremoved;torch.onnx.symbolic_opsets*functions no longer accessibletorch.onnx.symbolic_caffe2/d2implyavx512upperregsflag), may cause issues with specific VS2022 versionsScalarTypeto shim conversion; narrowly breaking for unpopular dtypes (quint*,qint*,Bits*,dummy_uint*,dummy_int*,Float8_e8m0fnu,Float4_e2m1fn_x2) when retrieving Tensor dtype and passing toaoti_torch_call_dispatcher✅ 8 CVEs resolved by this upgrade, including 1 critical 🚨 CVE
This PR will resolve the following CVEs:
weights_only=Falseallows arbitrary code execution when loading malicious pickle files, enabling remote code execution (RCE) attacks.libuvlibrary truncates hostnames longer than 256 characters before DNS resolution, allowing crafted long hostnames to resolve to unintended addresses and enabling server-side request forgery attacks. The vulnerability affects distributed C++ binaries when resolving externally influenced hostnames.