Repository navigation
linux: follow list pointers in walk_internal_list (keyboard_notifiers) - #2102
ricardojrdez wants to merge 2 commits into
Conversation
walk_internal_list built each element at the address of the pointer it was given (list_start.vol.offset) instead of the address it points to. For linux.malware.keyboard_notifiers, the list head pointer was therefore read as a notifier_block: its notifier_call was the head value (the address of the first notifier_block), and the real callbacks were never visited. Dereference the pointer to locate each element.
|
Thanks for this. Here are my comments as a random vol user, Firstly - something that isn't covered in my testing library! Doh! I built two images with speakup loaded, which registers a real keyboard notifier: one on Ubuntu 18.04 (4.15.0-213) and one on 24.04 (6.8.0-117). On both, develop reports keyboard_notifier_block and this PR reports keyboard_notifier_call. I confirmed both against /proc/kallsyms in the guest - so that is good. I haven't been able to test the positive case against everything (e.g. where it should find something) but running this against all the other images doesn't accidentally break anything as far as I can see. For the Again I'm not sure on the the testing bits, my only comment is being absolutely sure with the asserts that we're not off by one etc. It's far to easy to do. Thanks |
- Emit a debug message with the pointer location and target when walk_internal_list stops on an unreadable pointer, so skipped list elements are visible. - max_count is documented as the maximum number of yielded elements, but the walk yielded max_count + 1. Check the bound before yielding. - Tests: assert the exact elements under max_count, the max_count == length boundary, and the unreadable-pointer stop and log.
|
Thanks a lot for testing this, and for building the speakup images. It's good to have a real notifier confirmed against I've pushed 486a486 with your suggestions:
|
|
Great - thanks for making those changes. I still feel a bit uneasy around the testing - adding things like |
|
Thanks @eve-mem! I agree with you on the testing side. A first step could be to move this kind of helper into a shared module under test/, so other plugin tests can reuse it instead of copying it. Longer term, it might be worth deciding how unit tests should build symbol-backed objects without a full memory image. One option that comes to my mind is a minimal ISF plus an in-memory layer, which would test the real object code rather than duck-typed fakes. I'd keep that out of this PR so the fix stays small. I'm happy to open a separate issue so the maintainers can weigh in on the approach, and I can help with the work once there's agreement on a direction. |
linux.malware.keyboard_notifiersreports the address of the firstnotifier_blockas a callback and never reports the real callbacks.LinuxUtilities.walk_internal_list()receives the list head's pointer member (keyboard_notifier_list.head) and builds each element withvmlinux.object(struct_name, offset=list_start.vol.offset).vol.offsetof a pointer object is where the pointer is stored, not where it points. The first "element" is therefore built on top of theheadmember itself: itsnotifier_callis the value ofhead(the address of the firstnotifier_block), and itsnextis whatever followsheadin memory, which ends the walk. The realnotifier_blocks and theirnotifier_calls are never visited.keyboard_notifiersis the only caller ofwalk_internal_listin the tree.Change
Dereference the pointer to find each element (
list_start.dereference().vol.offset), and use that address for the repeat-entry check. The readable check now runs before the address is used.LinuxUtilitiesis bumped to 2.4.1; the method signature is unchanged and the docstring now says thatlist_startis a pointer to the first element.Testing
Added
test/test_linux_walk_internal_list.py, which walks a fake list whose head pointer is stored at a different address from the first element. It checks the yielded element addresses, the empty list, a cycle, andmax_count.Real image: Linux 6.18.59 x86-64 (VirtualBox core) with an out-of-tree module that calls
register_keyboard_notifier()withmemmodel_kbd_nb.notifier_call = memmodel_kbd_notify. Addresses from the guest's/proc/kallsymstaken from the same boot:AddressModulememmodel_kbd_notify=0xffffffffc0601010,memmodel_kbd_nb=0xffffffffc054b020memmodel_hook0xffffc054b020(thenotifier_block)0xffffc0601010(the callback)memmodel_hookOn an Ubuntu 24.04 (6.8.0-117) image with no registered keyboard notifiers, both develop and this PR return an empty list.
The
Symbolcolumn is still N/A for a callback inside a module; that comes frommodule_lookup_by_address()and is not changed here.