Repository navigation
linux.kmsg: read the newest printk ringbuffer record - #2101
ricardojrdez wants to merge 2 commits into
Conversation
The 5.10+ reader stopped when the cursor reached desc_ring.head_id, before reading that descriptor. head_id is the ID of the newest descriptor, so the most recent log record was never reported. Read from tail_id through head_id inclusive, bounded by the ring size.
|
Hello! Here are my thoughts as a random vol user. I tested this against all the images I have and it has meant that I get the extra lines on a lot of images. That's everything major/minor from 4 till now. No regressions on any images I have. I think if the walk hits the ring-size limit before reaching the newest record, it stops without saying so. On a corrupted or inconsistent image that silently loses records? Maybe add a vollog.debug(...) so it's noticed? I'm not sure about writing tests like that - not something I have really done before. I'm sure someone else can give you a view on it. Thanks! |
Suggested in review: if the descriptor IDs are inconsistent and the walk reaches desc_count descriptors without meeting head_id, records after that point are not reported. Emit a debug message so this is noticed.
|
Thanks a lot, Eve, for running it across your whole image set, and good catch on the silent stop. Pushed 578c289: when the walk reaches the ring-size bound without meeting |
|
Thanks for this (and for giving it a look over @eve-mem ). This seems reasonable, and the change is small and specific. Thank you for putting the vollog debugging message in place, generally where something unexpected may have happened we like to leave a debug message, so that someone somewhere has a chance of figuring out something's gone wrong. We'll run the tests over this, but otherwise it should be good to go in, thanks. |
|
Thanks for this, @ricardojrdez. I've been running into the missing-final-message issue during my recent Linux memory-forensics work. Before implementing a fix myself, I checked for existing PRs and found this one. It addresses exactly the same issue I was seeing. I applied your The kernel series I tested were 6.8, 6.12, 6.17, 6.18, 7.0, and 7.2:
Across these dumps, the output increased from 6,233 to 6,241 rows, recovering the missing final record in every case. All existing rows remained identical, including their fields and ordering. Each added row matched the message and timestamp in the capture-time The five tests included in this PR also passed. The newest-record test failed with the previous implementation, as expected. This resolves the issue in all eight captures I tested. I plan to build on this fix in my follow-up work. Thanks again! |
|
Thanks a lot, @cpuu, for taking the time to validate this. Glad it unblocks your follow-up work. Also, if you're interested in collaborating on research in Linux memory forensics, I'd be happy to hear from you. Feel free to ping me anytime! |
linux.kmsgon kernels >= 5.10 never reports the newest kernel-log record.Kmsg_5_10_to_.run()walks the printk descriptor ring withwhile cur_id != end_id, whereend_idisdesc_ring.head_id. Inkernel/printk/printk_ringbuffer.h,head_idis the ID of the newest descriptor (andtail_idthe oldest), so the loop exits when the cursor reaches the newest descriptor, before reading it. The most recent record is therefore always missing.The same loop also has no bound: if
tail_id == head_id(a ring with a single record) or the IDs are inconsistent in a smeared image, the cursor walks the whole 62-bit ID space.Change
Read from
tail_idthroughhead_idinclusive, and bound the walk by the ring size (desc_count), which is the maximum number of descriptors the ring can hold. The descriptor-state check is unchanged, so a head descriptor that is still reserved by a writer is skipped as before. The plugin version is bumped to 2.0.1.Testing
Added
test/test_linux_kmsg.py, which drivesKmsg_5_10_to_.run()over a fake descriptor ring and checks that the newest record is reported, that a reserved head is skipped, that a single-record ring works, and that inconsistent IDs are bounded by the ring size.Real images:
dmesgline written withecho ... > /dev/kmsgright before acquisitiondiamorphine: module verification failed: signature and/or required key missing - tainting kernelOn both images the first N rows are identical to develop; only the newest record is added.