Skip to content

Commit a86eb45

Browse files
committed
Handle ELF binary with no program segments
Do not return False for NX and No for RELRO when there is no program segments in the ELF binary file (e.g. kernel module). This is inspired from slimm609/checksec@29aea68 For RELRO, a new NA value is added For NX, True is returned to avoid changing NX type from boolean to string Signed-off-by: Fabrice Fontaine <[email protected]>
1 parent 265d45c commit a86eb45

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

checksec/binary.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ def __init__(self, bin_path: Path):
1919

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

2429
@property
2530
def checksec_state(self) -> Union["ELFChecksecData", "PEChecksecData"]:

checksec/elf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class RelroType(Enum):
7070
No = 1
7171
Partial = 2
7272
Full = 3
73+
NA = 4
7374

7475

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

118119
@property
119120
def relro(self) -> RelroType:
121+
# Handle binary with no program segments (e.g., Kernel modules)
122+
# In this case, return NA
123+
if len(self.bin.segments) == 0:
124+
return RelroType.NA
125+
120126
if self.bin.get(lief.ELF.Segment.TYPE.GNU_RELRO) is None:
121127
return RelroType.No
122128

0 commit comments

Comments
 (0)