From 08c6c9e4ce0dbb494cd6067045168ade2909e837 Mon Sep 17 00:00:00 2001 From: Sarah Lacard Date: Sat, 2 May 2026 11:54:40 -0600 Subject: [PATCH] =?UTF-8?q?blue:=20catches=20KG#260=20=E2=80=94=20=5F=5Ffo?= =?UTF-8?q?rmat=5F=5F=20protocol?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernelguard.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/kernelguard.py b/kernelguard.py index f086847..27bd22e 100644 --- a/kernelguard.py +++ b/kernelguard.py @@ -3025,6 +3025,15 @@ def detect_precision_downgrade(code: str | SubmissionFacts) -> list[dict]: return matches +def detect_format_protocol(code: str | SubmissionFacts) -> list[dict]: + facts = ensure_submission_facts(code) + code = facts.raw_code + if re.search(r'def\s+__format__\s*\(', code) and re.search(r'\bformat\s*\(', code): + if re.search(r'\bglobal\s+\w+', code): + return [{"pattern": "FORMAT_PROTOCOL", "severity": "critical", "evidence": "__format__ defined on custom class with global state (format() protocol caching bypass)"}] + return [] + + # --------------------------------------------------------------------------- # Score anomaly detection # --------------------------------------------------------------------------- @@ -3653,6 +3662,10 @@ class RulePolicy: "NEAR_CLONE_SPAM", "administrative", "support", SUSPICIOUS_ONLY, (), (), "downgrade", ), + "FORMAT_PROTOCOL": RulePolicy( + "FORMAT_PROTOCOL", "result_reuse", "hard", AUTO_FILTER, (), + (), "keep", + ), } BASE_SCORE_CONFIG = { @@ -3790,6 +3803,7 @@ def support_only_patterns(matched_patterns: list[dict]) -> bool: detect_thread_injection, detect_lazy_tensor, detect_precision_downgrade, + detect_format_protocol, ] BASE_DETECTOR_SPECS = [ @@ -3827,6 +3841,7 @@ def support_only_patterns(matched_patterns: list[dict]) -> bool: ("thread_injection", detect_thread_injection), ("lazy_tensor", detect_lazy_tensor), ("precision_downgrade", detect_precision_downgrade), + ("format_protocol", detect_format_protocol), ] VALID_RULE_OUTCOMES = {AUTO_FILTER, SUSPICIOUS_ONLY, TELEMETRY_ONLY} @@ -4705,6 +4720,7 @@ def _worker_parquet(args: tuple) -> dict: "TOKEN_PASTE_CUDA_API", "SEQUENCE_BATCH_GRAPH", "PARTIAL_GRAPH_KEY", "RUNTIME_PACKAGE_INSTALL", "PRECISION_DOWNGRADE", "SCORE_PHYSICS_FLOOR", "SCORE_IMPOSSIBLE", "SCORE_SUSPECT_FLOOR", "SCORE_BROKEN", "SCORE_EXTREME_SPEEDUP", "DUPLICATE_SPAM", "NEAR_CLONE_SPAM", + "FORMAT_PROTOCOL", ]