From 80381aeecc1ad4585d9275f208946d07cb0232ee Mon Sep 17 00:00:00 2001 From: starlet-dx <15929766099@163.com> Date: Thu, 16 Sep 2021 17:03:58 +0800 Subject: [PATCH] fix CVE-2021-29534 CVE-2021-37690 --- CVE-2021-29534.patch | 77 ++++++++++++++++++++++++++++++++++++++++++ CVE-2021-37690-1.patch | 56 ++++++++++++++++++++++++++++++ CVE-2021-37690-2.patch | 25 ++++++++++++++ CVE-2021-37690-3.patch | 25 ++++++++++++++ tensorflow.spec | 10 ++++-- 5 files changed, 191 insertions(+), 2 deletions(-) create mode 100644 CVE-2021-29534.patch create mode 100644 CVE-2021-37690-1.patch create mode 100644 CVE-2021-37690-2.patch create mode 100644 CVE-2021-37690-3.patch diff --git a/CVE-2021-29534.patch b/CVE-2021-29534.patch new file mode 100644 index 0000000..e3cf18f --- /dev/null +++ b/CVE-2021-29534.patch @@ -0,0 +1,77 @@ +From 69c68ecbb24dff3fa0e46da0d16c821a2dd22d7c Mon Sep 17 00:00:00 2001 +From: Amit Patankar +Date: Tue, 20 Apr 2021 12:14:41 -0700 +Subject: [PATCH] Fix overflow CHECK issue with + `tf.raw_ops.AddManySparseToTensorsMap`. + +PiperOrigin-RevId: 369492969 +Change-Id: I1d70d6c0c92e3d7a25bc3b3aa2a0c0ac9688bf81 +--- + .../core/kernels/sparse_tensors_map_ops.cc | 26 ++++++++++++++----- + 1 file changed, 19 insertions(+), 7 deletions(-) + +diff --git a/tensorflow/core/kernels/sparse_tensors_map_ops.cc b/tensorflow/core/kernels/sparse_tensors_map_ops.cc +index c2c0e43ca2ba8..5ea5fca544d3e 100644 +--- a/tensorflow/core/kernels/sparse_tensors_map_ops.cc ++++ b/tensorflow/core/kernels/sparse_tensors_map_ops.cc +@@ -21,9 +21,6 @@ limitations under the License. + #include + #include + +-#include "tensorflow/core/framework/op_kernel.h" +-#include "tensorflow/core/framework/register_types.h" +- + #include "tensorflow/core/framework/op_kernel.h" + #include "tensorflow/core/framework/register_types.h" + #include "tensorflow/core/framework/resource_mgr.h" +@@ -31,6 +28,7 @@ limitations under the License. + #include "tensorflow/core/framework/tensor_util.h" + #include "tensorflow/core/framework/types.h" + #include "tensorflow/core/lib/gtl/inlined_vector.h" ++#include "tensorflow/core/util/overflow.h" + #include "tensorflow/core/util/sparse/sparse_tensor.h" + + namespace tensorflow { +@@ -254,7 +252,22 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp { + errors::InvalidArgument( + "Rank of input SparseTensor should be > 1, but saw rank: ", rank)); + +- TensorShape tensor_input_shape(input_shape->vec()); ++ auto input_shape_vec = input_shape->vec(); ++ int new_num_elements = 1; ++ bool overflow_ocurred = false; ++ for (int i = 0; i < input_shape_vec.size(); i++) { ++ new_num_elements = ++ MultiplyWithoutOverflow(new_num_elements, input_shape_vec(i)); ++ if (new_num_elements < 0) { ++ overflow_ocurred = true; ++ } ++ } ++ ++ OP_REQUIRES( ++ context, !overflow_ocurred, ++ errors::Internal("Encountered overflow from large input shape.")); ++ ++ TensorShape tensor_input_shape(input_shape_vec); + gtl::InlinedVector std_order(rank); + std::iota(std_order.begin(), std_order.end(), 0); + SparseTensor input_st; +@@ -262,8 +275,7 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp { + tensor_input_shape, std_order, + &input_st)); + +- auto input_shape_t = input_shape->vec(); +- const int64 N = input_shape_t(0); ++ const int64 N = input_shape_vec(0); + + Tensor sparse_handles(DT_INT64, TensorShape({N})); + auto sparse_handles_t = sparse_handles.vec(); +@@ -274,7 +286,7 @@ class AddManySparseToTensorsMapOp : public SparseTensorAccessingOp { + // minibatch entries. + TensorShape output_shape; + OP_REQUIRES_OK(context, TensorShapeUtils::MakeShape( +- input_shape_t.data() + 1, ++ input_shape_vec.data() + 1, + input_shape->NumElements() - 1, &output_shape)); + + // Get groups by minibatch dimension diff --git a/CVE-2021-37690-1.patch b/CVE-2021-37690-1.patch new file mode 100644 index 0000000..812ad9b --- /dev/null +++ b/CVE-2021-37690-1.patch @@ -0,0 +1,56 @@ +From ee119d4a498979525046fba1c3dd3f13a039fbb1 Mon Sep 17 00:00:00 2001 +From: Daniel Ellis +Date: Wed, 14 Jul 2021 12:43:17 -0700 +Subject: [PATCH] Fix segmentation fault in shape inference logic. + +When running shape functions, some functions (such as `MutableHashTableShape`) +produce extra output information in the form of a `ShapeAndType` struct. The +shapes embedded in this struct are owned by an inference context that is +cleaned up almost immediately; if the upstream code attempts to access this +shape information, it can trigger a segfault. + +`ShapeRefiner` is mitigating this for normal output shapes by cloning them +(and thus putting the newly created shape under ownership of an inference +context that will not die), but we were not doing the same for shapes and +types. This commit fixes that by doing similar logic on output shapes and +types. + +PiperOrigin-RevId: 384761124 +Change-Id: I07c0c42d29dfbb55bfa13ec1f09ef825fb0a1a1d +--- + .../core/common_runtime/shape_refiner.cc | 21 +++++++++++++++++-- + 1 file changed, 19 insertions(+), 2 deletions(-) + +diff --git a/tensorflow/core/common_runtime/shape_refiner.cc b/tensorflow/core/common_runtime/shape_refiner.cc +index 375f809b31b36..2e29ef48189a5 100644 +--- a/tensorflow/core/common_runtime/shape_refiner.cc ++++ b/tensorflow/core/common_runtime/shape_refiner.cc +@@ -120,9 +120,26 @@ Status ShapeRefiner::InferShapesForFunctionSubNode( + TF_RETURN_IF_ERROR(outer_context->MakeShapeFromShapeProto(proto, &handle)); + outer_context->set_output(index, handle); + +- auto* resource = node_context->input_handle_shapes_and_types(0); ++ const std::vector* resource = ++ node_context->input_handle_shapes_and_types(0); + if (resource) { +- outer_context->set_output_handle_shapes_and_types(index, *resource); ++ // `ShapesAndType`s contain `ShapeHandle`s. These `ShapeHandle`s point ++ // to `Shape`s that are owned by a different inference context too. We ++ // need to copy them to the outer context to prevent them from being ++ // destroyed before they are used. ++ std::vector copied_shapes_and_types; ++ for (auto& shape_and_type : *resource) { ++ ShapeHandle handle; ++ TensorShapeProto proto; ++ node_context->ShapeHandleToProto(shape_and_type.shape, &proto); ++ TF_RETURN_IF_ERROR( ++ outer_context->MakeShapeFromShapeProto(proto, &handle)); ++ copied_shapes_and_types.push_back( ++ ShapeAndType(handle, shape_and_type.dtype, shape_and_type.type)); ++ } ++ ++ outer_context->set_output_handle_shapes_and_types( ++ index, copied_shapes_and_types); + } + } + diff --git a/CVE-2021-37690-2.patch b/CVE-2021-37690-2.patch new file mode 100644 index 0000000..666ed58 --- /dev/null +++ b/CVE-2021-37690-2.patch @@ -0,0 +1,25 @@ +From d8e07ff51f9e709399b8c553290836fb308e45ed Mon Sep 17 00:00:00 2001 +From: geetachavan1 <53313357+geetachavan1@users.noreply.github.com> +Date: Tue, 27 Jul 2021 16:08:12 -0700 +Subject: [PATCH 1/1] Update shape_refiner.cc + +--- + tensorflow/core/common_runtime/shape_refiner.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tensorflow/core/common_runtime/shape_refiner.cc b/tensorflow/core/common_runtime/shape_refiner.cc +index 6a7d1eadfb6..906bd14f96c 100644 +--- a/tensorflow/core/common_runtime/shape_refiner.cc ++++ b/tensorflow/core/common_runtime/shape_refiner.cc +@@ -132,7 +132,7 @@ Status InferShapesForFunctionSubNode(const Node* node, ShapeRefiner* refiner, + TF_RETURN_IF_ERROR( + outer_context->MakeShapeFromShapeProto(proto, &handle)); + copied_shapes_and_types.push_back( +- ShapeAndType(handle, shape_and_type.dtype, shape_and_type.type)); ++ ShapeAndType(handle, shape_and_type.dtype, shape_and_type.specialized_type)); + } + + outer_context->set_output_handle_shapes_and_types( +-- +2.27.0 + diff --git a/CVE-2021-37690-3.patch b/CVE-2021-37690-3.patch new file mode 100644 index 0000000..77baffb --- /dev/null +++ b/CVE-2021-37690-3.patch @@ -0,0 +1,25 @@ +From 106316a9077cfabca5d54721650c9a65fef4dc6a Mon Sep 17 00:00:00 2001 +From: Mihai Maruseac +Date: Sat, 7 Aug 2021 17:18:11 -0700 +Subject: [PATCH 1/1] Fix build + +--- + tensorflow/core/common_runtime/shape_refiner.cc | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/tensorflow/core/common_runtime/shape_refiner.cc b/tensorflow/core/common_runtime/shape_refiner.cc +index 906bd14f96c..3c5421a9507 100644 +--- a/tensorflow/core/common_runtime/shape_refiner.cc ++++ b/tensorflow/core/common_runtime/shape_refiner.cc +@@ -132,7 +132,7 @@ Status InferShapesForFunctionSubNode(const Node* node, ShapeRefiner* refiner, + TF_RETURN_IF_ERROR( + outer_context->MakeShapeFromShapeProto(proto, &handle)); + copied_shapes_and_types.push_back( +- ShapeAndType(handle, shape_and_type.dtype, shape_and_type.specialized_type)); ++ ShapeAndType(handle, shape_and_type.dtype)); + } + + outer_context->set_output_handle_shapes_and_types( +-- +2.27.0 + diff --git a/tensorflow.spec b/tensorflow.spec index fd71839..ecb21d9 100644 --- a/tensorflow.spec +++ b/tensorflow.spec @@ -1,7 +1,7 @@ %global _empty_manifest_terminate_build 0 Name: tensorflow Version: 2.3.1 -Release: 5 +Release: 6 Summary: An Open Source Machine Learning Framework for Everyone License: Apache License 2.0 URL: https://www.tensorflow.org/ @@ -12,7 +12,7 @@ Source1: external-%{_arch}.tar.bz2 Patch0001: 0001-Add-arm-source-file-into-aws-checksums.patch Patch0002: CVE-2021-37678.patch Patch0003: CVE-2021-37683.patch -#Patch0004: CVE-2021-39534.patch +Patch0004: CVE-2021-29534.patch Patch0005: CVE-2021-29566.patch Patch0006: CVE-2021-37691.patch Patch0007: CVE-2021-37689.patch @@ -182,6 +182,9 @@ Patch0170: CVE-2021-29516-2.patch Patch0171: CVE-2021-29516-3.patch Patch0172: CVE-2021-29516-4.patch Patch0173: CVE-2021-37679.patch +Patch0174: CVE-2021-37690-1.patch +Patch0175: CVE-2021-37690-2.patch +Patch0176: CVE-2021-37690-3.patch Requires: python3-future Requires: python3-numpy @@ -228,6 +231,9 @@ bazel --output_user_root=`pwd`/../output_user_root build //tensorflow/tools/pip_ %{_bindir}/* %changelog +* Thu Sep 16 2021 yaoxin - 2.3.1-6 +- Fix CVE-2021-29534 CVE-2021-37690 + * Tue Sep 14 2021 houyingchao - 2.3.1-5 - Fix CVE-2020-26267 CVE-2021-29515 CVE-2021-29551 CVE-2021-37645 CVE-2021-37681 CVE-2021-29516 CVE-2021-37679 -- Gitee