Document that an unimplemented opcode raises rather than being skipped (and 4 missing opcodes)

Aperta
#322 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
64/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python
Ambito
security

Direzione di ricerca

Inizia da Opcode.new e dalla tabella OPCODES_BY_NAME in fickling.fickle, quindi confronta la tabella con Python's pickletools.opcodes. Documenta che gli opcode non supportati sollevano NotImplementedError invece di essere ignorati e valuta l'aggiunta dei quattro opcode mancanti indicati. Il lavoro è completato quando la garanzia di sicurezza è documentata e qualsiasi modifica agli opcode è coperta dai controlli esistenti del progetto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Fickling's opcode table is missing four opcodes that CPython's pickletools knows, and the safety of that gap rests entirely on an undocumented behaviour: Opcode.__new__ raises on an unimplemented opcode rather than skipping it. That failure mode is load-bearing for downstream tools, and I would like to see it stated as a guarantee.

This is not a vulnerability report — the current behaviour is safe. It is a request to document what makes it safe, plus four opcodes you may want to add.

The gap

>>> import pickletools
>>> from fickling.fickle import OPCODES_BY_NAME
>>> sorted({op.name for op in pickletools.opcodes} - set(OPCODES_BY_NAME))
['BYTEARRAY8', 'FLOAT', 'NEXT_BUFFER', 'READONLY_BUFFER']

68 opcodes in CPython, 64 in fickling. FLOAT is protocol 0, not an exotic protocol-5 addition.

Why it matters, and why it is currently fine

A pickle can be made whose prefix fickling cannot decode but CPython walks straight through:

>>> import io, pickletools
>>> data = b"}" + b"F1.0\n" + b"cos\nsystem\n(S'echo pwned'\ntR."
>>> [op.name for op, _, _ in pickletools.genops(io.BytesIO(data))]
['EMPTY_DICT', 'FLOAT', 'GLOBAL', 'MARK', 'STRING', 'TUPLE', 'REDUCE', 'STOP']

CPython reaches GLOBAL and REDUCE. Fickling cannot get past FLOAT.

That is not exploitable today, because the dispatch in Opcode.__new__ raises instead of continuing:

raise NotImplementedError(f"TODO: Add support for Opcode {info.name}")

The file therefore surfaces as an error, and a caller that treats errors as unsafe is protected. The important detail is that this is a single central dispatch, so it holds uniformly for all four and for any future unknown opcode — the safe behaviour is a property of the architecture, not an accident of these particular opcodes.

The request

Document that an unimplemented opcode raises rather than being skipped, as a guarantee rather than an implementation detail.

Downstream tools depend on it whether they realise it or not. Ours does: we treat "fickling could not parse this" as "do not report this file as clean". If the dispatch were ever relaxed to skip unknown opcodes — a plausible, well-intentioned robustness change — every such tool would silently start reporting these files as safe, and nothing in the current documentation says that would be a breaking change.

Adding the four opcodes is worth doing and is additive. But it narrows this particular gap rather than closing the class: the table can drift from CPython again at the next protocol addition, and the loud failure is what makes that drift safe.

A note on your reporting guidelines

SECURITY.md asks for reproductions via the opcode API rather than raw byte strings, and I have followed that elsewhere. It is not possible here by construction: the finding is precisely that FLOAT, BYTEARRAY8, NEXT_BUFFER and READONLY_BUFFER have no representation in the opcode API, because they are not implemented. Raw bytes are the only way to express a pickle containing them — which is itself a small argument for adding them.

I have used echo in the proof of concept, per the same guidance.

Versions

master at 854c99a; also reproduced on the 0.1.12 release.

Lingua principale
Python
Stelle
678
Fork
89
Merge medio
41m
PR unite (30g)
14

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di trailofbits/fickling

Tutte le issue di trailofbits/fickling

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.