Commit Graph

36 Commits

Author SHA1 Message Date
Lianbo Jiang
538b9ed456 Fix "fuser" command to properly deal with an invalid argument
The man page of the "fuser" command suggests that the argument can be a
full pathname or inode address. However, the "fuser" command accepts an
invalid argument and prints a bogus result as below:

  crash> fuser x
   PID         TASK        COMM             USAGE
  100507  ffff9914431f4c80  "packagekitd"    fd
  100508  ffff991574e59980  "gmain"          fd
  100509  ffff9914431f3300  "gdbus"          fd
  102020  ffff991574400000  "sshd"           fd
  102043  ffff991441d19980  "sshd"           fd

The current fuser command has no checking mechanism to determine if an
argument is valid or not. Let's add it to handle such cases.

With the patch:
  crash> fuser x
  fuser: invalid argument: x

In addition, also add a note that fuser does not expect an argument other
than an inode address and full pathname, and if others are specified, the
output can be an unexpected result.

Reported-by: Buland Kumar Singh <bsingh@redhat.com>
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
2023-04-10 13:32:24 +09:00
Lianbo Jiang
88a4910d95 Fix "mount" command to appropriately display the mount dumps
Recently the following failure has been observed on some vmcores when
using the mount command:

  crash> mount
       MOUNT           SUPERBLK     TYPE   DEVNAME   DIRNAME
  ffff97a4818a3480 ffff979500013800 rootfs none      /
  ffff97e4846ca700 ffff97e484653000 sysfs  sysfs     /sys
  ...
  ffff97b484753420                0 mount: invalid kernel virtual address: 0  type: "super_block buffer"

The kernel virtual address of the super_block is zero when the mount
command fails with the vfsmnt address 0xffff97b484753420. And the
remaining mount information will be discarded. That is not expected.

Check the address and skip it with a warning, if this is an invalid
kernel virtual address, that can avoid truncating the remaining mount
dumps.

Reported-by: Dave Wysochanski <dwysocha@redhat.com>
Signed-off-by: Lianbo Jiang <lijiang@redhat.com>
2022-12-22 09:21:28 +09:00
Chunguang.Xu
5b9d3e98cd Add debian/ubuntu vmlinux location to default search dirs
Now crash cannot find debian/ubuntu kernel vmlinux, we need to
explicitly specify the path to vmlinux. Try to add the debian
vmlinux location to default search directories.

Signed-off-by: Chunguang Xu <chunguang.xu@shopee.com>
2022-09-02 11:19:01 +09:00
Kazuhito Hagio
f374aca364 Fix gcc-11 compiler warnings on filesys.c
Without the patch, the following gcc-11 compiler warnings are emitted
for filesys.c:

filesys.c: In function 'mount_point':
filesys.c:718:17: warning: 'pclose' called on pointer returned from a mismatched allocation function [-Wmismatched-dealloc]
  718 |                 pclose(mp);
      |                 ^~~~~~~~~~
filesys.c:709:27: note: returned from 'fopen'
  709 |                 if ((mp = fopen(mntfile, "r")) == NULL)
      |                           ^~~~~~~~~~~~~~~~~~~
filesys.c:738:17: warning: 'pclose' called on pointer returned from a mismatched allocation function [-Wmismatched-dealloc]
  738 |                 pclose(mp);
      |                 ^~~~~~~~~~
filesys.c:723:27: note: returned from 'fopen'
  723 |                 if ((mp = fopen(mntfile, "r")) == NULL)
      |                           ^~~~~~~~~~~~~~~~~~~

Signed-off-by: Kazuhito Hagio <k-hagio-ab@nec.com>
2022-07-27 13:55:05 +09:00
Philipp Rudo
01d20ca186 Fix live debugging with lockdown=integrity
With kernel lockdown the access to kernel interfaces that allow to
extract confidential information (lockdown=confidentiality) or modify a
running kernel (lockdown=integrity) can be restricted. Two of the
interfaces that can be restricted are /dev/mem (integrity &
confidentiality) and /proc/kcore (confidentiality). With
lockdown=integrity this leads to a situation where /dev/mem exists but
is not readable while /proc/kcore exists and is readable. This breaks
crash's live debugging when it is invoked without argument, i.e.

$ crash
[...]
crash: /dev/mem: Operation not permitted

while passing /proc/kcore as image succeeds. The reason for this is that
crash always picks /dev/mem as source when it exits but doesn't check if
it is readable. Fix this by only selecting /dev/mem when it is readable.

Signed-off-by: Philipp Rudo <prudo@redhat.com>
2021-11-15 11:54:36 +08:00
Alexey Makhalov
3fedbee9bf vmware_guestdump: new input format
vmware_guestdump is extension to vmware_vmss with ability to debug
debug.guest and debug.vmem files.

debug.guest.gz and debug.vmem.gz can be obtained using following
.vmx options from VM running in debug mode:
    monitor.mini-suspend_on_panic = TRUE
    monitor.suspend_on_triplefault = TRUE

guestdump (debug.guest) is simplified version of *.vmss which does
not contain full VM state, but minimal guest state, such as memory
layout and CPUs state, needed for debugger. is_vmware_guestdump()
and vmware_guestdump_init() functions parse guestdump header and
populate vmss data structure (from vmware_vmss.c). As result, all
handlers (except mempry_dump) from vmware_vmss.c can be reused.

How to use: $ crash /path/to/debug_file.guest vmlinux
Companion debug_file.vmem must be present in the same folder as
debug_file.guest. Otherwise crash will shot a message:
 vmw: Open the companion vmem file: /path/to/debug_file.vmem
 crash: vmw: /path/to/debug_file.vmem: No such file or directory

Signed-off-by: Alexey Makhalov <amakhalov@vmware.com>
2020-10-15 11:09:46 +09:00
Dave Anderson
1f6b1ce567 Change the gating of a debug message in the do_xarray_dump_cb()
function from CRASHDEBUG(0) to CRASHDEBUG(1).  Without the patch,
users of the XArray callback functionality may see messages of the
sort "entry has XARRAY_TAG_MASK bits set: 239ab0024001" without
setting a debug number.
(anderson@redhat.com)
2019-05-21 14:46:23 -04:00
Dave Anderson
3370ae03ed Export the get_mount_list() and get_dump_level() functions in defs.h
for use by extension modules.
(k-hagio@ab.jp.nec.com)
2019-05-21 14:32:56 -04:00
Dave Anderson
9166dd323f Fix for the "files -d <dentry>" option if the dentry.d_inode
pointer is NULL.  Without the patch, the command output does not
display the super_block pointer or the file's pathname.
(martin.moore@hpe.com)
2019-04-01 11:37:42 -04:00
Dave Anderson
4d55112701 Commit dd12805ed1db7 in the linux-next kernel repository, titled
"XArray: Remove radix tree compatibility", changes the definition
of "radix_tree_root" back to be a struct.  However, the content of
the new structure differs from the original structure, so without
the patch, current linux-next kernels fail during initialization
with the error message "radix trees do not exist or have changed
their format".  Because the new "radix_tree_root" and "xarray"
structures have nearly the same layout, the existing functionality
for XArrays can be reused.
(prudo@linux.ibm.com)
2019-03-22 15:50:40 -04:00
Dave Anderson
8c4598a430 Add support for usage of the XArray facility by the "files -p"
option.  Without the patch, the command fails on Linux 4.20 and later
kernels with the error message "files: radix trees do not exist or
have changed their format".
(anderson@redhat.com)
2018-11-14 15:14:29 -05:00
Dave Anderson
5233b6aa96 Third phase of support for the XArray facility, which consolidates
the radix_tree_pair and xarray_pair structures into a unified
list_pair structure that is used by both facilities, and fixes the
"bpf" command.  Without the patch, the command fails with the error
message "bpf: radix trees do not exist or have changed their format".
(anderson@redhat.com)
2018-11-14 12:17:15 -05:00
Dave Anderson
3b05002917 First phase of support for the XArray facility. The added support is
similar to that of radix trees, but introduces completely separate
functions, structures and #defines.  None of the applicable radix
tree users in the crash utility have been switched over, so this
phase does not introduce any functional changes.
(asmadeus@codewreck.org, anderson@redhat.com)
2018-11-12 15:59:30 -05:00
Dave Anderson
60a42d7092 Second phase of support for the VMCOREINFO PT_NOTE added to the ELF
header of /proc/kcore in Linux 4.19 and later kernels.  This patch
introduces support for live session /proc/kcore VMCOREINFO access by
the crash utility's internal pc->read_vmcoreinfo() function.  New
usage include the initialization of the x86_64 phys_base value, and
the arm64 phys_offset, page size, and VA bits count.
(anderson@redhat.com)
2018-10-31 11:29:39 -04:00
Dave Anderson
b9df4d1568 Fix for the "files -p <inode>" option. Without the patch, the
command attempts to translate radix tree node slot entries that
are RADIX_TREE_EXCEPTIONAL_ENTRY types, and as a result may fail
prematurely with an error message of the sort "files: do_radix_tree:
callback operation failed: entry: 5  item: 44788c5000a".
(anderson@redhat.com)
2018-09-06 14:01:28 -04:00
Dave Anderson
2f57a96ce2 Fix for the "files" command in Linux 4.17 and later kernels that
contain commit b93b016313b3ba8003c3b8bb71f569af91f19fc7, titled
"page cache: use xa_lock".  Without the patch, the "files -c" option
fails with the message "files: -c option not supported or applicable
on this architecture or kernel", and the "files -p &lt;inode>" option
fails in a similar manner.
(k-hagio@ab.jp.nec.com)
2018-09-04 14:29:45 -04:00
Dave Anderson
ba03b66cec Fix for the "files" and "net -s" commands when a task has an open
files count that exceeds 1024 (FD_SETSIZE) file descriptors.  Without
the patch, the commands may omit the display of open file descriptors.
(tan.hu@zte.com.cn)
2018-08-09 10:54:46 -04:00
Dave Anderson
7fcefcd4fe Fix for a crash-7.2.2 regression that may cause the "mount"
command to generate a segmentation violation.  The bug is
dependant upon the compiler version used to build the crash
utility, where a buffer overrun is not seen with more recent
versions of gcc, which hide the bug due to a different stack
layout of a function's local varibles.
(anderson@redhat.com)
2018-05-17 12:12:31 -04:00
Dave Anderson
48b1708609 For live system analysis, if both "/dev/mem" and the "/dev/crash"
memory driver do not exist, try to use "/proc/kcore".  Without
the patch, the session fails immediately with the error message
"crash: /dev/mem: No such file or directory".
(anderson@redhat.com)
2018-04-26 14:05:00 -04:00
Dave Anderson
11eceac4ef Fixes to address several gcc-8.0.1 compiler warnings that are generated
when building with "make warn".  The warnings are all false alarm
messages of type [-Wformat-overflow=], [-Wformat-truncation=] and
[-Wstringop-truncation]; the affected files are extensions.c, task.c,
kernel.c, memory.c, remote.c, symbols.c, filesys.c and xen_hyper.c.
(anderson@redhat.com)
2018-04-20 14:37:52 -04:00
Dave Anderson
a002f07040 Fix the search for the booted kernel on a live system to prevent
selecting the unusable "vmlinux.o" file found in private build
directories.  Without the patch, the non-executable vmlinux.o file
may be selected, and the resulting fatal error message indicates a
somewhat misleading "crash: cannot resolve _stext".
(bhsharma@redhat.com, anderson@redhat.com)
2018-02-28 16:13:51 -05:00
Dave Anderson
494a796e11 Fix to support Linux 4.15 and later kernels that contain kernel
commit e8cfbc245e24887e3c30235f71e9e9405e0cfc39, titled "pid: remove
pidhash".  The kernel's traditional usage of a pid_hash[] array to
store PIDs has been replaced by an IDR radix tree, requiring a new
crash plug-in function to gather the system's task set.  Without the
patch, the crash session fails during initialization with the error
message "crash: cannot resolve init_task_union".
(anderson@redhat.com)
2017-11-28 09:24:39 -05:00
Dave Anderson
21687ddf30 Fix to prevent an initialization-time failure when running a live
session on a host system that does not have a "/usr/src" directory.
Without the patch, the session fails with the message "*** Error in
'crash': free(): invalid pointer: <address> ***".
(Lei Chen)
2017-08-31 15:31:33 -04:00
Dave Anderson
5907614b2a Fixes to address three gcc-7.0.1 compiler warnings that are generated
when building with "make warn".  The warning types are "[-Wnonnull]"
in filesys.c, and "[-Wformat-overflow=]" in kernel.c and cmdline.c.
(anderson@redhat.com)
2017-03-03 15:10:02 -05:00
Dave Anderson
880574406d Fix for the "tree -t radix", "irq", and "files -p" command options
in Linux 4.6 and later kernels due to upstream changes in the radix
tree facility.  Without the patch, the commands will fail with the
message "radix trees do not exist or have changed their format".
(hirofumi@mail.parknet.co.jp)
2017-02-02 16:15:39 -05:00
Dave Anderson
89ed9d0a7f Introduction of support for "live" ramdump files, such as those that
are specified by the QEMU mem-path argument of a memory-backend-file
object.  This allows the running of a live crash session against a
QEMU guest from the host machine.  In this example, the /tmp/MEM file
on a QEMU host represents the guest's physical memory:

  $ qemu-kvm ...other-options... \
  -object memory-backend-file,id=MEM,size=128m,mem-path=/tmp/MEM,share=on \
  -numa node,memdev=MEM -m 128

and a live session run can be run against the guest kernel like so:

  $ crash <path-to-guest-vmlinux> live:/tmp/MEM@0

By prepending the ramdump image name with "live:", the crash session will
act as if it were running a normal live session.
(oleg@redhat.com)
2016-05-04 11:50:19 -04:00
Dave Anderson
dc20e27e0b Include sys/macros.h explicitly in filesys.c for the definitions
of major(), minor() and makedev().  These functions are defined
in the sys/sysmacros.h header, not sys/types.h.  Linux C libraries
are updating to drop the implicit include, so we need to include
it explicitly.
(vapier@gentoo.org)
2016-04-21 09:51:04 -04:00
Dave Anderson
3106fee2be Implementation of two new "files" command options. The "files -c"
option is context-sensitive, similar to the the regular "files"
command when used without an argument, but replaces the FILE and
DENTRY columns with I_MAPPING and NRPAGES columns that reflect
each open file's inode.i_mapping address_space structure address,
and the address_space.nrpages count within it; this shows how
many of each open file's pages are currently in the system's
page cache.  The "files -p <inode>" option takes the address
of an inode, and dumps all of its pages that are currently in the
system's page cache, borrowing the "kmem -p" page structure output.
(yangoliver@gmail.com)
2015-07-02 15:16:53 -04:00
Dave Anderson
1e858ed48e Fix for the "irq", "mount", "kmem -p" and "kmem -v" commands when
they are used in an input file.  If more than one of any of those
four commands are used in an input file, the output of the second
and subsequent command instances will not display their respective
command headers.
(anderson@redhat.com)
2015-05-08 15:58:58 -04:00
Dave Anderson
f7e4297640 Added support for VMware .vmss suspended state files as dumpfiles.
Similar to all other supported dumpfile types, it is invoked as:

  $ crash vmlinux <vmname>.vmss

A "<vmname>.vmss" file created by the VMware vSphere ESX hypervisor
contains a header and the full memory image.  A "<vmname>.vmss" file
created by the VMware Workstation facility only contains the header,
and must be accompanied by a companion "<vmname>.vmem" memory image
that is located in the same directory as the "<vmname>.vmss" file.
(hfu@vmware.com)
2015-02-05 14:40:44 -05:00
Dave Anderson
7e5c0cedef Fix for a misleading fatal error message if a 32-bit crash binary
built on an X86_64 host with "make target=X86" or "make target=ARM"
is used on a live X86_64 system without specifying a vmlinux
namelist.  Without the patch, the session fails with the message
"crash: cannot find booted kernel -- please enter namelist argument".
The error message will be "crash: compiled for the X86 architecture"
or "crash: compiled for the ARM architecture".
(anderson@redhat.com)
2014-11-21 15:19:20 -05:00
Dave Anderson
68c3828210 Add "/lib/modules/<version>/build" to the list of directories that
are searched for the currently-running kernel on live systems.  This
will automatically locate the vmlinux namelist for kernels that were
locally installed with "make modules_install install".
(lrintel@redhat.com)
2014-09-12 15:37:40 -04:00
Dave Anderson
de3daee5ee Fix to recognize that the live system "crash.ko" memory driver may
be compressed and named "crash.ko.xz".  Without the patch, the driver
is not recognized and loaded, and as a result the /dev/mem driver
and/or /proc/kcore will be tried as the live memory source.
(anderson@redhat.com)
2014-08-12 11:15:49 -04:00
Dave Anderson
77e9ca1305 Document the reason behind the deprecation of the "mount -f" option
for Linux 3.13 and later kernels if the option is attempted, and in
the "help mount" output, similar to the deprecated "mount -d" option.
(anderson@redhat.com)
2014-07-08 11:26:52 -04:00
Dave Anderson
5094787767 Deprecate the "mount -f" option for Linux 3.13 and later kernels
containing commit eee5cc2702929fd41cce28058dc6d6717f723f87, which
removed the super_block.s_files list_head member and the open files
list that it contained.  Without the patch, the command option fails
with the error message "mount: invalid structure member offset:
super_block_s_files"
(anderson@redhat.com)
2014-06-27 11:18:23 -04:00
Dave Anderson
03e3937ec7 Initial commit: crash-7.0.4 2014-01-28 16:46:11 -05:00