-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[WIP] Harden _is_target_allowed by adding runtime class validation on top of prefix checks to prevent unsafe target resolution #14540
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
base: main
Are you sure you want to change the base?
Conversation
…f prefix checks to prevent unsafe target resolution Signed-off-by: Kunal Dhawan <[email protected]>
…ly from nemo.core.classes.modelPT Signed-off-by: Kunal Dhawan <[email protected]>
Signed-off-by: KunalDhawan <[email protected]>
…PT inside the function Signed-off-by: Kunal Dhawan <[email protected]>
Signed-off-by: KunalDhawan <[email protected]>
This PR is stale because it has been open for 14 days with no activity. Remove stale label or comment or update or this will be closed in 7 days. |
Some tests are failing. @chtruong814 for review as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appears to be failing tests but seems to alleviate the bug. Will review again when tests pass.
nemo/core/classes/common.py
Outdated
# Must be a class, not a function! | ||
if not isinstance(obj, type): | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something for usability we want to be sure of: this necessarily excludes all of torch.nn.functional
, so we'll want to be sure there's no regression.
nemo/core/classes/common.py
Outdated
SAFE_BASES = (torch.nn.Module, ModelPT) | ||
|
||
# Must inherit from a known safe base! | ||
if not issubclass(obj, SAFE_BASES): | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to fix the underlying bug, but we should be very cautious with future changes since
>>> isinstance(torch.nn.parameter.torch.multiprocessing.Process, type)
True
Will pass the previous check but not this one.
If it comes down to it, may simply want to explicitly exclude things from r"torch\.nn\.\w+\.torch\.\w+"
Signed-off-by: Kunal Dhawan <[email protected]>
Signed-off-by: KunalDhawan <[email protected]>
…intaining security Signed-off-by: Kunal Dhawan <[email protected]>
Signed-off-by: KunalDhawan <[email protected]>
Important
The
Update branch
button must only be pressed in very rare occassions.An outdated branch is never blocking the merge of a PR.
Please reach out to the automation team before pressing that button.
What does this PR do ?
Previously,
_is_target_allowed
only checked whether the_target_
string in a config started with an allowed prefix (e.g.,torch.nn
). This was insufficient, since Python allows nested/indirect module resolution (e.g.,torch.nn.utils.rnn.torch.os.system
), which could be abused to execute arbitrary code at model load time.In the updated implementation, we:
hydra.utils.get_class
Collection: core
Changelog
_is_target_allowed
function in nemo/core/classes/common.py has been updatedGitHub Actions CI
The Jenkins CI system has been replaced by GitHub Actions self-hosted runners.
The GitHub Actions CI will run automatically when the "Run CICD" label is added to the PR.
To re-run CI remove and add the label again.
To run CI on an untrusted fork, a NeMo user with write access must first click "Approve and run".
Before your PR is "Ready for review"
Pre checks:
PR Type:
If you haven't finished some of the above items you can still open "Draft" PR.
Who can review?
Anyone in the community is free to review the PR once the checks have passed.
Contributor guidelines contains specific people who can review PRs to various areas.
Additional Information