Skip to content

Handle ELF binary with no program segments #140

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion checksec/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def __init__(self, bin_path: Path):

@property
def has_nx(self) -> bool:
return self.bin.has_nx
# Handle ELF binary with no program segments (e.g., Kernel modules)
# In this case, return True
if isinstance(self.bin, lief.ELF.Binary) and len(self.bin.segments) == 0:
return True
else:
return self.bin.has_nx

@property
def checksec_state(self) -> Union["ELFChecksecData", "PEChecksecData"]:
Expand Down
6 changes: 6 additions & 0 deletions checksec/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class RelroType(Enum):
No = 1
Partial = 2
Full = 3
NA = 4


class PIEType(Enum):
Expand Down Expand Up @@ -117,6 +118,11 @@ def set_dyn_syms(self) -> FrozenSet[str]:

@property
def relro(self) -> RelroType:
# Handle binary with no program segments (e.g., Kernel modules)
# In this case, return NA
if len(self.bin.segments) == 0:
return RelroType.NA

if self.bin.get(lief.ELF.Segment.TYPE.GNU_RELRO) is None:
return RelroType.No

Expand Down
2 changes: 1 addition & 1 deletion tests/binaries
Submodule binaries updated 1 files
+ elf/relro_na
4 changes: 2 additions & 2 deletions tests/e2e/test_e2e_elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_bool_prop(prop: str, is_enabled: bool):

@pytest.mark.parametrize("relro_type", list(RelroType))
def test_relro(relro_type: RelroType):
"""Test that relro type is No/Partial/Full"""
"""Test that relro type is No/Partial/Full/NA"""
bin_path = ELF_BINARIES / f"relro_{relro_type.name.lower()}"
chk_data = run_checksec(bin_path)
assert chk_data[str(bin_path)]["relro"] == relro_type.name
Expand All @@ -37,7 +37,7 @@ def test_relro_full_df1():

@pytest.mark.parametrize("pie_type", list(PIEType))
def test_pie(pie_type):
"""Test that PIE is No/Partial/Full"""
"""Test that PIE is No/Partial/Full/NA"""
bin_path = ELF_BINARIES / f"pie_{pie_type.name.lower()}"
chk_data = run_checksec(bin_path)
assert chk_data[str(bin_path)]["pie"] == pie_type.name
Expand Down