From: Chao Huang <chahuan(a)qti.qualcomm.com>
Hi Rui,
Thanks for the comments. I don't think we need MODULES_PARTIAL here:
the readable modules go into the usual module and symbol tables during
initialization, and mod -s/-S can use them without a separate recovery
state. The kset walk now uses do_list_no_hash() rather than the hash
queue used in v1.
I'd like crash to handle this at startup, without asking the user to
recover modules first. A list can be readable but incomplete, and the
user may not know anything is missing. In v1, module_init() only tried
kset after a modules-list read failure. This version checks the forward
list, the reverse list and module_kset, then combines the valid entries
and deduplicates them by module address. That also covers modules
silently omitted from an otherwise readable list.
If kset finds additional modules, one warning reports the number added.
If it only finds modules already collected from the list, there is no
extra message.
Most of the enumeration changes are in kernel.c. Both list directions
are walked independently, so a broken link on one side does not stop
the other scan. The kset scan skips built-in objects with no struct
module and checks the module_kobject.mod/module.mkobj relationship.
Candidates share the same name and memory-range checks; a bad candidate
does not discard the modules already collected. kset_walk() in tools.c
is a thin wrapper around the existing traversal and loop detection.
The collected addresses are then passed to the existing core/init or
module.mem symbol builders in symbols.c. This avoids walking the
damaged list again and builds the memory symbols needed by the .ko
loader to work out runtime section addresses. Symbol sizing and
construction use the same range and count checks, so damaged optional
init or symbol data can be skipped while keeping usable core data.
The public two-argument builder interfaces are preserved, and the new
offsets are appended to offset_table. Cleanup covers the temporary
address array and the zero-candidate case during reinitialization.
Later mod -s/-S calls use the existing loading path. They do not rebuild
the module table or drop previously loaded object data. bt is unchanged.
During testing of v1, we also ran into a size=0 case. This
revision skips candidates with no core storage and avoids allocating
zero-sized kallsyms buffers. Empty init regions or individual empty
module.mem regions are still allowed.
I also added checks for other possible cases, including oversized ELF
symbol counts, invalid string offsets and failed init reads. These
checks guard the table and string accesses and prevent reuse of an
init buffer after a failed read.
Live, legacy kallsyms-header and PaX paths are left as before, and
--no_modules is still respected. Modules absent from both sources,
or symbol data missing from the dump, cannot be recovered this way.
Thanks,
Chao