Skip to content

fix: add dangerous TF ops to SavedModel unsafe_tf_operators blocklist#341

Open
scruge1 wants to merge 1 commit intoprotectai:mainfrom
scruge1:fix/savedmodel-dangerous-ops
Open

fix: add dangerous TF ops to SavedModel unsafe_tf_operators blocklist#341
scruge1 wants to merge 1 commit intoprotectai:mainfrom
scruge1:fix/savedmodel-dangerous-ops

Conversation

@scruge1
Copy link

@scruge1 scruge1 commented Mar 24, 2026

Summary

  • Added 9 dangerous TensorFlow ops to the SavedModel scanner's unsafe_tf_operators blocklist
  • Previously only ReadFile and WriteFile were blocked out of 1,462 raw_ops
  • MatchingFiles enables filesystem enumeration that survives serialization and executes on tf.saved_model.load()

Why

A SavedModel containing tf.io.matching_files (the MatchingFiles op) passes modelscan with 0 issues but enumerates the filesystem when loaded. The scanner actively scans the .pb file, encounters MatchingFiles, classifies it as a known safe op (since it's in tf.raw_ops but not in the 2-item blocklist), and reports no issues.

Ops Added

Op Severity Risk
MatchingFiles HIGH Filesystem glob enumeration
WholeFileReader/V2 HIGH Reads entire files
InitializeTableFromTextFile/V2 MEDIUM File read via TF tables
LMDBReader MEDIUM Database read
PyFunc/PyFuncStateless/EagerPyFunc CRITICAL Arbitrary Python execution
FileSystemSetConfiguration MEDIUM Filesystem config modification

Testing

5 unit tests verifying each dangerous op category is present in the blocklist and original ops (ReadFile, WriteFile) are preserved.

The SavedModel scanner's blocklist contained only ReadFile and WriteFile.
TF has 1,462 raw_ops, many of which interact with the filesystem or
execute arbitrary code. Added 9 dangerous ops:

- MatchingFiles (HIGH): filesystem glob enumeration
- WholeFileReader/V2 (HIGH): reads entire files from disk
- InitializeTableFromTextFile/V2 (MEDIUM): reads files into TF tables
- LMDBReader (MEDIUM): reads LMDB databases
- PyFunc/PyFuncStateless/EagerPyFunc (CRITICAL): arbitrary Python execution
- FileSystemSetConfiguration (MEDIUM): modifies filesystem config

MatchingFiles is particularly dangerous as it survives SavedModel
serialization and executes on tf.saved_model.load(), enabling
filesystem enumeration (e.g., listing all .exe files in C:\Windows).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant