Repository navigation
Conversation
…ds no inode struct_file.get_inode() returns None when neither f_inode nor the dentry's d_inode is a readable, valid inode. is_valid() then read i_size of None and the AttributeError escaped from mm_struct.get_vma_iter(), stopping linux.proc.Maps and every other plugin that walks the VMAs of such a process. Skip the size check in that case; the other checks still apply.
The kernel sets the inode number of a SysV segment's file to the segment id (ipc/shm.c, newseg()), and the first segment of an IPC namespace has id 0. inode.is_valid() rejected i_ino 0 as smear, so struct_file.get_inode() returned None for that file: vm_area_struct.is_valid() crashed on it, and paths showed '<invalid dentry inode>' instead of '/SYSV00000000 (deleted)'. Accept i_ino 0 only for inodes on the internal shmem mount (shm_mnt), so the smear check is unchanged for every other inode.
|
Hi @miqsoft, thanks for this, looks like it works to me! I made a test image to match your description and your changes here made it go from a crash to working - so that is great. Before: After: I then tested it against my sample library and it looks good there too, no regression I can see and it fixed some crashes on some of my samples - hitting in open-iscsi's iscsid. With your changes it shows e.g. from proc maps and now with your changes the plugin out matches. Overall it fixed 102 of my plugin runs, and left the other 4,300ish unchanged so that is great. Like your other PR I think this needs a PATCH bump of the framework in It would be nice if there was a regression test, but the one linux sample that is tested against doesn't hit this issue from what I can tell. So I'm not sure that'll be possible. Thanks |
|
Thanks for testing it against your sample library, and good to hear it also fixes the iscsid crashes! I've pushed the PATCH bump to 2.28.4. #2085 changes the same line, so whichever of the two is merged second will need a rebase to 2.28.5. I'll do that as soon as the first one is in. About a regression test: the CI sample has no SysV segment 0, so it can't catch this. I could add a small unit test that needs no memory image, like the one #2052 added (test/test_linux_socket_addresses.py). It would build fake inode and VMA objects and check three things:
Happy to add it to this PR if you'd like? |
|
For the testing I'm not sure what is best - I would think @Abyss-W4tcher would be able to give you a good idea. 😄 |
|
Tested this on a Linux 6.18.59 x86-64 image with a process attached to SysV segment 0: linux.proc.Maps (1,973 rows), linux.elfs, linux.library_list (136 rows) and linux.malware.malfind all complete without errors, and the segment's VMA now renders as /SYSV00000000 (deleted) instead of an invalid-dentry placeholder. Looks good to me — thanks for the fix! |
Abyss-W4tcher
left a comment
There was a problem hiding this comment.
Code looks good to me and documents the claims against kernel source
Abyss-W4tcher
left a comment
There was a problem hiding this comment.
I agree with the tests you suggested, could you add them to the PR?
The CI images have no SysV segment 0, so test the two fixes with fake objects: inode.is_valid() accepts inode number 0 only on the shm mount (and not when shm_mnt is missing, NULL or unreadable), and vm_area_struct.is_valid() handles a file whose get_inode() returns None.
|
I've added the tests and additionally wrote a test, that checks that inode 0 is still rejected when shm_mnt is missing, NULL or unreadable, and when the reference count is negative. |
Abyss-W4tcher
left a comment
There was a problem hiding this comment.
Thanks for adding the tests, here is an AI review that raises legitimate minor points that could enhance the coverage. Could you take a look at adding these to your PR if you find them valid too?
A few small gaps, none blocking:
ordinarydoesn't show the shm lookup is skipped. It would still pass if_is_sysv_shm_segment()ran for every inode. Adding(5, OTHER_SB, 1, "unreadable", True)would show thati_ino > 0never touchesshm_mnt.- A negative
i_countwithi_ino > 0isn't tested.negative-countusesi_ino=0. The check order ininode.is_valid()changed, so(5, OTHER_SB, -1, "ok", False)would pin the old behaviour. vm_area_struct.is_valid()has no test forget_inode()raisingInvalidAddressException. That is the existingreturn Falsebranch, next to the new one.- The real
get_inode()chain isn't exercised. The bug goes throughget_inode(), which callsinode_ptr.is_valid(), and thenvm_area_struct.is_valid(). The tests call the twois_validmethods separately with fakes. If it's easy, one test that gives the realget_inode()a fake inode pointer withi_ino=0on the shm mount would show it now returns the inode instead of None. Skip it if it needs too much scaffolding.
Items 1–3 are one-line parametrize rows. I'd call 4 optional. Happy to approve once 1–3 are in.
ISFs generated from BTF type the shm_mnt symbol as void, so
object_from_symbol("shm_mnt").mnt_sb raised AttributeError, and an ISF
without a type for the symbol raised TypeError. Either escaped from
inode.is_valid() for every inode with number 0. Build the pointer with an
explicit vfsmount subtype instead of relying on the symbol's type.
Show that inodes with a nonzero number never look up shm_mnt, that a negative reference count is rejected and a zero one accepted for them, that vm_area_struct.is_valid() rejects a VMA whose get_inode() raises, and run the real struct_file.get_inode() and vm_area_struct.is_valid() chain on an inode with number 0. The fake kernel module now checks the symbol and type names it is asked for.
|
Thanks for the review, I added tests for all four points and found one more issue while doing so.
The other issue: ISFs generated from BTF type |
Volatility3 assumes ISFs are built from full debug information, so use the symbol's own type instead of an explicit vfsmount pointer. ISFs generated from BTF are not supported.
Abyss-W4tcher
left a comment
There was a problem hiding this comment.
LGTM now, thanks for your contribution!
Fixes #2082
linux.proc.Maps, and every plugin that walks VMAs withget_vma_iter(), crashes on processes that have System V shared memory segment 0 attached (cause and reproduction in the issue). The kernel uses the segment id as the inode number of the segment's file, so segment 0 has inode number 0.inode.is_valid()rejects that as smear,get_inode()returns None, andvm_area_struct.is_valid()then readsi_sizefrom None.Changes
vm_area_struct.is_valid(): skip the size check whenget_inode()returns None. This alone fixes the crash, also whenget_inode()returns None for other reasons (an unreadable or smeared inode).inode.is_valid(): accept inode number 0 for inodes on the kernel's internal shmem mount (shm_mnt), where SysV segments live. The segment is then shown as the kernel shows it,/SYSV00000000 (deleted), instead of<invalid dentry inode>. The smear check is unchanged for every other inode.The changes are separate commits, so the second can be dropped if you prefer to keep
inode.is_valid()as it is.Testing
linux.proc.Mapslists the segment as/SYSV00000000 (deleted)with inode 0, as the guest's own/proc/PID/mapsdoes.