Commit graph

315 commits

Author SHA1 Message Date
Jake Freeland 9bec841312 ktrace: Record detailed ECAPMODE violations
When a Capsicum violation occurs in the kernel, ktrace will now record
detailed information pertaining to the violation.

For example:
- When a namei lookup violation occurs, ktrace will record the path.
- When a signal violation occurs, ktrace will record the signal number.
- When a sendto(2) violation occurs, ktrace will record the recipient
  sockaddr.

For all violations, the syscall and ABI is recorded.

kdump is also modified to display this new information to the user.

Reviewed by:	oshogbo, markj
Approved by:	markj (mentor)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D40676
2024-04-07 18:52:51 -05:00
Kyle Evans 02c57f7b48 kdump: decode pollfd struct arrays coming from poll(2)
We'll handle these just as we do kevents, one per line with subsequent
lines indented sufficiently to distinguish them from the upcoming
return value.

Sample, with indentation stripped and revents changed to '...' in the
first one to keep the line length down:

CALL  poll(0x820610560,0x3,0)
STRU  struct pollfd[] = { { fd=0, events=0x1<POLLIN>, revents=0x11<...>
 { fd=1, events=0x4<POLLOUT>, revents=0x4<POLLOUT>}
 { fd=-1, events=0x4<POLLOUT>, revents=0} }
RET   poll 2

Reviewed by:	bapt, jhb
Differential Revision:	https://reviews.freebsd.org/D44160
2024-03-04 23:44:09 -06:00
Kyle Evans a206524709 kdump: use print_mask_arg0 appropriately
Some callers are using print_mask_arg() when they should be using
print_mask_arg0(); the latter should be used when all flags are optional
and there's not a flag to be decoded with a 0-mask.  This turns:

nmount(0x6991e009000,0x8,0<><invalid>0)

into:

nmount(0x6991e009000,0x8,0)

Reviewed by:	jhb
Differential Revision:	https://reviews.freebsd.org/D43007
2023-12-13 10:49:03 -06:00
Warner Losh 5e3934b15a usr.bin: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:24:01 -07:00
Warner Losh 0b8224d1cc Remove copyright strings ifdef'd out
We've ifdef'd out the copyright strings for some time now. Go ahead and
remove the ifdefs. Plus whatever other detritis was left over from other
recent removals. These copyright strings are present in the comments and
are largely from CSRG's attempt at adding their copyright to every
binary file (which modern interpretations of the license doesn't
require).

Sponsored by:		Netflix
2023-11-26 22:23:58 -07:00
Warner Losh bdcbfde31e usr.bin: Remove ancient SCCS tags.
Remove ancient SCCS tags from the tree, automated scripting, with two
minor fixup to keep things compiling. All the common forms in the tree
were removed with a perl script.

Sponsored by:		Netflix
2023-11-26 22:23:30 -07:00
Warner Losh b2c76c41be Remove $FreeBSD$: one-line nroff pattern
Remove /^\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:15 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Dmitry Chagin c2c9ac88c2 kdump: Add a facility to print numbers in decimal format always
To help grepping kdump output by pid or tid it makes sence to print
some numbers in decimal format always. Eg, process or thread identifier
at least, as they already printed in decimal format.
Switch to print pid/tid arguments of some Linux signal related syscalls
in decimal format.

Reviewed by:		jhb
Differential Revision:	https://reviews.freebsd.org/D40099
MFC after:		1 week
2023-05-26 19:35:08 +03:00
Dmitry Chagin 829f3d7d26 kdump: Decode linux_clone syscall flags
Reviewed by:		emaste
Differential Revision:	https://reviews.freebsd.org/D40151
MFC after:		1 week
2023-05-26 19:34:33 +03:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Simon J. Gerraty d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Brooks Davis bb23932803 ktrace: make ktr_tid a long not intptr_t (NFC)
Long ago, ktr_tid was ktr_buffer which pointed to the buffer following
the header and was used internally in the kernel.  Use was removed in
efbbbf570d and it was repurposed as ktr_kid in c6854c347f.  For
ABI reasons, it stayed an intptr_t rather than becoming an lwpid_t at
the time.  Since it doesn't hold a pointer any more (unless you have
a ktrace.out from 2005), change the type to long which is alwasy the
same size on all supported architectures.  Add a suggestion to change
the type to lwpid_t (__int32_t) on a future ABI break.

Remove most remaining references to ktr_buffer, retaing a comment in
kdump.c explaining why negative values are treated as 0.  While here,
accept that pid_t and lwpid_t are of type int and simplify casts in
printf.

This changed was motivated by CheriBSD where intptr_t is 16-bytes
in the pure-capability ABI.

Reviewed by:	kib, markj
Sponsored by:	DARPA, AFRL
Differential Revision:	https://reviews.freebsd.org/D36599
2022-09-17 09:21:59 +01:00
Dmitry Chagin ae37e4a0d1 kdump(1): Sort options in alphabetical order.
Reviewed by:		imp (early rev)
Differential Revision:	https://reviews.freebsd.org/D35775
MFC after:		2 weeks
2022-07-16 12:47:54 +03:00
Dmitry Chagin fc90f3a281 ktrace: Increase precision of timestamps.
Replace struct timeval in header with struct timespec.
To differentiate header formats, add a new KTR_VERSIONED flag
set in the header type field similar to the existing KTRDROP flag.

To make it easier to extend ktrace headers in the future,
extend the existing header with a version field (version 0 is
reserved for older records without KTR_VERSIONED) as well as
new fields holding the thread ID and CPU ID.

Reviewed by:		jhb, pauamma
Differential Revision:	https://reviews.freebsd.org/D35774
MFC after:		2 weeks
2022-07-16 12:46:12 +03:00
Dmitry Chagin 4d496ab44a kdump: Decode Linux *at() syscalls
MFC after:		2 weeks
2022-06-22 14:29:38 +03:00
Dmitry Chagin ed2f123a21 kdump: For future use made decode_filemode() public
MFC after:		2 weeks
2022-06-22 14:26:50 +03:00
Dmitry Chagin 39de84b619 kdump: Decode Linux clock_nanosleep syscall
MFC after:		2 weeks
2022-06-22 14:21:42 +03:00
Dmitry Chagin f587a2a765 kdump: Decode Linux sigprocmask how argument
MFC after:		2 weeks
2022-06-22 14:20:39 +03:00
Dmitry Chagin b9b86b6742 kdump: Decode getitimer, setitimer which argument
Reviewed by:		jhb (previous version, without truss)
Differential revision:	https://reviews.freebsd.org/D35231
MFC after:		2 weeks
2022-06-22 14:19:31 +03:00
Dmitry Chagin 3606a213bf kdump: Decode Linux l_sigset_t.
Reviewed by:		markj
Differential revision:	https://reviews.freebsd.org/D35153
MFC after:		2 weeks
2022-06-22 14:15:20 +03:00
Dmitry Chagin 8a0f6d8cfd kdump: Add preliminary support for decoding Linux syscalls
Reviewed by:		jhb
Differential revision:	https://reviews.freebsd.org/D35216
MFC after:		2 weeks
2022-06-22 14:03:56 +03:00
Dmitry Chagin 8b8e2e8f41 kdump: For future use extract common code to a separate files
Reviewed by:		jhb
Differential revision:	https://reviews.freebsd.org/D35356
MFC after:		2 weeks
2022-06-22 14:01:36 +03:00
Dmitry Chagin 586ed32106 kdump: Decode cpuset_t.
Reviewed by:		jhb
Differential revision:	https://reviews.freebsd.org/D34982
MFC after:		2 weeks
2022-05-11 10:40:39 +03:00
Mateusz Guzik f3f3e3c44d fd: add close_range(..., CLOSE_RANGE_CLOEXEC)
For compatibility with Linux.

MFC after:	3 days
Reviewed by:	markj
Differential Revision:	https://reviews.freebsd.org/D34424
2022-03-03 17:21:58 +00:00
Brooks Davis 8e4a3add99 struct kevent_freebsd11 -> struct freebsd11_kevent
Rename to match the naming of syscalls and allow 32 to be appended
without making an ugly name like kevent_freebsd1132.

While here, make the kevent changelist argument const.

Reviewed by:	kib
2021-11-15 18:34:27 +00:00
Konstantin Belousov cf0ee8738e Drop cloudabi
According to https://github.com/NuxiNL/cloudlibc:
CloudABI is no longer being maintained. It was an awesome experiment,
but it never got enough traction to be sustainable.

There is no reason to keep it in FreeBSD.

Approved by:	ed (private mail)
Reviewed by:	emaste
Sponsored by:	The FreeBSD Foundation
Differential revision:	https://reviews.freebsd.org/D31923
2021-09-22 00:18:44 +03:00
Alex Richardson 1a3a57d745 kdump: use VIS_NOLOCALE when printing output
Attempting to parse the output as UTF-8 exposed an out-of-bounds read
in vis(3) (see https://reviews.freebsd.org/D30771). However, I don't
think it makes much sense to decode this output at all. Additionally,
passing one byte at a time will almost certainly result in incorrect
output for multi-byte characters.

Reviewed By:	brooks
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D30772
2021-06-16 16:28:27 +01:00
Alex Richardson 7fa2f2a62f Rename NO_WERROR -> MK_WERROR=no
As suggested in D27598. This also supports MK_WERROR.clang=no and
MK_WERROR.gcc=no to support the existing NO_WERROR.<compiler> uses.

Reviewed By:	brooks
Differential Revision: https://reviews.freebsd.org/D27601
2021-01-07 09:31:03 +00:00
Kyle Evans c2679dd779 kdump/truss: decode new _umtx_op flags
In both cases, print the flag bits first followed by the command.

Output now looks something like this:

(ktrace)
_umtx_op(0x8605f7008,0xf<UMTX_OP_WAIT_UINT_PRIVATE>,0,0,0)
_umtx_op(0x9fffdce8,0x80000003<UMTX_OP__32BIT|UMTX_OP_WAKE>,0x1,0,0)

(truss)
_umtx_op(0x7fffffffda50,UMTX_OP_WAKE,0x1,0x0,0x0) = 0 (0x0)
_umtx_op(0x9fffdd08,UMTX_OP__32BIT|UMTX_OP_WAKE,0x1,0x0,0x0) = 0 (0x0)

Reviewed by:	kib
Differential Revision:	https://reviews.freebsd.org/D27325
2020-12-09 03:24:09 +00:00
Kyle Evans c1b0c84747 kdump: decode shm_open2
This is the kdump counterpart of the truss support added in r358116, and
also a part of D23733. shm_open2 is the successor to shm_open.

Reviewed by:	kaktus
2020-02-19 14:55:59 +00:00
Kyle Evans 550bec4fde kdump: decode SHM_ANON as first arg to legacy shm_open(2)
The first argument to shm_open(2) as well as shm_open2(2) may be a path or
SHM_ANON. Decode SHM_ANON, at least- paths will show up as namei results in
kdump output, which may be sufficient; in those cases, we'll have printed an
address.

Future commits will add support for shm_open2() to libsysdecode/truss/kdump.

Reported by:	kaktus
MFC after:	3 days
2020-02-19 14:32:55 +00:00
Simon J. Gerraty 2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Simon J. Gerraty 5ab1c5846f Add Makefile.depend.options
Leaf directories that have dependencies impacted
by options need a Makefile.depend.options file
to avoid churn in Makefile.depend

DIRDEPS for cases such as OPENSSL, TCP_WRAPPERS etc
can be set in local.dirdeps-options.mk
which can add to those set in Makefile.depend.options

See share/mk/dirdeps-options.mk

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22469
2019-12-11 17:37:37 +00:00
Kyle Evans a9ac5e1424 sysent: regenerate after r352705
This also implements it, fixes kdump, and removes no longer needed bits from
lib/libc/sys/shm_open.c for the interim.
2019-09-25 18:09:19 +00:00
Ed Maste c0347e182c kdump: expand comment on reasons for CAPFAIL_LOOKUP
Comment for CAPFAIL_LOOKUP refered only to paths containing ".." but
it is returned for other restricted VFS lookup cases, such as absolute
paths or openat(AT_FDCWD, ...).
2019-02-18 03:49:16 +00:00
John Baldwin 5cb9940ce2 Use 'bool' instead of 'int' for various boolean flags.
Reviewed by:	kib
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D16611
2018-08-18 20:23:53 +00:00
John Baldwin 7cf2ca3b01 Remove spurious ABI tags from kdump output.
The abidump routine output an ABI tag when -A was specified for records
that were not displayed due to type or pid filtering.  To fix, split
the code to lookup the ABI from the code to display the ABI, move the
code to display the ABI into dumpheader(), and move dumpheader() later
in the main loop as a simplification.  Previously dumpheader() was
called under a condition that repeated conditions made later in the
main loop.

Reviewed by:	kib
MFC after:	1 month
Sponsored by:	DARPA / AFRL
Differential Revision:	https://reviews.freebsd.org/D16608
2018-08-07 00:10:58 +00:00
Mariusz Zaborski 7672a0148f Convert cap_enter() < 0 && errno != ENOSYS to caph_enter() < 0.
No functional change intended.
2018-06-19 23:43:14 +00:00
Ed Maste fc7d33b49e kdump: simplify/remove per-arch #ifdefs
It is acceptable for syscallabi to map SV_ABI to SYSDECODE_ABI on all
architectures; libsysdecode will return not-found sentinel values if
it does not have a syscall name or errno mapping for a given
architecture.

Also, use __LP64__ for the SV_ILP32 -> SYSDECODE_ABI_LINUX32 mapping,
for any future 32- on 64-bit linuxulator implementation.

Reviewed by:	jhb
Sponsored by:	Turing Robotic Industries Inc.
2018-04-24 19:23:26 +00:00
Mariusz Zaborski c5033697f1 NLS data and tz can be cached using caspicum helpers.
Using them we simplifies and unifies sandboxed code.
2018-01-03 07:43:04 +00:00
John Baldwin ffb6607984 Decode kevent structures logged via ktrace(2) in kdump.
- Add a new KTR_STRUCT_ARRAY ktrace record type which dumps an array of
  structures.

  The structure name in the record payload is preceded by a size_t
  containing the size of the individual structures.  Use this to
  replace the previous code that dumped the kevent arrays dumped for
  kevent().  kdump is now able to decode the kevent structures rather
  than dumping their contents via a hexdump.

  One change from before is that the 'changes' and 'events' arrays are
  not marked with separate 'read' and 'write' annotations in kdump
  output.  Instead, the first array is the 'changes' array, and the
  second array (only present if kevent doesn't fail with an error) is
  the 'events' array.  For kevent(), empty arrays are denoted by an
  entry with an array containing zero entries rather than no record.

- Move kevent decoding tables from truss to libsysdecode.

  This adds three new functions to decode members of struct kevent:
  sysdecode_kevent_filter, sysdecode_kevent_flags, and
  sysdecode_kevent_fflags.

  kdump uses these helper functions to pretty-print kevent fields.

- Move structure definitions for freebsd11 and freebsd32 kevent
  structures to <sys/event.h> so that they can be shared with userland.
  The 32-bit structures are only exposed if _WANT_KEVENT32 is defined.
  The freebsd11 structures are only exposed if _WANT_FREEBSD11_KEVENT is
  defined.  The 32-bit freebsd11 structure requires both.

- Decode freebsd11 kevent structures in truss for the compat11.kevent()
  system call.

- Log 32-bit kevent structures via ktrace for 32-bit compat kevent()
  system calls.

- While here, constify the 'void *data' argument to ktrstruct().

Reviewed by:	kib (earlier version)
MFC after:	1 month
Differential Revision:	https://reviews.freebsd.org/D12470
2017-11-25 04:49:12 +00:00
Pedro F. Giffuni 8a16b7a18f General further adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 3-Clause license.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.
2017-11-20 19:49:47 +00:00
Bryan Drewery ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Mariusz Zaborski 2560d18180 We use a few different ifdef's names to check if we are using Casper or not,
let's standardize this. Now we are always use WITH_CASPER name.

Discussed with:	emaste@
MFC after:	1 month
2017-09-21 14:41:41 +00:00
John Baldwin 39a3a4386a Decode pathconf() names, *at() flags, and sysarch() numbers in libsysdecode.
Move tables that were previously in truss over to libsysdecode.  truss
output is unchanged, but kdump has been updated to decode these fields.
In addition, sysdecode_sysarch_number() should support all platforms
whereas the old table in truss only supported x86.
2017-09-04 05:34:36 +00:00
John Baldwin 66ba8943a1 Decode arguments to rtprio_thread() (same as rtprio()). 2017-06-10 01:32:18 +00:00
John Baldwin 9483ab16d4 Fix decoding of setpriority() arguments.
The PRIO_* 'which' value is stored in the first argument to setpriority(2),
not the last.  While here, decode the arguments to getpriority(2).
2017-06-10 00:35:45 +00:00
John Baldwin ee8aa41dca Decode the 'who' argument passed to getrusage().
Add a new sysdecode_getrusage_who() which decodes the RUSAGE_* constant
passed as the first argument to getrusage().  Use this function in both
kdump and truss to decode the first argument to getrusage().

PR:		215448
Submitted by:	Anton Yuzhaninov <citrin+pr@citrin.ru>
MFC after:	1 month
2017-06-03 14:22:15 +00:00