Skip to content

Commit

Permalink
Merge pull request volatilityfoundation#1503 from volatilityfoundatio…
Browse files Browse the repository at this point in the history
…n/issues/kmsg-msglen

Linux: Fix kmsg unguarded read of msg.len
  • Loading branch information
ikelos authored Jan 3, 2025
2 parents 801c933 + ac3e766 commit 66eb161
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions volatility3/framework/plugins/linux/kmsg.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,23 +317,27 @@ def run(self) -> Iterator[Tuple[str, str, str, str, str]]:
while cur_idx < end_idx:
msg_offset = log_buf_ptr + cur_idx # type: ignore
msg = self.vmlinux.object(object_type=log_struct_name, offset=msg_offset)
if msg.len == 0:
# As per kernel/printk.c:
# A length == 0 for the next message indicates a wrap-around to
# the beginning of the buffer.
cur_idx = 0
end_idx = log_next_idx
else:
facility, level, timestamp, caller = self.get_prefix(msg)
level_txt = self.get_level_text(level)
facility_txt = self.get_facility_text(facility)

for line in self.get_log_lines(msg):
yield facility_txt, level_txt, timestamp, caller, line
for line in self.get_dict_lines(msg):
yield facility_txt, level_txt, timestamp, caller, line

cur_idx += msg.len
try:
if msg.len == 0:
# As per kernel/printk.c:
# A length == 0 for the next message indicates a wrap-around to
# the beginning of the buffer.
cur_idx = 0
end_idx = log_next_idx
else:
facility, level, timestamp, caller = self.get_prefix(msg)
level_txt = self.get_level_text(level)
facility_txt = self.get_facility_text(facility)

for line in self.get_log_lines(msg):
yield facility_txt, level_txt, timestamp, caller, line
for line in self.get_dict_lines(msg):
yield facility_txt, level_txt, timestamp, caller, line

cur_idx += msg.len
except exceptions.InvalidAddressException:
vollog.warning("Kmsg buffer msg length could not be read")
return


class Kmsg_3_11_to_5_10(Kmsg_3_5_to_3_11):
Expand Down

0 comments on commit 66eb161

Please sign in to comment.