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

Fix KeyError on resource save after calling Resource.remove_tag on parent and child tag class #513

Merged
merged 2 commits into from
Nov 14, 2024

Conversation

alchzh
Copy link
Collaborator

@alchzh alchzh commented Nov 12, 2024

One sentence summary of this PR (This should go in the CHANGELOG!)
Fix bug where calling Resource.remove_tag on both a tag class and a class that inherits from that class causes a KeyError on resource save.

Link to Related Issue(s)
#507

Does not fully fix that issue, since calling remove_tag on only the parent tag will not properly remove it.

Please describe the changes in your request.
Changes a call to .remove to .discard instead, since its possible the resource was already removed from the index in the same update cycle

Anyone you think should look at this, specifically?

…ne of its base classes would cause a `KeyError` on resource save.
@whyitfor whyitfor requested a review from rbs-jacob November 13, 2024 20:59
@alchzh alchzh merged commit 4edbd7d into redballoonsecurity:master Nov 14, 2024
4 checks passed
@alchzh alchzh deleted the fix/remove_tag_base branch November 15, 2024 00:24
alchzh added a commit to alchzh/ofrak that referenced this pull request Nov 18, 2024
alchzh added a commit that referenced this pull request Jan 3, 2025
* Improved allocation of .bss(-like) sections

The existing strategy for allocating `.bss` in RAM has a few problems
 - only one contiguous `.bss` region per FEM is supported.
 - alignment was not properly calculated for `.bss`, leading to linker errors

This commit generalizes our process for allocating `.text`, `.data`,
`.rodata`, etc. to `.bss` and like as well. It also improves our support
for different platforms by reducing the use of hardcoded section names
for determining behavior in favor of attributes defined by the binary
format like `sh_type` and `sh_flags`

With the new system, instead of passing `unsafe_bss_segment` to
`make_fem`, `.bss` sections are allocated during the `allocate_bom`
step. This is supported by free space regions that don't map to any
data on the parent resource.

Changes (incomplete):
- Use SHT_NOBITS type to detect .bss(-like) sections on ELF toolchains
- Create `FreeSpaceWithoutData`` tag for allocating regions for .bss.
  These are created from `MemoryRegion` children of resources with
  `data_range=None`
- Use SHF_ALLOC flag to determine whether section needs to be patched
  or not instead of hard coded list of names.
- Pass flag to compiler to prevent `.eh_frame` generation
- Backwards compatible with old bss allocation for now, emits
  deprecation warnings.

* Rename FreeSpaceWithoutData to RuntimeFreeSpace and FreeSpaceAnyData to AnyFreeSpace

* Rename NOBITS_LEGACY_VADDR to BSS_LEGACY_VADDR

* Allocate non-bss segments before bss segments in case legacy bss allocation used.

* Prevent allocate_bom from allocating sections that will be discarded

* Test legacy .bss allocation in ofrak_patch_maker_test

* Remove workaround for remove_tag bug (fixed in #513)

* Fix test_symbol_resolution for new return value of _resolve_symbols_within_BOM

* Update notebook to reflect new Segment and AssembledObject definition

* Add tests for dataless bss allocation to test_allocatable_allocate.py

* Add test cases for RuntimeFreeSpace in the Analyzer

* Add test for RuntimeFreeSpace in test_allocation_modifier

* Test FreeSpaceModifier for RuntimeFreeSpace creation

* Test .bss allocation both the new and old way in patch_maker

* Changelog entries
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

Successfully merging this pull request may close these issues.

2 participants