Headline
CVE-2022-35982: Add sparse tensor validation to SparseBincountOp. · tensorflow/tensorflow@40adbe4
TensorFlow is an open source platform for machine learning. If SparseBincount
is given inputs for indices
, values
, and dense_shape
that do not make a valid sparse tensor, it results in a segfault that can be used to trigger a denial of service attack. We have patched the issue in GitHub commit 40adbe4dd15b582b0210dfbf40c243a62f5119fa. The fix will be included in TensorFlow 2.10.0. We will also cherrypick this commit on TensorFlow 2.9.1, TensorFlow 2.8.1, and TensorFlow 2.7.2, as these are also affected and still in supported range. There are no known workarounds for this issue.
@@ -366,7 +366,7 @@ def test_sparse_bincount_all_count(self, dtype): num_rows = 128 size = 1000 n_elems = 4096 inp_indices = np.random.randint(0, num_rows, (n_elems,)) inp_indices = np.random.randint(0, num_rows, (n_elems, 1)) inp_vals = np.random.randint(0, size, (n_elems,), dtype=dtype)
np_out = np.bincount(inp_vals, minlength=size) @@ -390,7 +390,7 @@ def test_sparse_bincount_all_count_with_weights(self, dtype): num_rows = 128 size = 1000 n_elems = 4096 inp_indices = np.random.randint(0, num_rows, (n_elems,)) inp_indices = np.random.randint(0, num_rows, (n_elems, 1)) inp_vals = np.random.randint(0, size, (n_elems,), dtype=dtype) inp_weight = np.random.random((n_elems,))
@@ -415,7 +415,7 @@ def test_sparse_bincount_all_binary(self, dtype): num_rows = 128 size = 10 n_elems = 4096 inp_indices = np.random.randint(0, num_rows, (n_elems,)) inp_indices = np.random.randint(0, num_rows, (n_elems, 1)) inp_vals = np.random.randint(0, size, (n_elems,), dtype=dtype)
np_out = np.ones((size,)) @@ -440,7 +440,7 @@ def test_sparse_bincount_all_binary_weights(self, dtype): num_rows = 128 size = 10 n_elems = 4096 inp_indices = np.random.randint(0, num_rows, (n_elems,)) inp_indices = np.random.randint(0, num_rows, (n_elems, 1)) inp_vals = np.random.randint(0, size, (n_elems,), dtype=dtype) inp_weight = np.random.random((n_elems,))
@@ -532,6 +532,27 @@ def test_size_is_not_scalar(self): # b/206619828 weights=[0, 0], binary_output=False))
def test_sparse_bincount_input_validation(self): np.random.seed(42) num_rows = 128 size = 1000 n_elems = 4096 inp_indices = np.random.randint(0, num_rows, (n_elems, 1)) inp_vals = np.random.randint(0, size, (n_elems,))
# Insert negative index. inp_indices[10, 0] = -2
with self.assertRaisesRegex((ValueError, errors.InvalidArgumentError), “out of bounds”): self.evaluate( gen_math_ops.sparse_bincount( indices=inp_indices, values=inp_vals, dense_shape=[num_rows], size=size, weights=[]))
class RaggedBincountOpTest(test_util.TensorFlowTestCase, parameterized.TestCase):
Related news
### Impact If `SparseBincount` is given inputs for `indices`, `values`, and `dense_shape` that do not make a valid sparse tensor, it results in a segfault that can be used to trigger a denial of service attack. ```python import tensorflow as tf binary_output = True indices = tf.random.uniform(shape=[], minval=-10000, maxval=10000, dtype=tf.int64, seed=-1288) values = tf.random.uniform(shape=[], minval=-10000, maxval=10000, dtype=tf.int32, seed=-9366) dense_shape = tf.random.uniform(shape=[0], minval=-10000, maxval=10000, dtype=tf.int64, seed=-9878) size = tf.random.uniform(shape=[], minval=-10000, maxval=10000, dtype=tf.int32, seed=-10000) weights = tf.random.uniform(shape=[], minval=-10000, maxval=10000, dtype=tf.float32, seed=-10000) tf.raw_ops.SparseBincount(indices=indices, values=values, dense_shape=dense_shape, size=size, weights=weights, binary_output=binary_output) ``` ### Patches We have patched the issue in GitHub commit [40adbe4dd15b582b0210dfbf40c243a62f5119fa](https://git...