Skip to content

Latest commit

 

History

History
113 lines (88 loc) · 8.78 KB

File metadata and controls

113 lines (88 loc) · 8.78 KB

Mitigation Strategies Analysis for taichi-dev/taichi

  • Description:

    1. Define a Whitelist (Taichi-Specific): Create a precise list of allowed Taichi language constructs. This goes beyond basic Python syntax and includes Taichi-specific elements:
      • Allowed decorators (e.g., @ti.kernel, @ti.func, @ti.struct_class). Disallow or carefully scrutinize others (e.g., @ti.pyfunc if external Python calls are risky).
      • Allowed data types (e.g., ti.i32, ti.f32, ti.types.vector(3, ti.f32)). Restrict or disallow custom data types if they introduce complexity or potential vulnerabilities.
      • Allowed control flow structures (e.g., for, if, while). Limit or disallow recursion if it's not strictly necessary.
      • Allowed built-in functions (e.g., ti.sin, ti.cos, ti.atomic_add). Disallow or carefully examine any functions that interact with external resources or have side effects.
      • Allowed operations (e.g., arithmetic, bitwise). Restrict or disallow potentially dangerous operations.
    2. Develop a Parser/Validator (Taichi-Focused):
      • Use Python's ast module to parse the Taichi kernel code (which is, at its core, Python code).
      • Traverse the AST and check each node against the whitelist. Specifically, look for ast.Call nodes where the function being called is a Taichi decorator or function.
      • For data inputs, use Taichi's type system (e.g., ti.types) to validate the types and shapes of arguments passed to kernels.
    3. Reject Invalid Code/Data: If any part of the Taichi code or data violates the whitelist, reject it immediately.
    4. Log Validation Failures: Log all rejections.
  • Threats Mitigated:

    • Untrusted Code Execution (High Severity): Prevents malicious Taichi code (specifically, code using disallowed Taichi features) from being compiled and executed.
    • Denial of Service (Medium Severity): Limits the complexity of Taichi code, reducing the chance of resource exhaustion.
  • Impact:

    • Untrusted Code Execution: Significant risk reduction (e.g., 80-95%, depending on whitelist strictness).
    • Denial of Service: Moderate risk reduction (e.g., 40-60%).
  • Currently Implemented:

    • Example (Hypothetical): Basic data type validation using ti.types is in src/input_validation.py. A simple whitelist of Taichi functions is in config/taichi_whitelist.json.
    • (Real Project: Specify files and functions where Taichi-specific validation occurs.)
  • Missing Implementation:

    • Example (Hypothetical): Full AST-based validation of Taichi constructs is missing. Validation of loop structures and disallowed operations is incomplete.
    • (Real Project: Identify gaps in Taichi-specific validation.)
  • Description:

    1. Identify Limits: Determine appropriate limits for CPU time, memory, and GPU memory.
    2. Implement Limits (Taichi-Specific):
      • GPU Memory: Explore Taichi's API for controlling GPU memory allocation. This might involve using specific Taichi functions or configuration options when initializing the Taichi runtime (e.g., setting a maximum memory fraction). This is the most direct Taichi-specific control.
      • CPU Time/Memory (Indirect): While Taichi doesn't directly offer CPU time or general memory limits within a kernel, you can use Python's standard library (e.g., threading.Timer, resource module) around the Taichi kernel invocation to enforce limits on the entire Taichi process. This isn't purely Taichi-specific, but it's the closest you can get without external tools.
    3. Monitor (Indirect): Use Python's psutil library (or similar) to monitor the Taichi process's resource usage from outside the kernel.
    4. Terminate: If limits are exceeded, terminate the Taichi process.
    5. Log: Log all violations.
  • Threats Mitigated:

    • Denial of Service (Medium Severity): Prevents excessive resource consumption.
  • Impact:

    • Denial of Service: Significant risk reduction (e.g., 70-90%).
  • Currently Implemented:

    • Example (Hypothetical): No direct Taichi API calls for resource limiting are used. A basic CPU timeout using threading.Timer is in src/kernel_executor.py.
    • (Real Project: Specify any Taichi API usage for resource control.)
  • Missing Implementation:

    • Example (Hypothetical): Investigate and implement Taichi's GPU memory limiting features. Implement more robust CPU time and memory limits using psutil and potentially the resource module.
    • (Real Project: Identify missing Taichi-specific resource controls.)
  • Description:

    1. Track Taichi Releases: Monitor the official Taichi GitHub repository (https://github.com/taichi-dev/taichi) for new releases. Subscribe to release notifications.
    2. Review Release Notes: Carefully examine the release notes for each new version, paying close attention to:
      • Security Fixes: Explicitly mentioned security vulnerabilities that have been addressed.
      • Bug Fixes: Bugs, even if not explicitly security-related, can sometimes lead to vulnerabilities.
      • Deprecations: Deprecated features might indicate potential future security issues.
    3. Update Regularly: Update your application's Taichi dependency to the latest stable release, after appropriate testing.
    4. Test After Update: Thoroughly test your application after each Taichi update to ensure compatibility and that no new issues have been introduced.
  • Threats Mitigated:

    • Compiler Bugs (Variable Severity): Reduces the risk of exploiting vulnerabilities in the Taichi compiler.
  • Impact:

    • Compiler Bugs: Risk reduction (degree depends on the specific bugs fixed).
  • Currently Implemented:

    • Example (Hypothetical): The application uses Taichi version X.Y.Z. There's no formal process for tracking updates.
    • (Real Project: Describe the current Taichi version and update practices.)
  • Missing Implementation:

    • Example (Hypothetical): Establish a formal process for monitoring Taichi releases and updating the dependency.
    • (Real Project: Identify gaps in Taichi update procedures.)
  • Description:

    1. Identify Unnecessary Features: Analyze your application's use of Taichi and identify any features that are not strictly required. This might include:
      • Advanced metaprogramming capabilities.
      • Custom data types.
      • Specific backends (e.g., if you only need CPU, disable GPU backends).
      • Experimental features.
    2. Disable Features:
      • Configuration Options: Check the Taichi documentation for configuration options that can disable specific features. This might involve setting environment variables or modifying Taichi's initialization.
      • Code Modifications: If configuration options are not available, you might need to modify the Taichi source code (if you have a fork) or avoid using the unnecessary features in your own code.
    3. Test Thoroughly: After disabling features, thoroughly test your application to ensure that it still functions correctly.
  • Threats Mitigated:

    • Untrusted Code Execution (Variable Severity): Reduces the attack surface by limiting the available Taichi features that could be exploited.
    • Compiler Bugs (Variable Severity): Reduces the likelihood of encountering bugs in unused features.
  • Impact:

    • Untrusted Code Execution: Risk reduction depends on the specific features disabled.
    • Compiler Bugs: Risk reduction depends on the specific features disabled.
  • Currently Implemented:

    • Example (Hypothetical): No specific Taichi features have been explicitly disabled.
    • (Real Project: List any Taichi features that have been disabled.)
  • Missing Implementation:

    • Example (Hypothetical): Analyze the application's Taichi usage and identify any features that can be safely disabled. Investigate Taichi's configuration options for disabling features.
    • (Real Project: Identify opportunities to disable unnecessary Taichi features.)