Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HuggingFace PT Inference/training CVE fix #3523

Merged
merged 31 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
714b723
HuggingFace Inference CVE fix
haixiw Nov 14, 2023
72cf7fe
Add more CVEs
haixiw Nov 14, 2023
4451330
Add toml change to trigger tests
haixiw Nov 14, 2023
17e742a
refactor the code base
haixiw Nov 15, 2023
767c8b8
Add more CVEs
haixiw Nov 15, 2023
cd409a5
update version to be compatible with python version
haixiw Nov 15, 2023
bdd8ca0
update scipy to latest version
haixiw Nov 15, 2023
a8354c7
remove dependencies not compatible with current python
haixiw Nov 15, 2023
e287e85
update allowlist
haixiw Nov 16, 2023
3ff8e1b
fix typo
haixiw Nov 16, 2023
fc070b5
fix build error on opencv
haixiw Nov 16, 2023
ea894ef
add ignore id for safety check
haixiw Nov 17, 2023
4e4dfd3
add ignore ids to both training and inference
haixiw Nov 17, 2023
119ecc3
try to fix some build errors
haixiw Nov 17, 2023
137a6ca
add mkl as dependency to address some failures
haixiw Nov 17, 2023
940cf84
update the HF inference toolkit
haixiw Nov 18, 2023
f5d8928
update diffuser version to resolve conflicts between huggingface infe…
haixiw Nov 18, 2023
7bf2dea
update pyYaml to consistent with awscli
haixiw Nov 18, 2023
f59353b
install deps as user to resolve #https://github.com/aws-actions/setup…
haixiw Nov 18, 2023
8a9cc9c
downgrade cpython to resolve break dependency with pyyaml
haixiw Nov 18, 2023
b034193
update install tag
haixiw Nov 18, 2023
e61eabb
exclude training image from the commit
haixiw Nov 19, 2023
5d31f8c
Revert "exclude training image from the commit"
haixiw Nov 20, 2023
5711ac9
Add training image back
haixiw Nov 20, 2023
8e5707a
specify awscli version
haixiw Nov 21, 2023
a6133b7
change download order for awscli and pyyaml
haixiw Nov 21, 2023
839c447
allowlist pyarrow
haixiw Nov 21, 2023
2716276
update pyyaml
haixiw Nov 21, 2023
ad8e99c
Revert "Add toml change to trigger tests"
haixiw Nov 21, 2023
2ef06c3
Merge branch 'master' into cve_fix_haixiw
arjkesh Dec 4, 2023
03867dd
Merge branch 'master' into cve_fix_haixiw
tejaschumbalkar Dec 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions data/ignore_ids_safety_scan.json
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,11 @@
"42815":"for shipping bokeh<=2.3.3 - the last available version for py3.6",
"45521":"pytorch-lightning is never installed as a dependency of transformers",
"44715":"False positive for numpy. Was fixed in 1.22.2",
"48547":"Latest version of rdflib is being installed"
"48547":"Latest version of rdflib is being installed",
"60235": "Temporarily ignoring to patch CRITICAL vulnerabilties at SEV2 pace",
"61601": "Temporarily ignoring to patch CRITICAL vulnerabilties at SEV2 pace",
"61416": "Temporarily ignoring to patch CRITICAL vulnerabilties at SEV2 pace",
"61893": "Temporarily ignoring to patch CRITICAL vulnerabilties at SEV2 pace"
}
},
"inference": {
Expand All @@ -1358,7 +1362,8 @@
"48547":"Latest version of rdflib is being installed",
"51159":"cryptography>38.0.1 does not exist yet",
"51450": "This bug is in Jax/Flax backend that would need Transformers 4.23 for fix.",
"51396": "Protobuf is only a runtime dependency of transformers. Current version of Protobuf installed in the image is not vulnerable."
"51396": "Protobuf is only a runtime dependency of transformers. Current version of Protobuf installed in the image is not vulnerable.",
"60235": "Temporarily ignoring to patch CRITICAL vulnerabilties at SEV2 pace"
}
},
"inference-neuron": {
Expand Down Expand Up @@ -1389,7 +1394,8 @@
"py3": {
"48547":"Latest version of rdflib is being installed",
"51396":"Protobuf is only a runtime dependency of transformers and we build our own transformers.",
"51450":"We build our own transformers specifically for PyTorch. This bug is in Jax/Flax backend."
"51450":"We build our own transformers specifically for PyTorch. This bug is in Jax/Flax backend.",
"60235": "Temporarily ignoring to patch CRITICAL vulnerabilties at SEV2 pace"
}
}
},
Expand Down
13 changes: 10 additions & 3 deletions huggingface/pytorch/inference/docker/2.0/py3/Dockerfile.cpu
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ARG TORCHAUDIO_URL=https://aws-pytorch-unified-cicd-binaries.s3.us-west-2.amazon

# HF ARGS
ARG TRANSFORMERS_VERSION
ARG DIFFUSERS_VERSION=0.16.1
ARG DIFFUSERS_VERSION=0.23.1

# Set Debian interaction
ARG DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -69,9 +69,12 @@ RUN apt-get update \
libxext6 \
libxrender-dev \
zlib1g-dev \
unattended-upgrades \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

RUN unattended-upgrade

# https://github.com/docker-library/openjdk/issues/261 https://github.com/docker-library/openjdk/pull/263/files
RUN keytool -importkeystore -srckeystore /etc/ssl/certs/java/cacerts -destkeystore /etc/ssl/certs/java/cacerts.jks -deststoretype JKS -srcstorepass changeit -deststorepass changeit -noprompt; \
mv /etc/ssl/certs/java/cacerts.jks /etc/ssl/certs/java/cacerts; \
Expand Down Expand Up @@ -167,7 +170,7 @@ RUN pip install --no-cache-dir \
diffusers==${DIFFUSERS_VERSION} \
"accelerate>=0.11.0" \
"protobuf>=3.19.5,<=3.20.2" \
"sagemaker-huggingface-inference-toolkit<3"
"sagemaker-huggingface-inference-toolkit>=2.3.0"

# Install IPEx and its dependencies
# from source is mandatory for cutomized AWS PyTorch binaries: https://github.com/intel/intel-extension-for-pytorch/issues/317
Expand All @@ -180,7 +183,11 @@ RUN cd /opt/ && mkdir -p ipex \

# IPEx installation installs the numpy==1.25.1. That causes a pip check failure due to incompatibility with numba.
# Re-installing numpy after IPEx installation to get the appropriate numpy version and fix pip checks.
RUN pip install --no-cache-dir "numpy<1.25"
RUN pip install --no-cache-dir "numpy<1.25" \
# Resolve CVE
urllib3==1.26.18 \
mkl


RUN HOME_DIR=/root \
&& curl -o ${HOME_DIR}/oss_compliance.zip https://aws-dlinfra-utilities.s3.amazonaws.com/oss_compliance.zip \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,97 @@
"title": "CVE-2019-13132 - libzmq5"
}
],
"scipy": [
"cryptography":[
{
"reason_to_ignore": "Temporarily ignoring to fix CRITICALs",
"description":"Issue summary: Generating excessively long X9.42 DH keys or checking\nexcessively long X9.42 DH keys or parameters may be very slow.\n\nImpact summary: Applications that use the functions DH_generate_key() to\ngenerate an X9.42 DH key may experience long delays. Likewise, applications\nthat use DH_check_pub_key(), DH_check_pub_key_ex() or EVP_PKEY_public_check()\nto check an X9.42 DH key or X9.42 DH parameters may experience long delays.\nWhere the key or parameters that are being checked have been obtained from\nan untrusted source this may lead to a Denial of Service.\n\nWhile DH_check() performs all the necessary checks (as of CVE-2023-3817),\nDH_check_pub_key() doesn't make any of these checks, and is therefore\nvulnerable for excessively large P and Q parameters.\n\nLikewise, while DH_generate_key() performs a check for an excessively large\nP, it doesn't check for an excessively large Q.\n\nAn application that calls DH_generate_key() or DH_check_pub_key() and\nsupplies a key or parameters obtained from an untrusted sour",
"vulnerability_id":"CVE-2023-5678",
"name":"CVE-2023-5678",
"package_name":"cryptography",
"package_details":{
"file_path":"opt/conda/lib/python3.10/site-packages/cryptography-41.0.5.dist-info/METADATA",
"name":"cryptography",
"package_manager":"PYTHONPKG",
"version":"41.0.5",
"release":null
},
"remediation":{
"recommendation":{
"text":"None Provided"
}
},
"cvss_v3_score":7.5,
"cvss_v30_score":0.0,
"cvss_v31_score":7.5,
"cvss_v2_score":0.0,
"cvss_v3_severity":"HIGH",
"source_url":"https://nvd.nist.gov/vuln/detail/CVE-2023-5678",
"source":"NVD",
"severity":"HIGH",
"status":"ACTIVE",
"title":"CVE-2023-5678 - cryptography"
}
],
"scipy":[
{
"reason_to_ignore": "Temporarily ignoring to fix CRITICALs",
"description":"A use-after-free issue was discovered in Py_FindObjects() function in SciPy versions prior to 1.8.0. NOTE: the vendor and discoverer indicate that this is not a security issue.",
"vulnerability_id":"CVE-2023-29824",
"name":"CVE-2023-29824",
"package_name":"scipy",
"package_details":{
"file_path":"opt/llvm-project/libcxx/utils/google-benchmark/requirements.txt",
"name":"scipy",
"package_manager":"PIP",
"version":"1.5.4",
"release":null
},
"remediation":{
"recommendation":{
"text":"None Provided"
}
},
"cvss_v3_score":9.8,
"cvss_v30_score":0.0,
"cvss_v31_score":9.8,
"cvss_v2_score":0.0,
"cvss_v3_severity":"CRITICAL",
"source_url":"https://nvd.nist.gov/vuln/detail/CVE-2023-29824",
"source":"NVD",
"severity":"CRITICAL",
"status":"ACTIVE",
"title":"CVE-2023-29824 - scipy"
}
],
"transformers": [
{
"reason_to_ignore": "According to the maintainer, this issue is not to be considered a vulnerability. The current version of Scipy installed is 1.11.1. Vulnerability requires version to be greater than 1.8.0.",
"description":"## Overview\n\nAffected versions of this package are vulnerable to Use After Free via the `Py_FindObjects()` function.\r\n\r\n**Note:**\r\n\r\nAccording to the maintainer, this issue is not to be considered a vulnerability.\n## PoC\n```\r\nvoid f() {\r\n PyObject *result = PyList_New(1); // <-- new reference returned (line 878)\r\n assert(result);\r\n printf(\"%ld\\n\", result->ob_refcnt); // 1\r\n\r\n PyErr_NoMemory(); // <-- error happens, an exception is thrown (line 890)\r\n Py_XDECREF(result); // <-- destruction here (line 924)\r\n printf(\"%ld\\n\", result->ob_refcnt); // 0\r\n\r\n if (PyErr_Occurred()) {\r\n Py_XDECREF(result); // <-- use after free here (line 931)\r\n printf(\"%ld\\n\", result->ob_refcnt); // -1\r\n }\r\n}\r\n```\n## Remediation\nUpgrade `scipy` to version 1.8.0 or higher.\n## References\n- [GitHub Commit](https://github.com/scipy/scipy/commit/e32fc2329d3dd23298725153c5b2cc7fcd0f14f1)\n- [GitHub Issue](https://github.com/scipy/scipy/issues/14713)\n- [GitHub PR](https://github.com/scipy/scipy/pull/15013)\n- [GitHub Release](http",
"vulnerability_id":"SNYK-PYTHON-SCIPY-5759266",
"name":"SNYK-PYTHON-SCIPY-5759266",
"package_name":"scipy",
"package_details":{
"file_path":"opt/llvm-project/libcxx/utils/google-benchmark/requirements.txt",
"name":"scipy",
"package_manager":"PIP",
"version":"1.5.4",
"release":null
},
"remediation":{
"recommendation":{
"text":"None Provided"
}
},
"cvss_v3_score":7.3,
"cvss_v30_score":0.0,
"cvss_v31_score":7.3,
"cvss_v2_score":0.0,
"cvss_v3_severity":"HIGH",
"source_url":"https://security.snyk.io/vuln/SNYK-PYTHON-SCIPY-5759266",
"source":"SNYK",
"severity":"HIGH",
"status":"ACTIVE",
"title":"IN1-PYTHON-SCIPY-5759266 - scipy"
"reason_to_ignore": "Need guidance from HF team on how to upgrade as it's breaking the image. Temporarily ignoring to patch other CVEs.",
"description": "\n Insecure Temporary File in GitHub repository huggingface/transformers prior to 4.30.0..",
"vulnerability_id": "CVE-2023-2800",
"name": "CVE-2023-2800",
"package_name": "transformers",
"package_details": {
"file_path": null,
"name": "transformers",
"package_manager": "PYTHONPKG",
"version": "4.26.0",
"release": ""
},
"remediation": {
"recommendation": {
"text": "Update transformers to 4.30.0."
}
},
"cvss_v3_score": 4.7,
"cvss_v30_score": 4.7,
"cvss_v31_score": 4.7,
"cvss_v2_score": 4.7,
"cvss_v3_severity": "MEDIUM",
"source_url": "https://nvd.nist.gov/vuln/detail/CVE-2023-2800",
"source": "NVD",
"severity": "MEDIUM",
"status": "ACTIVE",
"title": "CVE-2023-2800 - transformers"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ARG TORCHAUDIO_URL=https://aws-pytorch-unified-cicd-binaries.s3.us-west-2.amazon

# HF ARGS
ARG TRANSFORMERS_VERSION
ARG DIFFUSERS_VERSION=0.16.1
ARG DIFFUSERS_VERSION=0.23.1

# Set Debian interaction
ARG DEBIAN_FRONTEND=noninteractive
Expand Down Expand Up @@ -91,10 +91,13 @@ RUN apt-get update \
ffmpeg \
openssh-client \
openssh-server \
unattended-upgrades \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/* \
&& apt-get clean

RUN unattended-upgrade

# Install NCCL
RUN cd /tmp \
&& git clone https://github.com/NVIDIA/nccl.git -b v${NCCL_VERSION}-1 \
Expand Down Expand Up @@ -200,7 +203,10 @@ RUN pip install --no-cache-dir \
"accelerate>=0.11.0" \
"protobuf>=3.19.5,<=3.20.2" \
"numpy>=1.22.2,<1.23" \
"sagemaker-huggingface-inference-toolkit<3"
"sagemaker-huggingface-inference-toolkit>=2.3.0" \
# CVE
urllib3==1.26.18 \
mkl


RUN HOME_DIR=/root \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,97 @@
"status": "ACTIVE",
"title": "CVE-2019-13132 - libzmq5"
}
],
"cryptography":[
{
"description":"Issue summary: Generating excessively long X9.42 DH keys or checking\nexcessively long X9.42 DH keys or parameters may be very slow.\n\nImpact summary: Applications that use the functions DH_generate_key() to\ngenerate an X9.42 DH key may experience long delays. Likewise, applications\nthat use DH_check_pub_key(), DH_check_pub_key_ex() or EVP_PKEY_public_check()\nto check an X9.42 DH key or X9.42 DH parameters may experience long delays.\nWhere the key or parameters that are being checked have been obtained from\nan untrusted source this may lead to a Denial of Service.\n\nWhile DH_check() performs all the necessary checks (as of CVE-2023-3817),\nDH_check_pub_key() doesn't make any of these checks, and is therefore\nvulnerable for excessively large P and Q parameters.\n\nLikewise, while DH_generate_key() performs a check for an excessively large\nP, it doesn't check for an excessively large Q.\n\nAn application that calls DH_generate_key() or DH_check_pub_key() and\nsupplies a key or parameters obtained from an untrusted sour",
"vulnerability_id":"CVE-2023-5678",
"name":"CVE-2023-5678",
"package_name":"cryptography",
"package_details":{
"file_path":"opt/conda/lib/python3.10/site-packages/cryptography-41.0.5.dist-info/METADATA",
"name":"cryptography",
"package_manager":"PYTHONPKG",
"version":"41.0.5",
"release":null
},
"remediation":{
"recommendation":{
"text":"None Provided"
}
},
"cvss_v3_score":7.5,
"cvss_v30_score":0.0,
"cvss_v31_score":7.5,
"cvss_v2_score":0.0,
"cvss_v3_severity":"HIGH",
"source_url":"https://nvd.nist.gov/vuln/detail/CVE-2023-5678",
"source":"NVD",
"severity":"HIGH",
"status":"ACTIVE",
"title":"CVE-2023-5678 - cryptography"
}
],
"scipy":[
{
"reason_to_ignore":"Temporarily ignoring to fix CRITICALs",
"description":"A use-after-free issue was discovered in Py_FindObjects() function in SciPy versions prior to 1.8.0. NOTE: the vendor and discoverer indicate that this is not a security issue.",
"vulnerability_id":"CVE-2023-29824",
"name":"CVE-2023-29824",
"package_name":"scipy",
"package_details":{
"file_path":"opt/llvm-project/libcxx/utils/google-benchmark/requirements.txt",
"name":"scipy",
"package_manager":"PIP",
"version":"1.5.4",
"release":null
},
"remediation":{
"recommendation":{
"text":"None Provided"
}
},
"cvss_v3_score":9.8,
"cvss_v30_score":0.0,
"cvss_v31_score":9.8,
"cvss_v2_score":0.0,
"cvss_v3_severity":"CRITICAL",
"source_url":"https://nvd.nist.gov/vuln/detail/CVE-2023-29824",
"source":"NVD",
"severity":"CRITICAL",
"status":"ACTIVE",
"title":"CVE-2023-29824 - scipy"
}
],
"transformers": [
{
"reason_to_ignore": "Need guidance from HF team on how to upgrade as it's breaking the image. Temporarily ignoring to patch other CVEs.",
"description": "\n Insecure Temporary File in GitHub repository huggingface/transformers prior to 4.30.0..",
"vulnerability_id": "CVE-2023-2800",
"name": "CVE-2023-2800",
"package_name": "transformers",
"package_details": {
"file_path": null,
"name": "transformers",
"package_manager": "PYTHONPKG",
"version": "4.26.0",
"release": ""
},
"remediation": {
"recommendation": {
"text": "Update transformers to 4.30.0."
}
},
"cvss_v3_score": 4.7,
"cvss_v30_score": 4.7,
"cvss_v31_score": 4.7,
"cvss_v2_score": 4.7,
"cvss_v3_severity": "MEDIUM",
"source_url": "https://nvd.nist.gov/vuln/detail/CVE-2023-2800",
"source": "NVD",
"severity": "MEDIUM",
"status": "ACTIVE",
"title": "CVE-2023-2800 - transformers"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,23 @@ RUN pip install --no-cache-dir \
Jinja2 \
tensorboard \
evaluate==${EVALUATE_VERSION} \
accelerate==${ACCELERATE_VERSION}
accelerate==${ACCELERATE_VERSION} \
mkl

# Resolve CVE
RUN pip install --no-cache-dir -U \
pip \
werkzeug \
gevent \
certifi \
tornado \
fonttools

# install PyYAML<5.5,>=5.4 to avoid conflict with latest awscli
# Use --no-build-isolation to force pyyaml 6.0.0 to be installed using Cython<3 to avoid installation errors
RUN pip install --no-cache-dir "cython<3.0.0" \
&& pip install --no-build-isolation "pyyaml==6.0"


RUN apt-get update \
# TODO: Remove upgrade statements once packages are updated in base image
Expand Down
Loading