2609222ab4
- 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
170 lines
5.2 KiB
C
170 lines
5.2 KiB
C
/*-
|
|
* Copyright (c) 2009 Stanislav Sedov <stas@FreeBSD.org>
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*
|
|
* $FreeBSD$
|
|
*/
|
|
|
|
#ifndef _LIBPROCSTAT_H_
|
|
#define _LIBPROCSTAT_H_
|
|
|
|
/*
|
|
* Vnode types.
|
|
*/
|
|
#define PS_FST_VTYPE_VNON 1
|
|
#define PS_FST_VTYPE_VREG 2
|
|
#define PS_FST_VTYPE_VDIR 3
|
|
#define PS_FST_VTYPE_VBLK 4
|
|
#define PS_FST_VTYPE_VCHR 5
|
|
#define PS_FST_VTYPE_VLNK 6
|
|
#define PS_FST_VTYPE_VSOCK 7
|
|
#define PS_FST_VTYPE_VFIFO 8
|
|
#define PS_FST_VTYPE_VBAD 9
|
|
#define PS_FST_VTYPE_UNKNOWN 255
|
|
|
|
/*
|
|
* Descriptor types.
|
|
*/
|
|
#define PS_FST_TYPE_VNODE 1
|
|
#define PS_FST_TYPE_FIFO 2
|
|
#define PS_FST_TYPE_SOCKET 3
|
|
#define PS_FST_TYPE_PIPE 4
|
|
#define PS_FST_TYPE_PTS 5
|
|
#define PS_FST_TYPE_KQUEUE 6
|
|
#define PS_FST_TYPE_CRYPTO 7
|
|
#define PS_FST_TYPE_MQUEUE 8
|
|
#define PS_FST_TYPE_SHM 9
|
|
#define PS_FST_TYPE_SEM 10
|
|
#define PS_FST_TYPE_UNKNOWN 11
|
|
#define PS_FST_TYPE_NONE 12
|
|
|
|
/*
|
|
* Special descriptor numbers.
|
|
*/
|
|
#define PS_FST_UFLAG_RDIR 0x0001
|
|
#define PS_FST_UFLAG_CDIR 0x0002
|
|
#define PS_FST_UFLAG_JAIL 0x0004
|
|
#define PS_FST_UFLAG_TRACE 0x0008
|
|
#define PS_FST_UFLAG_TEXT 0x0010
|
|
#define PS_FST_UFLAG_MMAP 0x0020
|
|
#define PS_FST_UFLAG_CTTY 0x0040
|
|
|
|
/*
|
|
* Descriptor flags.
|
|
*/
|
|
#define PS_FST_FFLAG_READ 0x0001
|
|
#define PS_FST_FFLAG_WRITE 0x0002
|
|
#define PS_FST_FFLAG_NONBLOCK 0x0004
|
|
#define PS_FST_FFLAG_APPEND 0x0008
|
|
#define PS_FST_FFLAG_SHLOCK 0x0010
|
|
#define PS_FST_FFLAG_EXLOCK 0x0020
|
|
#define PS_FST_FFLAG_ASYNC 0x0040
|
|
#define PS_FST_FFLAG_SYNC 0x0080
|
|
#define PS_FST_FFLAG_NOFOLLOW 0x0100
|
|
#define PS_FST_FFLAG_CREAT 0x0200
|
|
#define PS_FST_FFLAG_TRUNC 0x0400
|
|
#define PS_FST_FFLAG_EXCL 0x0800
|
|
#define PS_FST_FFLAG_DIRECT 0x1000
|
|
#define PS_FST_FFLAG_EXEC 0x2000
|
|
#define PS_FST_FFLAG_HASLOCK 0x4000
|
|
|
|
struct procstat;
|
|
struct filestat {
|
|
int fs_type; /* Descriptor type. */
|
|
int fs_flags; /* filestat specific flags. */
|
|
int fs_fflags; /* Descriptor access flags. */
|
|
int fs_uflags; /* How this file is used. */
|
|
int fs_fd; /* File descriptor number. */
|
|
int fs_ref_count; /* Reference count. */
|
|
off_t fs_offset; /* Seek location. */
|
|
void *fs_typedep; /* Type dependent data. */
|
|
char *fs_path;
|
|
STAILQ_ENTRY(filestat) next;
|
|
cap_rights_t fs_cap_rights; /* Capability rights, if flag set. */
|
|
};
|
|
struct vnstat {
|
|
uint64_t vn_fileid;
|
|
uint64_t vn_size;
|
|
char *vn_mntdir;
|
|
uint32_t vn_dev;
|
|
uint32_t vn_fsid;
|
|
int vn_type;
|
|
uint16_t vn_mode;
|
|
char vn_devname[SPECNAMELEN + 1];
|
|
};
|
|
struct ptsstat {
|
|
uint32_t dev;
|
|
char devname[SPECNAMELEN + 1];
|
|
};
|
|
struct pipestat {
|
|
size_t buffer_cnt;
|
|
uint64_t addr;
|
|
uint64_t peer;
|
|
};
|
|
struct shmstat {
|
|
uint64_t size;
|
|
uint16_t mode;
|
|
};
|
|
struct sockstat {
|
|
uint64_t inp_ppcb;
|
|
uint64_t so_addr;
|
|
uint64_t so_pcb;
|
|
uint64_t unp_conn;
|
|
int dom_family;
|
|
int proto;
|
|
int so_rcv_sb_state;
|
|
int so_snd_sb_state;
|
|
struct sockaddr_storage sa_local; /* Socket address. */
|
|
struct sockaddr_storage sa_peer; /* Peer address. */
|
|
int type;
|
|
char dname[32];
|
|
};
|
|
|
|
STAILQ_HEAD(filestat_list, filestat);
|
|
|
|
__BEGIN_DECLS
|
|
void procstat_close(struct procstat *procstat);
|
|
void procstat_freeprocs(struct procstat *procstat, struct kinfo_proc *p);
|
|
void procstat_freefiles(struct procstat *procstat,
|
|
struct filestat_list *head);
|
|
struct filestat_list *procstat_getfiles(struct procstat *procstat,
|
|
struct kinfo_proc *kp, int mmapped);
|
|
struct kinfo_proc *procstat_getprocs(struct procstat *procstat,
|
|
int what, int arg, unsigned int *count);
|
|
int procstat_get_pipe_info(struct procstat *procstat, struct filestat *fst,
|
|
struct pipestat *pipe, char *errbuf);
|
|
int procstat_get_pts_info(struct procstat *procstat, struct filestat *fst,
|
|
struct ptsstat *pts, char *errbuf);
|
|
int procstat_get_shm_info(struct procstat *procstat, struct filestat *fst,
|
|
struct shmstat *shm, char *errbuf);
|
|
int procstat_get_socket_info(struct procstat *procstat, struct filestat *fst,
|
|
struct sockstat *sock, char *errbuf);
|
|
int procstat_get_vnode_info(struct procstat *procstat, struct filestat *fst,
|
|
struct vnstat *vn, char *errbuf);
|
|
struct procstat *procstat_open_sysctl(void);
|
|
struct procstat *procstat_open_kvm(const char *nlistf, const char *memf);
|
|
__END_DECLS
|
|
|
|
#endif /* !_LIBPROCSTAT_H_ */
|