Commit Graph

167 Commits

Author SHA1 Message Date
Davide Italiano
237abf0c56 - Trim an unused and bogus Makefile for mount_smbfs.
- Reconnect with some minor modifications, in particular now selsocket()
internals are adapted to use sbintime units after recent'ish calloutng
switch.
2013-06-28 21:00:08 +00:00
Andrey V. Elsukov
b9ef8051ae Use getnameinfo(3) instead of inet_ntop(3) to make printable versions of
sockaddr_in6 structures. getnameinfo(3) does the same thing, but it is
also able to represent a scope zone id as described in the RFC 4007.

MFC after:	2 weeks
2013-06-07 08:06:48 +00:00
Pawel Jakub Dawidek
d2c9ca44c3 If the -r option is given we cannot enter capability mode.
The option tells kdump to convert numeric UIDs and GIDs into user and
group names plus to convert times and dates into locallized versions.
This all needs opening various files at various occasions.
2013-05-30 21:59:29 +00:00
Pawel Jakub Dawidek
f9b20fc804 MFp4 @229086:
Make use of Capsicum to protect kdump(1), as it might be used to parse data
from untrusted sources:

- Sandbox kdump(1) using capability mode.
- Limit stdin descriptor (where opened file is moved to) to only
  CAP_READ and CAP_FSTAT rights.
- Limit stdout descriptor to only CAP_WRITE, CAP_FSTAT and CAP_IOCTL.
  Plus limit allowed ioctls to TIOCGETA only, which is needed for
  isatty() to work.
- Limit stderr descriptor to only CAP_WRITE and CAP_FSTAT. In addition
  if the -s option is not given, grant CAP_IOCTL right, but allow for
  TIOCGWINSZ ioctl only, as we need screen width to dump the data.
- Before entering capability mode call catopen("libc", NL_CAT_LOCALE),
  which opens message catalogs and caches data, so that strerror(3)
  and strsignal(3) can work in a sandbox.

Sponsored by:	The FreeBSD Foundation
Discussed with:	rwatson
2013-05-28 21:25:28 +00:00
Pawel Jakub Dawidek
4b0ae51212 MFp4 @229085:
Rearrange the code so we don't call ioctl(TIOCGWINSZ) if the -s option is given,
as the result won't be used then.

Sponsored by:	The FreeBSD Foundation
2013-05-28 21:21:46 +00:00
Pawel Jakub Dawidek
2609222ab4 Merge Capsicum overhaul:
- Capability is no longer separate descriptor type. Now every descriptor
  has set of its own capability rights.

- The cap_new(2) system call is left, but it is no longer documented and
  should not be used in new code.

- The new syscall cap_rights_limit(2) should be used instead of
  cap_new(2), which limits capability rights of the given descriptor
  without creating a new one.

- The cap_getrights(2) syscall is renamed to cap_rights_get(2).

- If CAP_IOCTL capability right is present we can further reduce allowed
  ioctls list with the new cap_ioctls_limit(2) syscall. List of allowed
  ioctls can be retrived with cap_ioctls_get(2) syscall.

- If CAP_FCNTL capability right is present we can further reduce fcntls
  that can be used with the new cap_fcntls_limit(2) syscall and retrive
  them with cap_fcntls_get(2).

- To support ioctl and fcntl white-listing the filedesc structure was
  heavly modified.

- The audit subsystem, kdump and procstat tools were updated to
  recognize new syscalls.

- Capability rights were revised and eventhough I tried hard to provide
  backward API and ABI compatibility there are some incompatible changes
  that are described in detail below:

	CAP_CREATE old behaviour:
	- Allow for openat(2)+O_CREAT.
	- Allow for linkat(2).
	- Allow for symlinkat(2).
	CAP_CREATE new behaviour:
	- Allow for openat(2)+O_CREAT.

	Added CAP_LINKAT:
	- Allow for linkat(2). ABI: Reuses CAP_RMDIR bit.
	- Allow to be target for renameat(2).

	Added CAP_SYMLINKAT:
	- Allow for symlinkat(2).

	Removed CAP_DELETE. Old behaviour:
	- Allow for unlinkat(2) when removing non-directory object.
	- Allow to be source for renameat(2).

	Removed CAP_RMDIR. Old behaviour:
	- Allow for unlinkat(2) when removing directory.

	Added CAP_RENAMEAT:
	- Required for source directory for the renameat(2) syscall.

	Added CAP_UNLINKAT (effectively it replaces CAP_DELETE and CAP_RMDIR):
	- Allow for unlinkat(2) on any object.
	- Required if target of renameat(2) exists and will be removed by this
	  call.

	Removed CAP_MAPEXEC.

	CAP_MMAP old behaviour:
	- Allow for mmap(2) with any combination of PROT_NONE, PROT_READ and
	  PROT_WRITE.
	CAP_MMAP new behaviour:
	- Allow for mmap(2)+PROT_NONE.

	Added CAP_MMAP_R:
	- Allow for mmap(PROT_READ).
	Added CAP_MMAP_W:
	- Allow for mmap(PROT_WRITE).
	Added CAP_MMAP_X:
	- Allow for mmap(PROT_EXEC).
	Added CAP_MMAP_RW:
	- Allow for mmap(PROT_READ | PROT_WRITE).
	Added CAP_MMAP_RX:
	- Allow for mmap(PROT_READ | PROT_EXEC).
	Added CAP_MMAP_WX:
	- Allow for mmap(PROT_WRITE | PROT_EXEC).
	Added CAP_MMAP_RWX:
	- Allow for mmap(PROT_READ | PROT_WRITE | PROT_EXEC).

	Renamed CAP_MKDIR to CAP_MKDIRAT.
	Renamed CAP_MKFIFO to CAP_MKFIFOAT.
	Renamed CAP_MKNODE to CAP_MKNODEAT.

	CAP_READ old behaviour:
	- Allow pread(2).
	- Disallow read(2), readv(2) (if there is no CAP_SEEK).
	CAP_READ new behaviour:
	- Allow read(2), readv(2).
	- Disallow pread(2) (CAP_SEEK was also required).

	CAP_WRITE old behaviour:
	- Allow pwrite(2).
	- Disallow write(2), writev(2) (if there is no CAP_SEEK).
	CAP_WRITE new behaviour:
	- Allow write(2), writev(2).
	- Disallow pwrite(2) (CAP_SEEK was also required).

	Added convinient defines:

	#define	CAP_PREAD		(CAP_SEEK | CAP_READ)
	#define	CAP_PWRITE		(CAP_SEEK | CAP_WRITE)
	#define	CAP_MMAP_R		(CAP_MMAP | CAP_SEEK | CAP_READ)
	#define	CAP_MMAP_W		(CAP_MMAP | CAP_SEEK | CAP_WRITE)
	#define	CAP_MMAP_X		(CAP_MMAP | CAP_SEEK | 0x0000000000000008ULL)
	#define	CAP_MMAP_RW		(CAP_MMAP_R | CAP_MMAP_W)
	#define	CAP_MMAP_RX		(CAP_MMAP_R | CAP_MMAP_X)
	#define	CAP_MMAP_WX		(CAP_MMAP_W | CAP_MMAP_X)
	#define	CAP_MMAP_RWX		(CAP_MMAP_R | CAP_MMAP_W | CAP_MMAP_X)
	#define	CAP_RECV		CAP_READ
	#define	CAP_SEND		CAP_WRITE

	#define	CAP_SOCK_CLIENT \
		(CAP_CONNECT | CAP_GETPEERNAME | CAP_GETSOCKNAME | CAP_GETSOCKOPT | \
		 CAP_PEELOFF | CAP_RECV | CAP_SEND | CAP_SETSOCKOPT | CAP_SHUTDOWN)
	#define	CAP_SOCK_SERVER \
		(CAP_ACCEPT | CAP_BIND | CAP_GETPEERNAME | CAP_GETSOCKNAME | \
		 CAP_GETSOCKOPT | CAP_LISTEN | CAP_PEELOFF | CAP_RECV | CAP_SEND | \
		 CAP_SETSOCKOPT | CAP_SHUTDOWN)

	Added defines for backward API compatibility:

	#define	CAP_MAPEXEC		CAP_MMAP_X
	#define	CAP_DELETE		CAP_UNLINKAT
	#define	CAP_MKDIR		CAP_MKDIRAT
	#define	CAP_RMDIR		CAP_UNLINKAT
	#define	CAP_MKFIFO		CAP_MKFIFOAT
	#define	CAP_MKNOD		CAP_MKNODAT
	#define	CAP_SOCK_ALL		(CAP_SOCK_CLIENT | CAP_SOCK_SERVER)

Sponsored by:	The FreeBSD Foundation
Reviewed by:	Christoph Mallon <christoph.mallon@gmx.de>
Many aspects discussed with:	rwatson, benl, jonathan
ABI compatibility discussed with:	kib
2013-03-02 00:53:12 +00:00
Andrey Zonov
4b03484ff7 - Make actually printing path of AF_LOCAL socket types.
MFC after:	1 week
2013-02-12 19:10:54 +00:00
Andrey Zonov
449df4ecb8 - Use correct size of copying different socket structures.
MFC after:	1 week
2013-02-12 18:48:11 +00:00
Sergey Kandaurov
e6043cf0e1 o Bring in sync decoding the first nfssvc(2) parameter (flags) with
the current definitions location.
o Respect numbers in NFSSVC_* (e.g. NFSSVC_V4ROOTEXPORT).

MFC after:	1 week
2013-02-12 13:01:34 +00:00
Jilles Tjoelker
a018a3c9e2 kdump: Also decode fcntl commands containing underscores and digits.
The commands F_SETLK_REMOTE, F_DUPFD_CLOEXEC and F_DUP2FD_CLOEXEC were not
decoded.
2012-11-02 16:07:21 +00:00
Attilio Rao
2e564269d0 Disconnect non-MPSAFE SMBFS from the build in preparation for dropping
GIANT from VFS. In addition, disconnect also netsmb, which is a base
requirement for SMBFS.

In the while SMBFS regular users can use FUSE interface and smbnetfs
port to work with their SMBFS partitions.

Also, there are ongoing efforts by vendor to support in-kernel smbfs,
so there are good chances that it will get relinked once properly locked.

This is not targeted for MFC.
2012-10-18 12:04:56 +00:00
Jilles Tjoelker
5677eef9a7 kdump: Pretty-print signal codes.
MFC after:	1 week
2012-09-22 12:40:00 +00:00
John Baldwin
01a36e296d Allow the -p argument to kdump to accept either a PID or a thread ID.
Submitted by:	Dmitry Banschikov  d.banschikov hostcomm ru
MFC after:	1 week
2012-06-04 19:09:14 +00:00
Alexander Motin
f6ad3f237a MFprojects/zfsd:
Revamp the CAM enclosure services driver.
This updated driver uses an in-kernel daemon to track state changes and
publishes physical path location information\for disk elements into the
CAM device database.

Sponsored by:   Spectra Logic Corporation
Sponsored by:   iXsystems, Inc.
Submitted by:   gibbs, will, mav
2012-05-24 14:07:44 +00:00
John Baldwin
88bf5036fc Include the associated wait channel message for context switch ktrace
records.  kdump supports both the old and new messages.

Submitted by:	Andrey Zonov  andrey zonov org
MFC after:	1 week
2012-04-20 15:32:36 +00:00
Dimitry Andric
c1b2e4fc21 In kdump's mkioctls script, use '${CPP}' instead of hardcodedly using
'gcc -E'.  This fixes building when WITH_CLANG_IS_CC is in effect.

Report by:	Niclas Zeising <zeising@daemonic.se>
MFC after:	1 week
2012-04-09 14:47:18 +00:00
John Baldwin
35818d2e94 Add new ktrace records for the start and end of VM faults. This gives
a pair of records similar to syscall entry and return that a user can
use to determine how long page faults take.  The new ktrace records are
enabled via the 'p' trace type, and are enabled in the default set of
trace points.

Reviewed by:	kib
MFC after:	2 weeks
2012-04-05 17:13:14 +00:00
John Baldwin
9fd52232b8 Fix style in previous commit.
Submitted by:	bde
2012-02-24 20:12:53 +00:00
John Baldwin
145e6aa9f8 Pretty-print the advice constants passed to posix_fadvise(2).
MFC after:	2 weeks
2012-02-23 21:08:21 +00:00
Dag-Erling Smørgrav
c04743dac1 It turns out that truss also used kdump's mkioctls script, and expected
ioctlname() to return a pointer to the name rather than print it.  This did
not show up in testing because truss had its own prototype for ioctlname(),
so it would build fine and run fine as long as the program being traced did
not issue an ioctl.

Teach mkioctls to generate different versions of ioctlname() based on its
first command-line argument.

Pointed out by:	Garrett Cooper <yanegomi@gmail.com>
2011-10-21 11:08:25 +00:00
Dag-Erling Smørgrav
60e45df8ed Fix copy-pasto in CAPFAIL_INCREASE case.
Noticed by:	pjd
2011-10-18 09:39:41 +00:00
Dag-Erling Smørgrav
e141be6f79 Revisit the capability failure trace points. The initial implementation
only logged instances where an operation on a file descriptor required
capabilities which the file descriptor did not have.  By adding a type enum
to struct ktr_cap_fail, we can catch other types of capability failures as
well, such as disallowed system calls or attempts to wrap a file descriptor
with more capabilities than it had to begin with.
2011-10-18 07:28:58 +00:00
Dag-Erling Smørgrav
51b6c61f98 Clean up mkioctls a bit, and fix cross-building by checking ${MACHINE}
instead of $(uname -m).

Pointed out by:	nyan@
2011-10-13 16:29:24 +00:00
Dag-Erling Smørgrav
81a3139422 Make kdump compile cleanly at WARNS level 6, with one exception: the
ipfilter headers contain a duplicated function declaration.  Turn off
-Werror to allow kdump to compile in spite of this.

It would be neat to be able to turn off -Werror on a file-by-file basis...

PR:		bin/161478
Submitted by:	Garrett Cooper <yanegomi@gmail.com>
2011-10-12 21:45:12 +00:00
Dag-Erling Smørgrav
c601ad8eeb Add a new trace point, KTRFAC_CAPFAIL, which traces capability check
failures.  It is included in the default set for ktrace(1) and kdump(1).
2011-10-11 20:37:10 +00:00
Dag-Erling Smørgrav
661522f5f3 The previous commit did not fix the issue since it did not prevent sign
extension.  Cast to u_register_t first, then to uintmax_t.

Submitted by:	bde@
2011-10-11 15:04:58 +00:00
Dag-Erling Smørgrav
63a896e49b Cast to unsigned for %#jx.
Noticed by:	jh@
2011-10-11 07:46:45 +00:00
Dag-Erling Smørgrav
95bb676aee Address some of bde@'s concerns with the new code. 2011-10-08 21:02:08 +00:00
Dag-Erling Smørgrav
515dfc239d Teach kdump(1) to decode capability bitmasks.
MFC after:	3 weeks
2011-10-08 13:01:38 +00:00
Dag-Erling Smørgrav
6eaa54110b Fix the dependency issue properly by a) moving kdump_subr.c to the front
of the SRCS list and b) listing kdump_subr.h in DPSRCS.
2011-10-08 12:59:41 +00:00
Dag-Erling Smørgrav
d09e66be12 Bring ioctlname() in line with all the other *name() functions, which
actually print the name (or the numeric value, if they can't figure out
the correct name) instead of just returning a pointer to it.  Also, since
ioctl numbers are not and probably never will be unique, drop support for
using a switch statement instead of an if/else chain.
2011-10-08 12:47:00 +00:00
Dag-Erling Smørgrav
09307b2547 I appreciate the logic behind using a (void) cast to indicate that the
return value is intentionally ignored, but frankly, all it does is
get in the way of the code.

Also fix a few other incorrect casts, such as (void *)malloc(foo) and
passing signed values to %x.
2011-10-08 12:28:06 +00:00
Dag-Erling Smørgrav
e4bb45b1ce Fix casting. 2011-10-08 12:21:51 +00:00
Dag-Erling Smørgrav
c02541ee80 Whitespace. 2011-10-08 12:10:16 +00:00
Dag-Erling Smørgrav
73430055e6 C has had swicth statements for 40 years or so. It's about time we
started using them.
2011-10-08 11:51:48 +00:00
Dag-Erling Smørgrav
77e23dbe07 Sort and line up. 2011-10-08 11:39:00 +00:00
Dag-Erling Smørgrav
34bb8e6d12 1) Some of the #defines or enums for which we auto-generate naming
functions may be wider than int, so use intmax_t throughout.  Also
   add missing casts in printf() calls.

2) Clean up some of the auto-generated code to improve readability.

3) Auto-generate kdump_subr.h.  Note that this requires a semi-ugly hack
   in the Makefile to make sure it is generated before make(1) tries to
   build kdump.c, or preprocess it for 'make depend'.

MFC after:	3 weeks
2011-10-08 09:57:29 +00:00
Alexander Leidinger
b66e74b695 Add 2-clause BSD license.
Approved by:	David Kirchner <dpk@dpk.net> (initial author)
Requested by:	Otto Moerbeek <otto@drijf.net>
MFC after:	1 week
2011-06-17 06:12:28 +00:00
Dmitry Chagin
27242311a3 Fix regex for ptraceopname().
PR:		bin/157663
Submitted by:	jason wright <jason@thought.net>
MFC after:	10 days
2011-06-06 19:00:38 +00:00
Jilles Tjoelker
a4a1c5b11e kdump: Show code for signals where the default action was taken.
This information is available as of kernel r220740. Trace files from older
kernels will always have 0.

MFC after:	1 week
2011-04-17 21:11:55 +00:00
Dmitry Chagin
dde5f9b938 Teach kdump to decode linux syscalls names too.
Fix bug introduced in my previous commit: the kernel always dump native
signal numbers, so no need to check the ABI in ktrpsig().

Suggested by:	jhb
MFC after:	1 Month.
2011-03-01 16:42:28 +00:00
Dmitry Chagin
a30c325c64 Update manual page to reflect latest changes of ABI description support.
MFC after:	1 Month.
2011-02-25 22:14:12 +00:00
Dmitry Chagin
7144d36fab Teach kdump to understand sv_flags records in the trace files.
MFC after:	1 Month.
2011-02-25 22:07:23 +00:00
Joel Dahl
da52b4caaf Remove the advertising clause from UCB copyrighted files in usr.bin. This
is in accordance with the information provided at
ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change

Also add $FreeBSD$ to a few files to keep svn happy.

Discussed with:	imp, rwatson
2010-12-11 08:32:16 +00:00
Xin LI
706d26a4a4 Decode IPC_CREAT and IPC_EXCL for semget(2).
PR:		bin/152781
Submitted by:	Anton Yuzhaninov <citrin citrin ru>
MFC after:	2 weeks
2010-12-02 18:24:22 +00:00
John Baldwin
c23d84a86b Correct the abbreviations for general I/O and signal traces.
PR:		docs/151854
Submitted by:	Stephen Veiss  stephen of brokenbottle net
MFC after:	3 days
2010-11-01 15:18:57 +00:00
Alexander Leidinger
57db56459a Fix regex for some socket- and acl-related syscall values.
Submitted by:	Mikhail <hidden.node@gmail.com>
PR:		149295
MFC-after:	2 weeks
2010-10-06 12:41:42 +00:00
Rui Paulo
bd0f1ee24f Fix indenting of the previous commit. 2010-09-16 11:40:41 +00:00
Rui Paulo
836450ab23 When generating functions to print the arguments of system calls with
bitwise parameters (e.g. mmap), print the syscall parameter value first.
The resulting output looks like the %b specifier of printf(9).

Before:
mmap(0,0x8000,PROT_READ|PROT_WRITE,...
After:
mmap(0,0x8000,0x3<PROT_READ|PROT_WRITE>,...

Submitted by:	Norberto Lopes <nlopes.ml at gmail.com>
Idea from:	freebsd-arch/2006-April/005116.html
2010-09-16 11:33:31 +00:00
Ed Schouten
99742a231f Change all our own code to use st_*tim instead of st_*timespec.
Also remove some local patches to diff(1) which are now unneeded.
2010-03-28 13:16:08 +00:00