diff --git a/SPECS/pytorch/CVE-2024-5187.patch b/SPECS/pytorch/CVE-2024-5187.patch new file mode 100644 index 00000000000..fb9b07d93df --- /dev/null +++ b/SPECS/pytorch/CVE-2024-5187.patch @@ -0,0 +1,85 @@ +From a8c49a5fac46df180ba95810dcbb56c00dbd9c76 Mon Sep 17 00:00:00 2001 +From: sunflowersxu <166728538+sunflowersxu@users.noreply.github.com> +Date: Thu, 13 Jun 2024 01:47:14 +0800 +Subject: [PATCH] Mitigate tarball directory traversal risks (#6164) + +Hi, this pr is cleaner version than #6145 + +Signed-off-by: sunriseXu <15927176697@163.com> +Co-authored-by: sunriseXu <15927176697@163.com> +Co-authored-by: Justin Chu +--- + third_party/onnx/onnx/hub.py | 43 +++++++++++++++++++++++++++++++++++- + 1 file changed, 42 insertions(+), 1 deletion(-) + +diff --git a/third_party/onnx/onnx/hub.py b/third_party/onnx/onnx/hub.py +index e5ca9e2c..dc888742 100644 +--- a/third_party/onnx/onnx/hub.py ++++ b/third_party/onnx/onnx/hub.py +@@ -271,6 +271,35 @@ def load( + return onnx.load(cast(IO[bytes], BytesIO(model_bytes))) + + ++def _tar_members_filter(tar: tarfile.TarFile, base: str) -> list[tarfile.TarInfo]: ++ """Check that the content of ``tar`` will be extracted safely ++ ++ Args: ++ tar: The tarball file ++ base: The directory where the tarball will be extracted ++ ++ Returns: ++ list of tarball members ++ """ ++ result = [] ++ for member in tar: ++ member_path = os.path.join(base, member.name) ++ abs_base = os.path.abspath(base) ++ abs_member = os.path.abspath(member_path) ++ if not abs_member.startswith(abs_base): ++ raise RuntimeError( ++ f"The tarball member {member_path} in downloading model contains " ++ f"directory traversal sequence which may contain harmful payload." ++ ) ++ elif member.issym() or member.islnk(): ++ raise RuntimeError( ++ f"The tarball member {member_path} in downloading model contains " ++ f"symbolic links which may contain harmful payload." ++ ) ++ result.append(member) ++ return result ++ ++ + def download_model_with_test_data( + model: str, + repo: str = "onnx/models:main", +@@ -280,6 +309,7 @@ def download_model_with_test_data( + ) -> Optional[str]: + """ + Downloads a model along with test data by name from the onnx model hub and returns the directory to which the files have been extracted. ++ Users are responsible for making sure the model comes from a trusted source, and the data is safe to be extracted. + + :param model: The name of the onnx model in the manifest. This field is case-sensitive + :param repo: The location of the model repo in format "user/repo[:branch]". +@@ -342,7 +372,18 @@ def download_model_with_test_data( + local_model_with_data_dir_path = local_model_with_data_path[ + 0 : len(local_model_with_data_path) - 7 + ] +- model_with_data_zipped.extractall(local_model_with_data_dir_path) ++ # Mitigate tarball directory traversal risks ++ if hasattr(tarfile, "data_filter"): ++ model_with_data_zipped.extractall( ++ path=local_model_with_data_dir_path, filter="data" ++ ) ++ else: ++ model_with_data_zipped.extractall( ++ path=local_model_with_data_dir_path, ++ members=_tar_members_filter( ++ model_with_data_zipped, local_model_with_data_dir_path ++ ), ++ ) + model_with_data_path = ( + local_model_with_data_dir_path + + "/" +-- +2.39.4 + diff --git a/SPECS/pytorch/generate_source_tarball.sh b/SPECS/pytorch/generate_source_tarball.sh deleted file mode 100644 index e49598755cf..00000000000 --- a/SPECS/pytorch/generate_source_tarball.sh +++ /dev/null @@ -1,102 +0,0 @@ -#!/bin/bash -# Copyright (c) Microsoft Corporation. -# Licensed under the MIT License. - -set -e - -SRC_TARBALL="" -OUT_FOLDER="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -PKG_VERSION="" - -# parameters: -# -# --srcTarball : src tarball file -# this file contains the 'initial' source code of the component -# and should be replaced with the new/modified src code -# --outFolder : folder where to copy the new tarball(s) -# --pkgVersion : package version -# -PARAMS="" -while (( "$#" )); do - case "$1" in - --srcTarball) - if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then - SRC_TARBALL=$2 - shift 2 - else - echo "Error: Argument for $1 is missing" >&2 - exit 1 - fi - ;; - --outFolder) - if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then - OUT_FOLDER=$2 - shift 2 - else - echo "Error: Argument for $1 is missing" >&2 - exit 1 - fi - ;; - --pkgVersion) - if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then - PKG_VERSION=$2 - shift 2 - else - echo "Error: Argument for $1 is missing" >&2 - exit 1 - fi - ;; - -*|--*=) # unsupported flags - echo "Error: Unsupported flag $1" >&2 - exit 1 - ;; - *) # preserve positional arguments - PARAMS="$PARAMS $1" - shift - ;; - esac -done - -echo "--srcTarball -> $SRC_TARBALL" -echo "--outFolder -> $OUT_FOLDER" -echo "--pkgVersion -> $PKG_VERSION" - -if [ -z "$PKG_VERSION" ]; then - echo "--pkgVersion parameter cannot be empty" - exit 1 -fi - -echo "-- create temp folder" -TEMPDIR=$(mktemp -d) -function cleanup { - echo "+++ cleanup -> remove $TEMPDIR" - rm -rf $TEMPDIR -} -trap cleanup EXIT - -echo 'Starting pytorch source tarball creation' -cd $TEMPDIR -git clone --depth 1 https://github.com/pytorch/pytorch.git -pushd pytorch -git fetch --all --tags -git checkout tags/v$PKG_VERSION -b pytorch-$PKG_VERSION -git submodule update --init --recursive -popd -mv pytorch/third_party third_party -mkdir -pv android -mv pytorch/android/libs android - -TARBALL_NAME="pytorch-$PKG_VERSION-submodules.tar.gz" - -NEW_TARBALL="$OUT_FOLDER/$TARBALL_NAME" - -# Create a reproducible tarball -# Credit to https://reproducible-builds.org/docs/archives/ for instructions -# Do not update mtime value for new versions- keep the same value for ease of -# reproducing old tarball versions in the future if necessary -tar --sort=name --mtime="2021-11-10 00:00Z" \ - --owner=0 --group=0 --numeric-owner \ - --pax-option=exthdr.name=%d/PaxHeaders/%f,delete=atime,delete=ctime \ - -zcf $NEW_TARBALL third_party android - -echo "Source tarball $NEW_TARBALL successfully created!" diff --git a/SPECS/pytorch/pytorch.signatures.json b/SPECS/pytorch/pytorch.signatures.json index 54db1554123..d3441afa795 100644 --- a/SPECS/pytorch/pytorch.signatures.json +++ b/SPECS/pytorch/pytorch.signatures.json @@ -1,6 +1,5 @@ { - "Signatures": { - "pytorch-2.2.2-submodules.tar.gz": "74d91f9cbba81848a0c07c718810889c46ca2d24a198444d8e3caca13eea9ffc", - "pytorch-2.2.2.tar.gz": "57a1136095bdfe769acb87876dce77212da2c995c61957a67a1f16172d235d17" - } -} + "Signatures": { + "pytorch-2.2.2.tar.gz": "57a1136095bdfe769acb87876dce77212da2c995c61957a67a1f16172d235d17" + } +} \ No newline at end of file diff --git a/SPECS/pytorch/pytorch.spec b/SPECS/pytorch/pytorch.spec index 4256781ebbf..fa44ce7096c 100644 --- a/SPECS/pytorch/pytorch.spec +++ b/SPECS/pytorch/pytorch.spec @@ -2,15 +2,13 @@ Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration. Name: pytorch Version: 2.2.2 -Release: 2%{?dist} +Release: 3%{?dist} License: BSD-3-Clause Vendor: Microsoft Corporation Distribution: Azure Linux Group: Development/Languages/Python URL: https://pytorch.org/ Source0: https://github.com/pytorch/pytorch/releases/download/v%{version}/%{name}-v%{version}.tar.gz#/%{name}-%{version}.tar.gz -# Use the generate_source_tarball.sh script to create a tarball of submodules during version updates. -Source1: %{name}-%{version}-submodules.tar.gz BuildRequires: cmake BuildRequires: gcc BuildRequires: gcc-c++ @@ -26,6 +24,7 @@ BuildRequires: python3-six Patch1: CVE-2024-27318.patch Patch2: CVE-2022-1941.patch +Patch3: CVE-2024-5187.patch %description PyTorch is a Python package that provides two high-level features: @@ -59,7 +58,7 @@ PyTorch is a Python package that provides two high-level features: You can reuse your favorite Python packages such as NumPy, SciPy and Cython to extend PyTorch when needed. %prep -%autosetup -a 1 -p 1 -n %{name}-v%{version} +%autosetup -p 1 -n %{name}-v%{version} %build export USE_CUDA=0 @@ -87,6 +86,9 @@ cp -arf docs %{buildroot}/%{_pkgdocdir} %{_docdir}/* %changelog +* Wed Nov 06 2024 Sean Dougherty - 2.2.2-3 +- patch for CVE-2024-5187 + * Tue Sep 17 2024 Archana Choudhary - 2.2.2-2 - patch for CVE-2024-27318, CVE-2022-1941