..  Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

..    http://www.apache.org/licenses/LICENSE-2.0

..  Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

.. _dev-security:

Security Guide
==============

Reporting Security Issues
-------------------------

The Apache Software Foundation takes a very active stance in eliminating security problems and denial of service attacks against its products.
We strongly encourage folks to report such problems to our private security mailing list first, before disclosing them in a public forum.

Please note that the security mailing list should only be used for reporting undisclosed security vulnerabilities and managing the process of fixing such vulnerabilities. We cannot accept regular bug reports or other queries at this address. All mail sent to this address that does not relate to an undisclosed security problem in our source code will be ignored.
Questions about: if a vulnerability applies to your particular application obtaining further information on a published vulnerability availability of patches
and/or new releases should be addressed to the user Discuss forum.

The private security mailing address is: `security@apache.org <security@apache.org>`_.
Feel free to consult the `Apache Security guide <https://www.apache.org/security/>`_.


Security Model
--------------
The default binary generated by TVM only relies on a minimum runtime API.
The runtime depends on a limited set of system calls(e.g. malloc) in the system library.


TVM RPC server assumes that the user is trusted and needs to be used in a trusted network environment
and encrypted channels. It allows writings of arbitrary files into the server and provide
full remote code execution capabilities to anyone who can access this API.
All of the TVM APIs are designed to be used by trusted users, for APIs that involves URL,
we expect users to put in only trusted URLs.


RPC data exchange between the tracker, server and client are in plain-text.
It is recommended to use them under trusted networking environment or encrypted channels.


Loading serialized artifacts must only be done with input from a trusted source.


Security Advisories
-------------------

Subroutine Cache Hash Collision
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``SubroutineMixin._get_subroutine()`` in ``python/tvm/relax/frontend/nn/subroutine.py``
used ``tvm_ffi.structural_hash`` as the sole cache lookup key without a subsequent
``structural_equal`` verification. If two different ``arg_ty`` values produced the
same 64-bit hash, the cache would return a previously compiled function with
mismatched parameter shapes, leading to silently incorrect compiled output.

**Severity**: Low. The ``structural_hash`` function returns a 64-bit integer.
A natural hash collision requires approximately 2^32 distinct inputs (birthday bound),
making accidental collision extremely unlikely in normal compilation workflows.
The issue is primarily a correctness defect rather than a practically exploitable
security vulnerability.

**Root Cause**: The subroutine cache (``cls._gvar``) was keyed by
``(structural_hash(arg_ty, map_free_vars=True), is_dataflow)``.
A hash match was treated as proof of structural equality, skipping the necessary
``structural_equal`` check.

**Fix**: The cache now stores a list of ``(arg_ty, result)`` pairs per hash bucket.
On lookup, each candidate is verified with ``structural_equal`` before returning.
This follows the standard hash-table pattern: hash for bucket selection, equality
for final verification.
