Commit Graph

1994 Commits

Author SHA1 Message Date
Omar Sandoval
f4e43ddf14 tests: hack around crashed thread stack trace test failures on s390x
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 15:23:40 -08:00
Omar Sandoval
1be320ade9 vmtest: don't try testing on known-broken version+architecture combinations
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 14:05:19 -08:00
Omar Sandoval
b568474a14 vmtest: fix mypy errors
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 13:47:06 -08:00
Omar Sandoval
bab4f43d68 tests: replace fork_and_sigwait() and fork_and_call() with fork_and_stop()
Before Linux kernel commit 4e57a4ddf6b0 ("ARM: 9107/1: syscall: always
store thread_info->abi_syscall") (in v5.15), on Arm, the syscall number
in /proc/<pid>/syscall is unreliable unless the process is being traced.
fork_and_sigwait() relies on this to detect when the created process has
scheduled out for good. Instead, we can have the created process raise
SIGSTOP and wait for it to be stopped. This is simpler and also doesn't
require us to care about the sigwait syscall numbers. While we're
reworking it, let's also consolidate it with fork_and_call().
test_task_state_to_char() can't use the new function because it wants
the function to sleep, then stop, then die, but it's easy enough to
open-code that one special case.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 11:57:29 -08:00
Omar Sandoval
fca8b9859d tests: disable get_kconfig() test on Arm
elfutils commit c1c1c06e30f0 ("libebl: Add ebl_func_addr_mask plus ARM
backend implementation.") has a bug that I haven't gotten around to
fixing: it masks the least significant bit of all symbol values, not
just function symbol values. This breaks the get_kconfig() helper: if
the kernel_config_data_end symbol value is odd, then the length of the
compressed config data is truncated by one byte and gzip decompression
fails. Disable the test on Arm until we get it fixed.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 11:57:29 -08:00
Omar Sandoval
e5df46f2f2 vmtest.kbuild: add patch to get usable CFI on s390x on Linux 4.9 and 4.14
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 11:57:29 -08:00
Omar Sandoval
33f9d4c369 vmtest.kbuild: add patch to make kdump work on ppc64 on Linux 6.2 and 6.3
This fix was backported to other stable kernel versions from 6.6, but
not to 6.2 or 6.3.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 02:23:30 -08:00
Omar Sandoval
8ac2cbf7b5 vmtest.kbuild: add more 32-bit Arm headers to AArch64 packages
The drgn_test module build started failing on Linux 4.9 on AArch64 again
(maybe because of the new config options?). Add more arch/arm headers
that were being referenced from arch/arm64.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 02:23:30 -08:00
Omar Sandoval
85bb738a9f vmtest.kbuild: add patch to get .debug_frame on old AArch64 kernels
A few older kernel versions are missing the .debug_frame section because
the compiler is generating .eh_frame instead, only for it to get
discarded by the linker script. Backport a patch to disable .eh_frame
generation to the kernel versions that we care about.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 02:23:30 -08:00
Omar Sandoval
52c2a1c4b3 vmtest.vm: kill QEMU on exception or signal
If an exception is raised after QEMU is started, then the
subprocess.Popen context manager waits for the QEMU process to exit,
which it likely never will. If vmtest.vm gets killed with SIGTERM, the
QEMU process continues running. Fix both of these issues by terminating
the QEMU process if there is an exception and adding a signal handler
for SIGTERM to exit gracefully.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 02:23:30 -08:00
Omar Sandoval
a0a86364a8 libdrgn: memory_reader: indicate when fault is for physical memory
It can be confusing and misleading to see a FaultError for a strange
address that is actually physical.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-08 02:23:30 -08:00
Omar Sandoval
a5da128bb1 tools/fsrefs.py: check for references from uprobes
This one is pretty involved to implement and to test.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 16:18:45 -08:00
Omar Sandoval
3272a62f3b tools/fsrefs.py: check for references from swap files
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 16:18:45 -08:00
Omar Sandoval
9cf7768ce8 tools/fsrefs.py: check for references from loop devices
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 16:18:45 -08:00
Omar Sandoval
bb61dc78a0 tools/fsrefs.py: check for references from binfmt_misc
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 16:18:45 -08:00
Omar Sandoval
71da69c9c4 tests: add fork_and_call()
Like fork_and_sigwait(), but returns the called function's return value,
and only waits for the function to return, not sigwait.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 16:18:45 -08:00
Omar Sandoval
bb137f1887 tools/fsrefs.py: add mode to find references to a filesystem/super block
In this mode, we print the paths of the referenced files. Now that we
have multiple "checks" we're doing, also add an option to enable or
disable specific checks.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 16:18:45 -08:00
Omar Sandoval
f8851c54f0 tools/fsrefs.py: add missing sys import
It's only missing when used as a library (e.g., by the tests).

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 15:24:32 -08:00
Omar Sandoval
479eb47a4e vmtest.vm: make Ctrl-C work in VM
Apparently the kernel starts the init process with stdin and stdout set
to /dev/console, which cannot be a controlling tty, which is required
for stuff like Ctrl-C and shell job control to work. This can apparently
be worked around with setsid -c; see
https://github.com/systemd/systemd/issues/1431#issuecomment-393347607.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 15:13:24 -08:00
Omar Sandoval
d0e748d286 vmtest.config: enable more options for fsrefs.py tests
CONFIG_UPROBE_EVENTS was called CONFIG_UPROBE_EVENT before Linux 4.11.
Also enable CONFIG_DNOTIFY, CONFIG_FANOTIFY, and CONFIG_PERF_EVENTS
explicitly for the future.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-06 13:33:20 -08:00
Omar Sandoval
8aa998035a helpers.linux.idr: add idr_for_each_entry()
This is a convenience wrapper around idr_for_each() and a cast.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-05 10:43:03 -08:00
Omar Sandoval
0562be06cb helpers.linux: add plist helpers
I ran into plists in the swap code, but they're also used in the
real-time scheduler and futexes. The helpers are trivial wrappers around
the list helpers.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-05 10:27:31 -08:00
Omar Sandoval
3cce4b8dd8 vmtest.config: enable CONFIG_USER_NS for fsrefs.py tests
I missed this option in commit 45a2f32379 ("vmtest.config: enable
config options for upcoming tool"). Also alphabetize the options
properly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-04 14:58:07 -08:00
Omar Sandoval
07ae81df91 vmtest.manage: work around broken 5.10 stable build
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-04 14:54:59 -08:00
Omar Sandoval
8c31531e59 CI: add Python 3.13
With #361 and #385 fixed, we can build on Python 3.13. Since it's still
in alpha, there could be new breakages, but at least we'll catch them
promptly.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-04 10:12:57 -08:00
Omar Sandoval
afc8a5693e libdrgn: python: use new PyLong_AsNativeBytes() in Python 3.13
Python 3.13.0a4 added a new public function, PyLong_AsNativeBytes(), to
replace the private _PyLong_AsByteArray(). It also modified the
signature of _PyLong_AsByteArray(). Let's use PyLong_AsNativeBytes()
when it's available. (PyLong_AsNativeBytes() also has the exact overflow
behavior we wanted, so it's a win-win.)

Closes #385.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-04 10:10:23 -08:00
Omar Sandoval
ef4b364cd0 Update elfutils in manylinux wheels to 0.191
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 15:49:39 -08:00
Omar Sandoval
e250dfea62 libdrgn: support DWARF package (.dwp) files
My elfutils patches to support .dwp files were just merged and included
in release 0.191. libdw does all of the heavy lifting, we just need to
apply the section offsets when we parse DWARF ourselves. We still need
to support older versions of elfutils, so add a stub.

Closes #317.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 15:49:08 -08:00
Omar Sandoval
f62dc96f24 libdrgn: dwarf_info: index type units from split DWARF files
Type units don't have a skeleton unit, so we need to walk over all of
the units in the split DWARF file to find them. Instead of doing this in
a second pass, rework drgn_dwarf_index_read_cus(): instead of
substituting skeleton units with their respective split units, call
drgn_dwarf_index_read_cus() recursively on the split DWARF file.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 14:37:47 -08:00
Omar Sandoval
9d53e65414 tools: add fsrefs.py
My team and I have investigated many issues that turned out to be caused
by a stray reference to a file or filesystem, either by user error or
due to a kernel bug. Userspace tools like lsof and fuser can't find all
of these. This adds a drgn-based tool similar to lsof/fuser. This
initial version only checks the basics: file descriptors, task working
directories, task root directories, task executables, and VMAs. Upcoming
changes will check additional, more obscure places.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 13:06:30 -08:00
Omar Sandoval
a337e9f45f tests: use virtio-blk instead of loop for Linux block helper tests
Now that we enable CONFIG_VIRTIO_BLK in our kconfig, there's no need to
use a loop device. Configure a virtio-blk device in vmtest.vm so that
the block helper tests have a disk to test with.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 10:55:31 -08:00
Omar Sandoval
0e4d69472b vmtest.config: fix grammatical error in comment
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 10:55:31 -08:00
Omar Sandoval
45a2f32379 vmtest.config: enable config options for upcoming tool
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-03-01 10:55:28 -08:00
Omar Sandoval
586ca27436 tests: allow fork_and_sigwait() to pass arguments to function
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-29 21:58:44 -08:00
Omar Sandoval
6eae1d34f8 Run mypy on future tools
Add the tools directory to the mypy pre-commit configuration.
bpf_inspect.py has a bunch of mypy errors, so we'll opt it out for now.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-29 21:57:20 -08:00
Omar Sandoval
aaf4414af2 Add 6.8 to supported kernels
This needed the dcache/mount updates for for_each_mount() and
path_lookup().

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-27 10:22:40 -08:00
Omar Sandoval
ec4a626eb2 helpers.fs: update path_lookup() handling of mounts for Linux 6.8
_follow_mount(), used by path_lookup(), was also affected by the
mnt_list change in 6.8. We can sidestep it by using the mount's list of
children mounts instead.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-27 10:22:40 -08:00
Omar Sandoval
f610dc2e26 helpers.fs: add comment to version divergence in for_each_mount()
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-27 10:22:40 -08:00
Johannes Thumshirn
f8354aef30 helpers.linux.fs: update for_each_mount() for changes in Linux 6.8
Starting with kernel v6.8 the mnt_list int struct mnt_namespace git
converted to a rb-tree.

Reflect this change in drgn's for_each_mount() helper.

Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
2024-02-27 09:57:40 -08:00
Omar Sandoval
718da449ef helpers.linux.fs: update path_lookup() for dentry changes in Linux 6.8
The list of children for a dentry was changed to an hlist with different
field names for both the anchor and entries.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-22 13:45:34 -08:00
Omar Sandoval
241afd5b62 cli: add FaultError to default imports
It's not uncommon to need to catch FaultError in the CLI. Josef Bacik
complained that he often forgets to import it when he needs it, so let's
do it by default.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-02-22 13:30:32 -08:00
Omar Sandoval
145ac798cb scripts/build_dists.sh: default to Podman instead of Docker
It's nice running without root/sudo, and it's also nice not needing to
enable an extra repository to install Docker.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-01-17 01:26:35 -08:00
Omar Sandoval
695d27654d libdrgn: python: don't use private dict APIs removed in Python 3.13
_PyDict_GetItemIdWithError() and _PyDict_SetItemId() have
straightforward replacements, so no need to fight this upstream.

Closes #361.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-01-17 00:32:52 -08:00
Omar Sandoval
71a65dbfb1 libdrgn: fix memory leak of type template parameters
We never free drgn_type::template_parameters.

Fixes: 352c31e1ac ("Add support for C++ template parameters")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-01-16 13:28:10 -08:00
Peter Collingbourne
d22f434600 libdrgn: aarch64: Apply TBI to virtual addresses
In tag-based KASAN modes, TCR_EL1.TBI1 is enabled, which causes the
top 8 bits of virtual addresses to be ignored for address translation
purposes. Do the same when reading from memory. There is no harm in doing
so unconditionally, as the architecture does not support >56 bit VA sizes.

Signed-off-by: Peter Collingbourne <pcc@google.com>
2024-01-16 13:11:50 -08:00
Omar Sandoval
5ea7704609 tests: add a test case for stack_depot_fetch()
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-01-14 00:31:08 -08:00
Omar Sandoval
21cfb0436e tests: add a test case for stack_trace_from_pcs()
Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-01-14 00:30:54 -08:00
Omar Sandoval
adef44f41b drgn.helpers.linux.stackdepot: tiny documentation improvements
Link to the header file and add the kernel version to a commit
reference.

Signed-off-by: Omar Sandoval <osandov@osandov.com>
2024-01-13 23:25:00 -08:00
Peter Collingbourne
431f1f3fcf drgn.helpers.linux.stackdepot: add stack_depot_fetch() helper
This helper returns a stack trace from the stack depot.

Signed-off-by: Peter Collingbourne <pcc@google.com>
2024-01-13 23:23:41 -08:00
Peter Collingbourne
9fecb27283 Add drgn.Program.stack_trace_from_pcs()
This function is useful when you only have a list of PCs
and not the full stack trace, for example when working with
the stack depot.

Signed-off-by: Peter Collingbourne <pcc@google.com>
2024-01-13 23:23:41 -08:00