-
Notifications
You must be signed in to change notification settings - Fork 708
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
Freeze .rodata before trying to load programs #1159
Conversation
5f3a44d
to
792bcdb
Compare
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.
LGTM.
Testing good on my side, thanks. |
// potentially pending creation. This is needed for frozen maps like .rodata | ||
// that need to be finalized before invoking the verifier. | ||
if !mapSpec.Type.canStoreMapOrProgram() { | ||
if err := m.finalize(mapSpec); err != nil { |
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.
Can you remind me why we can't populate deferred maps at this point 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.
Map fds need to be relocated into programs before a program can be loaded, but we can't populate a prog array without creating programs first. We've split up this process into multiple stages to keep things clear. Technically, we only need to defer populating prog arrays, but we can refactor this again later if new requirements pop up.
This test fails if .rodata is not frozen when freeze_rodata() is verified. Signed-off-by: Timo Beckers <[email protected]>
`cl.loadMap()` now finalizes maps that can be finalized right after creation, aka. 'scalar' maps without references to other bpf resources. Prog maps or outer maps are populated at a later stage. After doing a first pass over all requested Maps and Programs, a separate pass is run by `cl.populateMaps()` (renamed to `populateDeferredMaps()`) that only considers prog maps and outer maps, lazy-loads dependencies and fully resolves Spec.Contents, then finalizes the Map. This fixes .rodata being frozen after the verifier has run, which not only defeats the point of having constants, but also causes verifier errors if a runtime-provided constant is used as a return code or helper argument that must be proven to be within a certain range during verification. Signed-off-by: Timo Beckers <[email protected]>
792bcdb
to
ff77f82
Compare
As reported in #1143 and #1156.
The change is fairly minimal, had to reindent most of
populateMaps()
.The gist of it is
cl.loadMap()
now finalizes maps that can be finalized right after loading, aka. 'scalar' maps without references to other bpf resources. Prog maps or outer maps are skipped.After doing a first pass over all requested Maps and Programs, a separate pass is run by the renamed
populateDeferredMaps()
that only considers prog maps and outer maps, lazy-loads dependencies and fully resolvesSpec.Contents
, then finalizes the Map.