freebsd-dev/lib/libc/sys
Pawel Jakub Dawidek 7008be5bd7 Change the cap_rights_t type from uint64_t to a structure that we can extend
in the future in a backward compatible (API and ABI) way.

The cap_rights_t represents capability rights. We used to use one bit to
represent one right, but we are running out of spare bits. Currently the new
structure provides place for 114 rights (so 50 more than the previous
cap_rights_t), but it is possible to grow the structure to hold at least 285
rights, although we can make it even larger if 285 rights won't be enough.

The structure definition looks like this:

	struct cap_rights {
		uint64_t	cr_rights[CAP_RIGHTS_VERSION + 2];
	};

The initial CAP_RIGHTS_VERSION is 0.

The top two bits in the first element of the cr_rights[] array contain total
number of elements in the array - 2. This means if those two bits are equal to
0, we have 2 array elements.

The top two bits in all remaining array elements should be 0.
The next five bits in all array elements contain array index. Only one bit is
used and bit position in this five-bits range defines array index. This means
there can be at most five array elements in the future.

To define new right the CAPRIGHT() macro must be used. The macro takes two
arguments - an array index and a bit to set, eg.

	#define	CAP_PDKILL	CAPRIGHT(1, 0x0000000000000800ULL)

We still support aliases that combine few rights, but the rights have to belong
to the same array element, eg:

	#define	CAP_LOOKUP	CAPRIGHT(0, 0x0000000000000400ULL)
	#define	CAP_FCHMOD	CAPRIGHT(0, 0x0000000000002000ULL)

	#define	CAP_FCHMODAT	(CAP_FCHMOD | CAP_LOOKUP)

There is new API to manage the new cap_rights_t structure:

	cap_rights_t *cap_rights_init(cap_rights_t *rights, ...);
	void cap_rights_set(cap_rights_t *rights, ...);
	void cap_rights_clear(cap_rights_t *rights, ...);
	bool cap_rights_is_set(const cap_rights_t *rights, ...);

	bool cap_rights_is_valid(const cap_rights_t *rights);
	void cap_rights_merge(cap_rights_t *dst, const cap_rights_t *src);
	void cap_rights_remove(cap_rights_t *dst, const cap_rights_t *src);
	bool cap_rights_contains(const cap_rights_t *big, const cap_rights_t *little);

Capability rights to the cap_rights_init(), cap_rights_set(),
cap_rights_clear() and cap_rights_is_set() functions are provided by
separating them with commas, eg:

	cap_rights_t rights;

	cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FSTAT);

There is no need to terminate the list of rights, as those functions are
actually macros that take care of the termination, eg:

	#define	cap_rights_set(rights, ...)				\
		__cap_rights_set((rights), __VA_ARGS__, 0ULL)
	void __cap_rights_set(cap_rights_t *rights, ...);

Thanks to using one bit as an array index we can assert in those functions that
there are no two rights belonging to different array elements provided
together. For example this is illegal and will be detected, because CAP_LOOKUP
belongs to element 0 and CAP_PDKILL to element 1:

	cap_rights_init(&rights, CAP_LOOKUP | CAP_PDKILL);

Providing several rights that belongs to the same array's element this way is
correct, but is not advised. It should only be used for aliases definition.

This commit also breaks compatibility with some existing Capsicum system calls,
but I see no other way to do that. This should be fine as Capsicum is still
experimental and this change is not going to 9.x.

Sponsored by:	The FreeBSD Foundation
2013-09-05 00:09:56 +00:00
..
__error.c
__vdso_gettimeofday.c Rework the __vdso_* symbols attributes to only make the symbols weak, 2013-01-30 12:48:16 +00:00
_exit.2
abort2.2
accept.2 accept(2), pipe(2): Fix .Dd. 2013-05-01 22:47:47 +00:00
access.2
acct.2
adjtime.2
aio_cancel.2
aio_error.2
aio_mlock.2 Minor mdoc fixes. 2013-06-09 07:15:43 +00:00
aio_read.2
aio_return.2
aio_suspend.2
aio_waitcomplete.2
aio_write.2
bind.2 Document that bind(2) can fail with EAFNOSUPPORT. 2012-12-04 09:53:09 +00:00
bindat.2 - Implement two new system calls: 2013-03-02 21:11:30 +00:00
brk.2
cap_enter.2 Merge Capsicum overhaul: 2013-03-02 00:53:12 +00:00
cap_fcntls_limit.2 mdoc: remove superfluous paragraph macro. 2013-03-02 06:55:55 +00:00
cap_ioctls_limit.2 Correct function name and return value. 2013-08-17 14:55:31 +00:00
cap_rights_limit.2 cap_rights_limit(2): CAP_ACCEPT also permits accept4(2). 2013-05-27 21:37:19 +00:00
chdir.2
chflags.2 Remove EOL whitespace. 2013-08-22 16:02:20 +00:00
chmod.2
chown.2
chroot.2 - Use standard RETURN VALUES section. 2013-01-15 14:09:08 +00:00
clock_gettime.2
clock_gettime.c
close.2
closefrom.2
connect.2
connectat.2 - Implement two new system calls: 2013-03-02 21:11:30 +00:00
cpuset_getaffinity.2 Remove cross-references to nonexistent CPU_SET(3) manpage. 2013-04-21 06:46:41 +00:00
cpuset.2 Remove cross-references to nonexistent CPU_SET(3) manpage. 2013-04-21 06:46:41 +00:00
dup.2 Add man page dup3(3). 2013-08-16 13:16:27 +00:00
execve.2
extattr_get_file.2 Fix return type of extattr_set_* and fix rmextattr(8) utility. 2013-04-02 05:30:41 +00:00
fcntl.2 Make the F_READAHEAD option to fcntl(2) work as documented: a value of zero 2013-02-13 15:09:16 +00:00
fcntl.c
ffclock.2
fhopen.2
flock.2
fork.2 fork(2): Add information about fork() in multi-threaded processes. 2013-05-31 20:46:08 +00:00
fsync.2
ftruncate.c
getdirentries.2
getdtablesize.2 getdtablesize(2): Describe what this function actually does. 2013-04-24 21:24:35 +00:00
getfh.2
getfsstat.2
getgid.2
getgroups.2
getitimer.2
getlogin.2
getloginclass.2
getpeername.2 Document that getpeername(2) and getsockname(2) can fail with EINVAL. 2012-11-23 10:14:54 +00:00
getpgrp.2
getpid.2
getpriority.2
getrlimit.2
getrusage.2
getsid.2
getsockname.2 Document that getpeername(2) and getsockname(2) can fail with EINVAL. 2012-11-23 10:14:54 +00:00
getsockopt.2 Correct the returned message lengths for timeval and bintime control 2013-04-05 18:09:43 +00:00
gettimeofday.2
gettimeofday.c Rework the __vdso_* symbols attributes to only make the symbols weak, 2013-01-30 12:48:16 +00:00
getuid.2
intro.2 POSIX 1003.1-2008: add ENOTRECOVERABLE, EOWNERDEAD errnos. 2013-05-04 19:07:22 +00:00
ioctl.2
issetugid.2
jail.2
kenv.2
kill.2
kldfind.2
kldfirstmod.2
kldload.2
kldnext.2
kldstat.2
kldsym.2
kldunload.2
kqueue.2 Enhance the description of NOTE_TRACK: 2013-07-25 19:34:24 +00:00
kse.2
ktrace.2
link.2
lio_listio.2
listen.2
lseek.2
lseek.c
madvise.2
Makefile.inc Add new system call - aio_mlock(). The name speaks for itself. It allows 2013-06-08 13:27:57 +00:00
mincore.2
minherit.2
mkdir.2
mkfifo.2
mknod.2
mlock.2 There are actually two different cases when mlock(2) returns 2013-03-19 05:44:25 +00:00
mlockall.2 - Update manual pages accordingly to r244384 and r244385. 2012-12-25 13:43:01 +00:00
mmap.2 Add new mmap(2) flags to permit applications to request specific virtual 2013-08-16 21:13:55 +00:00
mmap.c
modfind.2
modnext.2
modstat.2
mount.2
mprotect.2
mq_close.2
mq_getattr.2
mq_notify.2
mq_open.2
mq_receive.2
mq_send.2
mq_setattr.2
msgctl.2
msgget.2
msgrcv.2
msgsnd.2
msync.2
munmap.2
nanosleep.2
nfssvc.2
ntp_adjtime.2
open.2 Document the ERESTART translation to EINTR for devfs nodes. 2013-02-07 15:11:43 +00:00
pathconf.2
pdfork.2 Xref capsicum(4) and procdesc(4) from pdfork(2). 2013-08-28 20:00:25 +00:00
pipe.2 accept(2), pipe(2): Fix .Dd. 2013-05-01 22:47:47 +00:00
poll.2
posix_fadvise.2 posix_fadvise(2) first appeared in FreeBSD 9.1 2013-01-23 10:50:52 +00:00
posix_fallocate.2
posix_openpt.2 Allow O_CLOEXEC in posix_openpt() flags. 2013-03-21 21:39:15 +00:00
pread.c
profil.2
pselect.2 pselect(2): Add xref to sigsuspend(2). 2013-08-16 14:06:29 +00:00
ptrace.2 Document EINVAL error return from PT_LWPINFO 2013-07-22 18:18:21 +00:00
pwrite.c
quotactl.2
read.2
readlink.2
reboot.2
recv.2 Implement SOCK_CLOEXEC, SOCK_NONBLOCK and MSG_CMSG_CLOEXEC. 2013-03-19 20:58:17 +00:00
rename.2
revoke.2
rfork.2
rmdir.2
rtprio.2 Document that rtprio(2) and rtprio_thread(2) can fail with EFAULT 2012-11-16 09:56:25 +00:00
sched_get_priority_max.2
sched_setparam.2
sched_setscheduler.2
sched_yield.2
sctp_generic_recvmsg.2 Remove the advertising clause from the Regents of the University of 2013-05-28 21:05:06 +00:00
sctp_generic_sendmsg.2 Remove the advertising clause from the Regents of the University of 2013-05-28 21:05:06 +00:00
sctp_peeloff.2 Remove the advertising clause from the Regents of the University of 2013-05-28 21:05:06 +00:00
select.2
semctl.2
semget.2
semop.2
send.2
sendfile.2 Document that sendfile(2) can fail with ENOBUFS. 2012-11-14 01:45:10 +00:00
setfib.2 Update the setfib man page to reflect recent changes. 2013-05-20 20:47:40 +00:00
setgroups.2
setpgid.2
setregid.2
setresuid.2
setreuid.2
setsid.2
setuid.2
shm_open.2
shmat.2
shmctl.2
shmget.2
shutdown.2
sigaction.2 sigaction(2): Document various non-POSIX functions as async-signal safe. 2013-06-08 13:45:43 +00:00
sigaltstack.2
sigpending.2
sigprocmask.2
sigqueue.2 sigqueue(2): Fix typo (EEPERM -> EPERM). 2013-02-10 13:20:23 +00:00
sigreturn.2 sigreturn(2): Remove ancient compatibility warning about 4.2BSD. 2013-05-25 13:59:40 +00:00
sigstack.2
sigsuspend.2 sigsuspend(2): Add xrefs to pselect(2) and sigwait-alikes. 2013-08-15 22:33:27 +00:00
sigwait.2
sigwait.c
sigwaitinfo.2
socket.2 Implement SOCK_CLOEXEC, SOCK_NONBLOCK and MSG_CMSG_CLOEXEC. 2013-03-19 20:58:17 +00:00
socketpair.2 Implement SOCK_CLOEXEC, SOCK_NONBLOCK and MSG_CMSG_CLOEXEC. 2013-03-19 20:58:17 +00:00
stack_protector_compat.c
stack_protector.c
stat.2
statfs.2
swapon.2
Symbol.map Change the cap_rights_t type from uint64_t to a structure that we can extend 2013-09-05 00:09:56 +00:00
symlink.2
sync.2
sysarch.2
syscall.2
timer_create.2
timer_delete.2
timer_settime.2
truncate.2
truncate.c
umask.2
undelete.2
unlink.2
utimes.2
utrace.2
uuidgen.2
vfork.2
wait.2 Document wait6() and waitid(). 2012-11-13 12:56:42 +00:00
write.2