Skip to content

Commit f014fa4

Browse files
committed
Handle binary with no program segments
Do not return False for NX and No for RELRO when there is no program segments in the 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 f014fa4

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

checksec/binary.py

+6-1
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 binary with no program segments (e.g., Kernel modules)
23+
# In this case, return True
24+
if len(self.bin.segments):
25+
return self.bin.has_nx
26+
else:
27+
return True
2328

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

checksec/elf.py

+6
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)