CVE-2022-36012 (Other, published 2022-09-16T23:15Z)
Description: value: TensorFlow is an open source platform for machine learning. When `mlir::tfg::ConvertGenericFunctionToFunctionDef` is given empty function attributes, it crashes. We have patched the issue in GitHub commit ad069af92392efee1418c48ff561fd3070a03d7b. 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.
Severity: nan (CVSS v3 base score: 7.5)
Weakness: CWE-617 \u2014 Reachable Assertion
The product contains an assert() or similar statement that can be triggered by an attacker, which leads to an application exit or other behavior that is more severe than necessary.
Repository: https://github.com/tensorflow/tensorflow
Files changed:
tensorflow/core/ir/importexport/functiondef_import.cc
tensorflow/core/ir/importexport/tests/graphdef_to_mlir/invalid_generic_func_with_empty_control_result.pbtxt
tensorflow/core/ir/importexport/tests/graphdef_to_mlir/invalid_generic_func_with_empty_input.pbtxt
tensorflow/core/ir/importexport/tests/graphdef_to_mlir/invalid_generic_func_with_empty_result.pbtxt
Commit message: [tfg][functiondef_import] Error on empty edge names

Return an error in the generic function importer if an edge name is empty.

PiperOrigin-RevId: 449953062


Vulnerable code:
    for (const std::string& input : node.input())
    if (position == output_name_to_position.end())
    if (position == control_output_to_position.end())

Fixed code:
#include "tensorflow/core/platform/statusor.h"
using tensorflow::StatusOr;
    for (const std::string& input : node.input()) {
      if (input.empty())
        return InvalidArgument("Node '", node.name(), "' has an empty input");
    }
    if (position == output_name_to_position.end()) {
    }
    if (ret_val.second.empty()) {
      return InvalidArgument("Function '", func.signature().name(),
                             "' has empty result name");
    }
    if (position == control_output_to_position.end()) {
    }
    if (ret_val.second.empty()) {
      return InvalidArgument("Function '", func.signature().name(),
                             "' has empty control result name");
    }
# RUN: not tfg-translate -graphdef-to-mlir %s 2>&1 | FileCheck %s

# CHECK: Function 'foo' has empty control result name

library {
  function {
    signature {
      name: "foo"
      control_output: "output"
    }
    node_def {
      name: "y"
      op: "NoOp"
      attr {
        key: "T"
        value {
          placeholder: "T"
        }
      }
    }
    control_ret {
      key: "output"
      value: ""
    }
  }
}
# RUN: not tfg-translate -graphdef-to-mlir %s 2>&1 | FileCheck %s

# CHECK: Node 'y' has an empty input

library {
  function {
    signature {
      name: "foo"
    }
    node_def {
      name: "y"
      input: ""
      op: "Identity"
      attr {
        key: "T"
        value {
          placeholder: "T"
        }
      }
    }
  }
}
# RUN: not tfg-translate -graphdef-to-mlir %s 2>&1 | FileCheck %s

# CHECK: Function 'foo' has empty result name

library {
  function {
    signature {
      name: "foo"
      output_arg {
        name: "output"
        type: DT_INT32
      }
    }
    node_def {
      name: "y"
      op: "NoOp"
      attr {
        key: "T"
        value {
          placeholder: "T"
        }
      }
    }
    ret {
      key: "output"
      value: ""
    }
  }
}