Skip to content

Linux: fix get_vma_iter() crash on System V shared memory segment 0 - #2083

Open
miqsoft wants to merge 7 commits into
volatilityfoundation:developfrom
miqsoft:fix/linux-sysv-shm-inode-zero
Open

miqsoft wants to merge 7 commits into
volatilityfoundation:developfrom
miqsoft:fix/linux-sysv-shm-inode-zero

Conversation

@miqsoft

@miqsoft miqsoft commented Nov 9, 2026 •

Copy link
Copy Markdown

Fixes #2082

linux.proc.Maps, and every plugin that walks VMAs with get_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, and vm_area_struct.is_valid() then reads i_size from None.

Changes

  1. vm_area_struct.is_valid(): skip the size check when get_inode() returns None. This alone fixes the crash, also when get_inode() returns None for other reasons (an unreadable or smeared inode).
  2. 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

  • Debian 12 (kernel 6.1.0-54-cloud-amd64) with a process attached to SysV segment 0: develop crashes; with this PR, linux.proc.Maps lists the segment as /SYSV00000000 (deleted) with inode 0, as the guest's own /proc/PID/maps does.

…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.
@eve-mem

eve-mem commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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:

$ vol.py -vvv -q  --offline -s <isf dir> -f debian-12_6.1.190-1-amd64_amd64_20261111T1036Z_sysv-shm0-2g.elf linux.proc.Maps
Traceback (most recent call last):
  File "vol.py", line 16, in <module>
    volatility3.cli.main()
  File "volatility3/cli/__init__.py", line 942, in main
    CommandLine().run()
  File "volatility3/cli/__init__.py", line 527, in run
    renderer.render(grid)
  File "volatility3/cli/text_renderer.py", line 612, in render
    grid.populate(visitor, final_output)
  File "volatility3/framework/renderers/__init__.py", line 318, in populate
    for level, item in self._generator:
  File "volatility3/framework/plugins/linux/proc.py", line 192, in _generator
    for vma in self.list_vmas(task, filter_func=vma_filter_func):
  File "volatility3/framework/plugins/linux/proc.py", line 97, in list_vmas
    for vma in mm_pointer.get_vma_iter():
  File "volatility3/framework/symbols/linux/extensions/__init__.py", line 1128, in get_vma_iter
    if not vma.is_valid():
           ^^^^^^^^^^^^^^
  File "volatility3/framework/symbols/linux/extensions/__init__.py", line 1296, in is_valid
    if inode.i_size > 0 and self.get_page_offset() > inode.i_size:
       ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'i_size'

After:

$ vol.py -vvv -q --offline -s <isf dir> -f debian-12_6.1.190-1-amd64_amd64_20261111T1036Z_sysv-shm0-2g.elf linux.proc.Maps

PID	Process	Start	End	Flags	PgOff	Major	Minor	Inode	File Path	File output

598	vib-shm0	0x7fb82fa6d000	0x7fb82fa6e000	rw-	0x0	0	1	0	/SYSV00000000 (deleted)	Disabled

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 /SYSV00000000 (deleted) which matches the output from /proc/PID/maps.

e.g. from proc maps

7f3ea563a000-7f3ea563b000 rw-s 00000000 00:05 65538                      /SYSV00000000 (deleted)
7f3ea563b000-7f3ea563f000 rw-s 00000000 00:05 32769                      /SYSV00000000 (deleted)
7f3ea563f000-7f3ea5640000 rw-s 00000000 00:05 0                          /SYSV00000000 (deleted)

and now with your changes the plugin out matches.

PID	Process	Start	End	Flags	PgOff	Major	Minor	Inode	File Path	File output

979	iscsid	0x7f3ea563a000	0x7f3ea563b000	rw-	0x0	0	5	65538	/SYSV00000000 (deleted)	Disabled
979	iscsid	0x7f3ea563b000	0x7f3ea563f000	rw-	0x0	0	5	32769	/SYSV00000000 (deleted)	Disabled
979	iscsid	0x7f3ea563f000	0x7f3ea5640000	rw-	0x0	0	5	0	/SYSV00000000 (deleted)	Disabled

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 constants/_version.py (2.28.3 → 2.28.4), so we know which version has the fix. No _required_framework_version needs to change, because nothing public was added

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
🦊

@miqsoft

miqsoft commented Nov 12, 2026 •

Copy link
Copy Markdown
Author

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:

  • an inode with number 0 on the shm mount is accepted
  • the same inode on any other mount is still rejected
  • vm_area_struct.is_valid() doesn't crash when get_inode() returns None

Happy to add it to this PR if you'd like?

@eve-mem

eve-mem commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

For the testing I'm not sure what is best - I would think @Abyss-W4tcher would be able to give you a good idea. 😄

@ricardojrdez

Copy link
Copy Markdown
Contributor

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 Abyss-W4tcher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me and documents the claims against kernel source

@Abyss-W4tcher Abyss-W4tcher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@miqsoft

miqsoft commented Nov 17, 2026

Copy link
Copy Markdown
Author

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 Abyss-W4tcher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. ordinary doesn'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 that i_ino > 0 never touches shm_mnt.
  2. A negative i_count with i_ino > 0 isn't tested. negative-count uses i_ino=0. The check order in inode.is_valid() changed, so (5, OTHER_SB, -1, "ok", False) would pin the old behaviour.
  3. vm_area_struct.is_valid() has no test for get_inode() raising InvalidAddressException. That is the existing return False branch, next to the new one.
  4. The real get_inode() chain isn't exercised. The bug goes through get_inode(), which calls inode_ptr.is_valid(), and then vm_area_struct.is_valid(). The tests call the two is_valid methods separately with fakes. If it's easy, one test that gives the real get_inode() a fake inode pointer with i_ino=0 on 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.
@miqsoft

miqsoft commented Nov 18, 2026

Copy link
Copy Markdown
Author

Thanks for the review, I added tests for all four points and found one more issue while doing so.

  1. Instead of the "unreadable" row I added (5, OTHER_SB, 1, "untouched", True). _is_sysv_shm_segment() catches InvalidAddressException and returns False, so with a lookup for every inode i_ino > 0 or ... would still be True and the "unreadable" row would pass anyway. In the "untouched" mode any kernel module lookup calls pytest.fail(). I checked it against an is_valid() that always does the lookup: the new row fails there, the "unreadable" row passes.
  2. Added (5, OTHER_SB, -1, "ok", False), plus (5, OTHER_SB, 0, "untouched", True) to pin the < 0 boundary.
  3. Added test_vma_is_invalid_when_get_inode_raises.
  4. Added test_file_get_inode_ino_0, which runs the real struct_file.get_inode() on a fake file with an inode-0 pointer: on the shm mount it returns the inode, on another mount None. test_vma_is_valid_for_shm_segment_0 takes the same chain through vm_area_struct.is_valid().

The other issue: ISFs generated from BTF type shm_mnt as void, so object_from_symbol("shm_mnt").mnt_sb raised AttributeError, and an ISF without a type for the symbol raised TypeError. Either would have turned every inode-0 check into a crash. _is_sysv_shm_segment() now builds the pointer with an explicit vfsmount subtype (f94bce1). I checked it against two BTF ISFs (5.13, 6.17) and the Debian 6.1 dwarf2json ISF.

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 Abyss-W4tcher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now, thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: linux.proc.Maps crashes on processes attached to System V shared memory segment 0

4 participants