1 .\" $NetBSD: kauth.9,v 1.88 2009/08/10 22:36:37 wiz Exp $
3 .\" Copyright (c) 2005, 2006 Elad Efrat <elad@NetBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. The name of the author may not be used to endorse or promote products
15 .\" derived from this software without specific prior written permission.
17 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 .Nd kernel authorization framework
38 or kernel authorization, is the subsystem managing all authorization requests
40 It manages user credentials and rights, and can be used
41 to implement a system-wide security policy.
42 It allows external modules to plug-in the authorization process.
45 introduces some new concepts, namely
49 which will be detailed together with other useful information for kernel
50 developers in this document.
54 types include the following:
55 .Bl -tag -width kauth_listener_t
57 Representing credentials that can be associated with an object.
58 Includes user- and group-ids (real, effective, and save) as well as group
59 membership information.
69 each scope holding a group of
72 Each listener works as a callback for when an authorization request within the
74 When such a request is made, all listeners on the scope are passed common
75 information such as the credentials of the request context, an identifier for
76 the requested operation, and possibly other information as well.
78 Every listener examines the passed information and returns its decision
79 regarding the requested operation.
80 It can either allow, deny, or defer the operation -- in which case, the
81 decision is left to the other listeners.
83 For an operation to be allowed, all listeners must not return any deny
86 Scopes manage listeners that operate in the same aspect of the system.
87 .Ss Kernel Programming Interface
89 exports a KPI that allows developers both of
91 and third-party products to authorize requests, access and modify credentials,
92 create and remove scopes and listeners, and perform other miscellaneous operations on
94 .Ss Authorization Requests
96 provides a single authorization request routine, which all authorization
98 This routine dispatches the request to the listeners of the appropriate scope,
99 together with four optional user-data variables, and returns the augmented
104 .Ft int Fn kauth_authorize_action "kauth_scope_t scope" "kauth_cred_t cred" \
105 "kauth_action_t op" "void *arg0" "void *arg1" "void *arg2" "void *arg3"
107 An authorization request can return one of two possible values.
108 Zero indicates success -- the operation is allowed;
112 indicates failure -- the operation is denied.
114 Each scope has its own authorization wrapper, to make it easy to call from various
115 places by eliminating the need to specify the scope and/or cast values.
116 The authorization wrappers are detailed in each scope's section.
118 .Fn kauth_authorize_action
119 has several special cases, when it will always allow the request.
120 These are for when the request is issued by the kernel itself (indicated by the
121 credentials being either
125 or when there was no definitive decision from any of the listeners (i.e., it
126 was not explicitly allowed or denied) and no security model was loaded.
129 .Dq org.netbsd.kauth.generic ,
130 manages generic authorization requests in the kernel.
132 The authorization wrapper for this scope is declared as
134 .Ft int Fn kauth_authorize_generic "kauth_cred_t cred" "kauth_action_t op" \
137 The following operations are available for this scope:
138 .Bl -tag -width compact
139 .It Dv KAUTH_GENERIC_ISSUSER
140 Checks whether the credentials belong to the super-user.
142 Using this request is strongly discouraged and should only be done as a
143 temporary place-holder, as it is breaking the separation between the
144 interface for authorization requests from the back-end implementation.
145 .It Dv KAUTH_GENERIC_CANSEE
146 Checks whether an object with one set of credentials can access
147 information about another object, possibly with a different set of
151 contains the credentials of the object looked at.
153 This request should be issued only in cases where generic credentials
154 check is required; otherwise it is recommended to use the object-specific
159 .Dq org.netbsd.kauth.system ,
160 manages authorization requests affecting the entire system.
162 The authorization wrapper for this scope is declared as
164 .Ft int Fn kauth_authorize_system "kauth_cred_t cred" \
165 "kauth_action_t op" "enum kauth_system_req req" "void *arg1" "void *arg2" \
168 The following requests are available for this scope:
169 .Bl -tag -width compact
170 .It Dv KAUTH_SYSTEM_ACCOUNTING
171 Check if enabling/disabling accounting allowed.
172 .It Dv KAUTH_SYSTEM_CHROOT
174 can be any of the following:
175 .Bl -tag -width compact
176 .It Dv KAUTH_REQ_SYSTEM_CHROOT_CHROOT
180 .It Dv KAUTH_REQ_SYSTEM_CHROOT_FCHROOT
185 .It Dv KAUTH_SYSTEM_CPU
186 Check CPU-manipulation access.
189 can be any of the following:
190 .Bl -tag -width compact
191 .It Dv KAUTH_REQ_SYSTEM_CPU_SETSTATE
192 Set CPU state, including setting it online or offline.
194 .It Dv KAUTH_SYSTEM_DEBUG
195 This request concentrates several debugging-related operations.
197 can be any of the following:
198 .Bl -tag -width compact
199 .It Dv KAUTH_REQ_SYSTEM_DEBUG_IPKDB
204 .It Dv KAUTH_SYSTEM_FILEHANDLE
205 Check if filehandle operations allowed.
206 .It Dv KAUTH_SYSTEM_FS_QUOTA
207 Check if file-system quota operations are allowed.
212 describing the file-system mount in question.
214 can be one of the following:
215 .Bl -tag -width compact
216 .It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_GET
217 Check if retrieving quota information is allowed.
222 with the user-id of the user whose quota information is to be retrieved.
223 .It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF
224 Check if turning quota on/off is allowed.
225 .It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE
226 Check if managing the quota by setting the quota/quota use is allowed.
231 with the user-id of the user whose quota/quota use is to be set.
232 .It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_NOLIMIT
233 Check if bypassing the quota (not enforcing it) is allowed.
235 .It Dv KAUTH_SYSTEM_FS_RESERVEDSPACE
236 Check if using the file-system reserved space is allowed.
237 .It Dv KAUTH_SYSTEM_MODULE
238 Check if a module request is allowed.
242 .It Dv KAUTH_SYSTEM_MKNOD
243 Check if creating devices is allowed.
244 .It Dv KAUTH_SYSTEM_MOUNT
245 Check if mount-related operations are allowed.
248 can be any of the following:
249 .Bl -tag -width compact
250 .It Dv KAUTH_REQ_SYSTEM_MOUNT_GET
251 Check if retrieving information about a mount is allowed.
255 with the mount structure in question,
259 with file-system specific data, if any.
260 .It Dv KAUTH_REQ_SYSTEM_MOUNT_NEW
261 Check if mounting a new file-system is allowed.
266 on which the file-system is to be mounted,
270 with the mount flags, and
274 with file-system specific data, if any.
275 .It Dv KAUTH_REQ_SYSTEM_MOUNT_UNMOUNT
276 Checks if unmounting a file-system is allowed.
281 with the mount in question.
282 .It Dv KAUTH_REQ_SYSTEM_MOUNT_UPDATE
283 Checks if updating an existing mount is allowed.
288 of the existing mount,
292 with the new mount flags, and
296 with file-system specific data, if any.
298 .It Dv KAUTH_SYSTEM_PSET
299 Check processor-set manipulation.
302 can be any of the following:
303 .Bl -tag -width compact
304 .It Dv KAUTH_REQ_SYSTEM_PSET_ASSIGN
305 Change processor-set processor assignment.
306 .It Dv KAUTH_REQ_SYSTEM_PSET_BIND
307 Bind an LWP to a processor-set.
308 .It Dv KAUTH_REQ_SYSTEM_PSET_CREATE
309 Create a processor-set.
310 .It Dv KAUTH_REQ_SYSTEM_PSET_DESTROY
311 Destroy a processor-set.
313 .It Dv KAUTH_SYSTEM_REBOOT
314 Check if rebooting is allowed.
315 .It Dv KAUTH_SYSTEM_SETIDCORE
316 Check if changing coredump settings for set-id processes is allowed.
317 .It Dv KAUTH_SYSTEM_SWAPCTL
320 requests are allowed.
321 .It Dv KAUTH_SYSTEM_SYSCTL
322 This requests operations related to
325 indicates the specific request and can be one of the following:
326 .Bl -tag -width compact
327 .It Dv KAUTH_REQ_SYSTEM_SYSCTL_ADD
331 .It Dv KAUTH_REQ_SYSTEM_SYSCTL_DELETE
335 .It Dv KAUTH_REQ_SYSTEM_SYSCTL_DESC
336 Check if adding description to a
339 .It Dv KAUTH_REQ_SYSTEM_SYSCTL_MODIFY
342 node variable that doesn't have a custom sysctl helper function is allowed.
344 This request might be deprecated in the future.
345 .It Dv KAUTH_REQ_SYSTEM_SYSCTL_PRVT
346 Check if accessing private
350 .It Dv KAUTH_SYSTEM_TIME
351 This request groups time-related operations.
353 can be any of the following:
354 .Bl -tag -width compact
355 .It Dv KAUTH_REQ_SYSTEM_TIME_ADJTIME
356 Check if changing the time using
359 .It Dv KAUTH_REQ_SYSTEM_TIME_NTPADJTIME
360 Check if setting the time using
363 .It Dv KAUTH_REQ_SYSTEM_TIME_SYSTEM
364 Check if changing the time (usually via
370 .Ft struct timespec *
375 with the delta from the current time,
379 indicating whether the caller is a device context (e.g.
382 .It Dv KAUTH_REQ_SYSTEM_TIME_RTCOFFSET
383 Check if changing the RTC offset is allowed.
384 .It Dv KAUTH_REQ_SYSTEM_TIME_TIMECOUNTERS
385 Check if manipulating timecounters is allowed.
390 .Dq org.netbsd.kauth.process ,
391 manages authorization requests related to processes in the system.
393 The authorization wrapper for this scope is declared as
395 .Ft int Fn kauth_authorize_process "kauth_cred_t cred" \
396 "kauth_action_t op" "struct proc *p" "void *arg1" "void *arg2" \
399 The following operations are available for this scope:
400 .Bl -tag -width compact
401 .It Dv KAUTH_PROCESS_KTRACE
402 Checks whether an object with one set of credentials can
406 possibly with a different set of credentials.
411 .Dv KAUTH_REQ_PROCESS_KTRACE_PERSISTENT ,
412 this checks if persistent tracing can be done.
413 Persistent tracing maintains the trace across a set-user-id/set-group-id
415 and normally requires privileged credentials.
416 .It Dv KAUTH_PROCESS_PROCFS
417 Checks whether object with passed credentials can use
425 for the target element in the target process, and
427 is the access type, which can be either
428 .Dv KAUTH_REQ_PROCESS_PROCFS_CTL ,
429 .Dv KAUTH_REQ_PROCESS_PROCFS_READ ,
430 .Dv KAUTH_REQ_PROCESS_PROCFS_RW ,
432 .Dv KAUTH_REQ_PROCESS_PROCFS_WRITE ,
440 .It Dv KAUTH_PROCESS_PTRACE
441 Checks whether object with passed credentials can use
450 .It Dv KAUTH_PROCESS_CANSEE
451 Checks whether an object with one set of credentials can access
452 information about another process, possibly with a different set of
456 indicates the class of information being viewed, and can either of
457 .Dv KAUTH_REQ_PROCESS_CANSEE_ARGS ,
458 .Dv KAUTH_REQ_PROCESS_CANSEE_ENTRY ,
459 .Dv KAUTH_REQ_PROCESS_CANSEE_ENV ,
461 .Dv KAUTH_REQ_PROCESS_CANSEE_OPENFILES .
462 .It Dv KAUTH_PROCESS_SCHEDULER_GETAFFINITY
463 Checks whether viewing the scheduler affinity is allowed.
464 .It Dv KAUTH_PROCESS_SCHEDULER_SETAFFINITY
465 Checks whether setting the scheduler affinity is allowed.
466 .It Dv KAUTH_PROCESS_SCHEDULER_GETPARAMS
467 Checks whether viewing the scheduler policy and parameters is allowed.
468 .It Dv KAUTH_PROCESS_SCHEDULER_SETPARAMS
469 Checks whether modifying the scheduler policy and parameters is allowed.
470 .It Dv KAUTH_PROCESS_SIGNAL
471 Checks whether an object with one set of credentials can post signals
475 is the process the signal is being posted to, and
477 is the signal number.
478 .It Dv KAUTH_PROCESS_CORENAME
479 Controls access to process corename.
483 .Dv KAUTH_REQ_PROCESS_CORENAME_GET
485 .Dv KAUTH_REQ_PROCESS_CORENAME_SET ,
486 indicating access to read or write the process' corename, respectively.
488 When modifying the corename,
490 holds the new corename to be used.
491 .It Dv KAUTH_PROCESS_FORK
492 Checks if the process can fork.
496 indicating how many processes exist on the system at the time of the check.
497 .It Dv KAUTH_PROCESS_KEVENT_FILTER
498 Checks whether setting a process
502 .It Dv KAUTH_PROCESS_NICE
509 .It Dv KAUTH_PROCESS_RLIMIT
510 Controls access to process resource limits.
514 .Dv KAUTH_REQ_PROCESS_RLIMIT_GET
516 .Dv KAUTH_REQ_PROCESS_RLIMIT_SET ,
517 indicating access to read or write the process' resource limits, respectively.
519 When modifying resource limits,
521 is the new value to be used and
523 indicates which resource limit is to be modified.
524 .It Dv KAUTH_PROCESS_SETID
525 Check if changing the user- or group-ids, groups, or login-name for
528 .It Dv KAUTH_PROCESS_STOPFLAG
529 Check if setting the stop flags for
537 indicates the flag, and can be either
546 .Dq org.netbsd.kauth.network ,
547 manages networking-related authorization requests in the kernel.
549 The authorization wrapper for this scope is declared as
551 .Ft int Fn kauth_authorize_network "kauth_cred_t cred" "kauth_action_t op" \
552 "enum kauth_network_req req" "void *arg1" "void *arg2" "void *arg3"
554 The following operations are available for this scope:
555 .Bl -tag -width compact
556 .It Dv KAUTH_NETWORK_ALTQ
557 Checks if an ALTQ operation is allowed.
560 indicates the ALTQ subsystem in question, and can be one of the following:
562 .Bl -tag -compact -width compact
563 .It Dv KAUTH_REQ_NETWORK_ALTQ_AFMAP
564 .It Dv KAUTH_REQ_NETWORK_ALTQ_BLUE
565 .It Dv KAUTH_REQ_NETWORK_ALTQ_CBQ
566 .It Dv KAUTH_REQ_NETWORK_ALTQ_CDNR
567 .It Dv KAUTH_REQ_NETWORK_ALTQ_CONF
568 .It Dv KAUTH_REQ_NETWORK_ALTQ_FIFOQ
569 .It Dv KAUTH_REQ_NETWORK_ALTQ_HFSC
570 .It Dv KAUTH_REQ_NETWORK_ALTQ_JOBS
571 .It Dv KAUTH_REQ_NETWORK_ALTQ_PRIQ
572 .It Dv KAUTH_REQ_NETWORK_ALTQ_RED
573 .It Dv KAUTH_REQ_NETWORK_ALTQ_RIO
574 .It Dv KAUTH_REQ_NETWORK_ALTQ_WFQ
576 .It Dv KAUTH_NETWORK_BIND
582 allows to indicate the type of the request to structure listeners and callers
584 Supported request types:
585 .Bl -tag -width compact
586 .It Dv KAUTH_REQ_NETWORK_BIND_PORT
587 Checks if binding to a non-privileged/reserved port is allowed.
588 .It Dv KAUTH_REQ_NETWORK_BIND_PRIVPORT
589 Checks if binding to a privileged/reserved port is allowed.
591 .It Dv KAUTH_NETWORK_FIREWALL
592 Checks if firewall-related operations are allowed.
595 indicates the sub-action, and can be one of the following:
596 .Bl -tag -width compact
597 .It Dv KAUTH_REQ_NETWORK_FIREWALL_FW
598 Modification of packet filtering rules.
599 .It Dv KAUTH_REQ_NETWORK_FIREWALL_NAT
600 Modification of NAT rules.
602 .It Dv KAUTH_NETWORK_INTERFACE
603 Checks if network interface-related operations are allowed.
608 associated with the interface.
612 describing the interface-specific operation.
614 is (optionally) a pointer to the interface-specific request structure.
616 indicates the sub-action, and can be one of the following:
617 .Bl -tag -width compact
618 .It Dv KAUTH_REQ_NETWORK_INTERFACE_GET
619 Check if retrieving information from the device is allowed.
620 .It Dv KAUTH_REQ_NETWORK_INTERFACE_GETPRIV
621 Check if retrieving privileged information from the device is allowed.
622 .It Dv KAUTH_REQ_NETWORK_INTERFACE_SET
623 Check if setting parameters on the device is allowed.
624 .It Dv KAUTH_REQ_NETWORK_INTERFACE_SETPRIV
625 Check if setting privileged parameters on the device is allowed.
630 for the interface was passed in
632 there's no way to tell what structure
635 .It Dv KAUTH_NETWORK_INTERFACE_PPP
636 Checks if operations performed on the
638 network interface are allowed.
641 can be one of the following:
642 .Bl -tag -width compact
643 .It Dv KAUTH_REQ_NETWORK_INTERFACE_PPP_ADD
644 Checks if adding and enabling a
646 interface to the system is allowed.
648 .It Dv KAUTH_NETWORK_INTERFACE_SLIP
649 Checks if operations performed on the
651 network interface are allowed.
654 can be one of the following:
655 .Bl -tag -width compact
656 .It Dv KAUTH_REQ_NETWORK_INTERFACE_SLIP_ADD
657 Checks if adding and enabling a
659 interface to the system is allowed.
661 .It Dv KAUTH_NETWORK_INTERFACE_STRIP
662 Checks if operations performed on the
664 network interface are allowed.
667 can be one of the following:
668 .Bl -tag -width compact
669 .It Dv KAUTH_REQ_NETWORK_INTERFACE_STRIP_ADD
670 Check if adding and enabling a
672 interface to the system is allowed.
674 .It Dv KAUTH_NETWORK_INTERFACE_TUN
675 Checks if operations performed on the
677 network interface are allowed.
680 can be one of the following:
681 .Bl -tag -width compact
682 .It Dv KAUTH_REQ_NETWORK_INTERFACE_TUN_ADD
683 Checks if adding and enabling a
685 interface to the system is allowed.
687 .It Dv KAUTH_NETWORK_FORWSRCRT
688 Checks whether status of forwarding of source-routed packets can be modified
690 .It Dv KAUTH_NETWORK_NFS
691 Check is an NFS related operation is allowed.
694 can be any of the following:
695 .Bl -tag -width compact
696 .It Dv KAUTH_REQ_NETWORK_NFS_EXPORT
697 Check if modifying the NFS export table is allowed.
698 .It Dv KAUTH_REQ_NETWORK_NFS_SVC
699 Check if access to the NFS
703 .It Dv KAUTH_NETWORK_ROUTE
704 Checks if a routing-related request is allowed.
708 .Ft struct rt_msghdr *
710 .It Dv KAUTH_NETWORK_SOCKET
711 Checks if a socket related operation is allowed.
714 allows to indicate the type of the request to structure listeners and callers
716 Supported request types:
717 .Bl -tag -width compact
718 .It Dv KAUTH_REQ_NETWORK_SOCKET_RAWSOCK
719 Checks if opening a raw socket is allowed.
720 .It Dv KAUTH_REQ_NETWORK_SOCKET_OPEN
721 Checks if opening a socket is allowed.
727 parameters describing the domain, socket type, and protocol,
729 .It Dv KAUTH_REQ_NETWORK_SOCKET_CANSEE
730 Checks if looking at the socket passed is allowed.
735 describing the socket.
736 .It Dv KAUTH_REQ_NETWORK_SOCKET_DROP
737 Checks if a connection can be dropped.
742 describing the socket.
743 .It Dv KAUTH_REQ_NETWORK_SOCKET_SETPRIV
744 Checks if setting privileged socket options is allowed.
749 describing the socket,
753 describing the socket option.
756 .Ss Machine-dependent Scope
757 The machine-dependent (machdep) scope,
758 .Dq org.netbsd.kauth.machdep ,
759 manages machine-dependent authorization requests in the kernel.
761 The authorization wrapper for this scope is declared as
763 .Ft int Fn kauth_authorize_machdep "kauth_cred_t cred" "kauth_action_t op" \
764 "void *arg0" "void *arg1" "void *arg2" "void *arg3"
766 The actions on this scope provide a set that may or may not affect all
768 Below is a list of available actions, along with which platforms are affected
770 .Bl -tag -width compact
771 .It Dv KAUTH_MACHDEP_CACHEFLUSH
772 Request to flush the whole CPU cache.
776 .It Dv KAUTH_MACHDEP_IOPERM_GET
777 Request to get the I/O permission level.
782 .It Dv KAUTH_MACHDEP_IOPERM_SET
783 Request to set the I/O permission level.
788 .It Dv KAUTH_MACHDEP_IOPL
789 Request to set the I/O privilege level.
794 .It Dv KAUTH_MACHDEP_LDT_GET
795 Request to get the LDT (local descriptor table).
800 .It Dv KAUTH_MACHDEP_LDT_SET
801 Request to set the LDT (local descriptor table).
806 .It Dv KAUTH_MACHDEP_MTRR_GET
807 Request to get the MTRR (memory type range registers).
812 .It Dv KAUTH_MACHDEP_MTRR_SET
813 Request to set the MTRR (memory type range registers).
818 .It Dv KAUTH_MACHDEP_NVRAM
819 Request to access (read/write) the NVRAM.
822 .It Dv KAUTH_MACHDEP_UNMANAGEDMEM
823 Request to access unmanaged memory.
836 .Dq org.netbsd.kauth.device ,
837 manages authorization requests related to devices on the system.
838 Devices can be, for example, terminals, tape drives, Bluetooth accessories, and
840 Network devices specifically are handled by the
844 In addition to the standard authorization wrapper:
846 .Ft int Fn kauth_authorize_device "kauth_cred_t cred" "kauth_action_t op" \
847 "void *arg0" "void *arg1" "void *arg2" "void *arg3"
849 this scope provides authorization wrappers for various device types.
851 .Ft int Fn kauth_authorize_device_tty "kauth_cred_t cred" "kauth_action_t op" \
854 Authorizes requests for
859 is the terminal device in question.
860 It is passed to the listener as
864 is the action and can be one of the following:
865 .Bl -tag -width compact
866 .It Dv KAUTH_DEVICE_TTY_OPEN
867 Open the terminal device pointed to by
869 .It Dv KAUTH_DEVICE_TTY_PRIVSET
870 Set privileged settings on the terminal device pointed to by
872 .It Dv KAUTH_DEVICE_TTY_STI
877 allowing to inject characters into the terminal buffer, simulating terminal
881 .Ft int Fn kauth_authorize_device_spec "kauth_cred_t cred" \
882 "enum kauth_device_req req" "struct vnode *vp"
884 Authorizes requests for
886 usually disk devices, but also direct memory access, on the system.
889 .Dv KAUTH_DEVICE_RAWIO_SPEC
890 as the action to the listener, and accepts two arguments.
892 passed to the listener as
894 is access requested, and can be one of
895 .Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_READ ,
896 .Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_WRITE ,
898 .Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_RW ,
899 representing read, write, or both read/write access respectively.
901 is the vnode of the special file in question, and is passed to the listener as
904 Keep in mind that it is the responsibility of the security model developer to
905 check whether the underlying device is a disk or the system memory, using
907 .Bd -literal -offset indent
908 if ((vp-\*[Gt]v_type == VCHR) \*[Am]\*[Am]
909 iskmemdev(vp-\*[Gt]v_un.vu_specinfo-\*[Gt]si_rdev))
910 /* system memory access */
913 .Ft int Fn kauth_authorize_device_passthru "kauth_cred_t cred" "dev_t dev" \
914 "u_long mode" "void *data"
918 requests, or user commands passed directly to the hardware.
919 These have the potential of resulting in direct disk and/or memory access.
922 .Dv KAUTH_DEVICE_RAWIO_PASSTHRU
923 as the action to the listener, and accepts three arguments.
927 to the listener, is the device for which the request is made.
931 to the listener, is a generic representation of the access mode requested.
932 It can be one or more (binary-OR'd) of the following:
934 .Bl -tag -width compact -offset indent -compact
935 .It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READ
936 .It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READCONF
937 .It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITE
938 .It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITECONF
944 to the listener, is device-specific data that may be associated with the
946 .Ss Bluetooth Devices
947 Authorizing actions relevant to Bluetooth devices is done using the standard
948 authorization wrapper, with the following actions:
950 .Bl -tag -width compact
951 .It KAUTH_DEVICE_BLUETOOTH_BCSP
952 Check if operations on a
958 .Ft enum kauth_device_req
959 with one of the following values:
960 .Bl -tag -width compact
961 .It Dv KAUTH_REQ_DEVICE_BLUETOOTH_BCSP_ADD
962 Check if adding and enabling a
966 .It KAUTH_DEVICE_BLUETOOTH_BTUART
967 Check if operations on a
973 .Ft enum kauth_device_req
974 with one of the following values:
975 .Bl -tag -width compact
976 .It Dv KAUTH_REQ_DEVICE_BLUETOOTH_BTUART_ADD
977 Check if adding and enabling a
981 .It KAUTH_DEVICE_BLUETOOTH_RECV
982 Check if a packet can be received from the device.
994 is the event ID, and for
1000 is the connection handle.
1001 .It KAUTH_DEVICE_BLUETOOTH_SEND
1002 Check if a packet can be sent to the device.
1006 .Ft struct hci_unit *
1007 describing the HCI unit,
1011 describing the packet header.
1012 .It KAUTH_DEVICE_BLUETOOTH_SETPRIV
1013 Check if privileged settings can be changed.
1017 .Ft struct hci_unit *
1018 describing the HCI unit,
1022 describing the request, and
1026 describing the command.
1028 .Ss Kernel random device
1029 Authorization actions relevant to the kernel random device,
1031 is done using the standard authorization wrapper, with the following actions:
1033 .Bl -tag -width compact
1034 .It KAUTH_DEVICE_RND_ADDDATA
1035 Check if adding data to the entropy pool is allowed.
1036 .It KAUTH_DEVICE_RND_GETPRIV
1037 Check if privileged settings and information can be retrieved.
1038 .It KAUTH_DEVICE_RND_SETPRIV
1039 Check if privileged settings can be changed.
1041 .Ss Credentials Scope
1042 The credentials scope,
1043 .Dq org.netbsd.kauth.cred ,
1044 is a special scope used internally by the
1046 framework to provide hooking to credential-related operations.
1050 scope, allowing hooking operations such as initialization of new credentials,
1051 credential inheritance during a fork, and copying and freeing of credentials.
1052 The main purpose for this scope is to give a security model a way to control
1053 the aforementioned operations, especially in cases where the credentials
1054 hold security model-private data.
1056 Notifications are made using the following function, which is internal to
1059 .Ft int Fn kauth_cred_hook "kauth_cred_t cred" "kauth_action_t action" \
1060 "void *arg0" "void *arg1"
1062 With the following actions:
1063 .Bl -tag -width compact
1064 .It Dv KAUTH_CRED_COPY
1065 The credentials are being copied.
1067 are the credentials of the lwp context doing the copy, and
1077 credentials, respectively.
1078 .It Dv KAUTH_CRED_FORK
1079 The credentials are being inherited from a parent to a child process during a
1083 are the credentials of the lwp context doing the fork, and
1089 of the parent and child processes, respectively.
1090 .It Dv KAUTH_CRED_FREE
1094 .It Dv KAUTH_CRED_INIT
1097 are being initialized.
1100 Since this is a notify-only scope, all listeners are required to return
1101 .Dv KAUTH_RESULT_ALLOW .
1102 .Ss Credentials Accessors and Mutators
1104 has a variety of accessor and mutator routines to handle
1108 The following routines can be used to access and modify the user- and
1111 .Bl -tag -width compact
1112 .It Ft uid_t Fn kauth_cred_getuid "kauth_cred_t cred"
1113 Returns the real user-id from
1115 .It Ft uid_t Fn kauth_cred_geteuid "kauth_cred_t cred"
1116 Returns the effective user-id from
1118 .It Ft uid_t Fn kauth_cred_getsvuid "kauth_cred_t cred"
1119 Returns the saved user-id from
1121 .It Ft void Fn kauth_cred_setuid "kauth_cred_t cred" "uid_t uid"
1122 Sets the real user-id in
1126 .It Ft void Fn kauth_cred_seteuid "kauth_cred_t cred" "uid_t uid"
1127 Sets the effective user-id in
1131 .It Ft void Fn kauth_cred_setsvuid "kauth_cred_t cred" "uid_t uid"
1132 Sets the saved user-id in
1136 .It Ft gid_t Fn kauth_cred_getgid "kauth_cred_t cred"
1137 Returns the real group-id from
1139 .It Ft gid_t Fn kauth_cred_getegid "kauth_cred_t cred"
1140 Returns the effective group-id from
1142 .It Ft gid_t Fn kauth_cred_getsvgid "kauth_cred_t cred"
1143 Returns the saved group-id from
1145 .It Ft void Fn kauth_cred_setgid "kauth_cred_t cred" "gid_t gid"
1146 Sets the real group-id in
1150 .It Ft void Fn kauth_cred_setegid "kauth_cred_t cred" "gid_t gid"
1151 Sets the effective group-id in
1155 .It Ft void Fn kauth_cred_setsvgid "kauth_cred_t cred" "gid_t gid"
1156 Sets the saved group-id in
1160 .It Ft u_int Fn kauth_cred_getrefcnt "kauth_cred_t cred"
1161 Return the reference count for
1165 The following routines can be used to access and modify the group
1168 .Bl -tag -width compact
1169 .It Ft int Fn kauth_cred_ismember_gid "kauth_cred_t cred" "gid_t gid" \
1171 Checks if the group-id
1173 is a member in the group list of
1178 will be set to one, otherwise, to zero.
1180 The return value is an error code, or zero for success.
1181 .It Ft u_int Fn kauth_cred_ngroups "kauth_cred_t cred"
1182 Return the number of groups in the group list of
1184 .It Ft gid_t Fn kauth_cred_group "kauth_cred_t cred" "u_int idx"
1185 Return the group-id of the group at index
1187 in the group list of
1189 .It Ft int Fn kauth_cred_setgroups "kauth_cred_t cred" "const gid_t *groups" \
1190 "size_t ngroups" "uid_t gmuid" "enum uio_seg seg"
1193 groups from array pointed to by
1195 to the group list in
1197 adjusting the number of groups in
1207 is a user or kernel space address.
1209 Any groups remaining will be set to an invalid value.
1212 is unused for now, and to maintain interface compatibility with the Darwin
1215 The return value is an error code, or zero for success.
1216 .It Ft int Fn kauth_cred_getgroups "kauth_cred_t cred" "gid_t *groups" \
1217 "size_t ngroups" "enum uio_seg seg"
1220 groups from the group list in
1222 to the buffer pointed to by
1231 is a user or kernel space address.
1233 The return value is an error code, or zero for success.
1235 .Ss Credential Private Data
1237 provides an interface to allow attaching security-model private data to
1240 The use of this interface has two parts that can be divided to direct and
1241 indirect control of the private-data.
1242 Directly controlling the private data is done by using the below routines,
1243 while the indirect control is often dictated by events such as process
1244 fork, and is handled by listening on the credentials scope (see above).
1246 Attaching private data to credentials works by registering a key to serve
1247 as a unique identifier, distinguishing various sets of private data that
1248 may be associated with the credentials.
1249 Registering, and deregistering, a key is done by using these routines:
1251 .Bl -tag -width compact
1252 .It Ft int Fn kauth_register_key "const char *name" "kauth_key_t *keyp"
1253 Register new key for private data for
1255 (usually, the security model name).
1257 will be used to return the key to be used in further calls.
1259 The function returns 0 on success and an error code (see
1262 .It Ft int Fn kauth_deregister_key "kauth_key_t key"
1263 Deregister private data key
1267 Once registered, private data may be manipulated by the following routines:
1268 .Bl -tag -width compact
1269 .It Ft void Fn kauth_cred_setdata "kauth_cred_t cred" "kauth_key_t key" \
1271 Set private data for
1277 .It Ft void * Fn kauth_cred_getdata "kauth_cred_t cred" "kauth_key_t key"
1278 Retrieve private data for
1284 Note that it is required to use the above routines every time the private
1285 data is changed, i.e., using
1286 .Fn kauth_cred_getdata
1287 and later modifying the private data should be accompanied by a call to
1288 .Fn kauth_cred_setdata
1292 .Ss Credential Inheritance and Reference Counting
1294 provides an interface for handling shared credentials.
1298 is first allocated, its reference count is set to 1.
1299 However, with time, its reference count can grow as more objects (processes,
1300 LWPs, files, etc.) reference it.
1302 The following routines are available for managing credentials reference
1304 .Bl -tag -width compact
1305 .It Ft void Fn kauth_cred_hold "kauth_cred_t cred"
1306 Increases reference count to
1309 .It Ft void Fn kauth_cred_free "kauth_cred_t cred"
1310 Decreases the reference count to
1314 If the reference count dropped to zero, the memory used by
1319 Credential inheritance happens during a
1321 and is handled by the following function:
1323 .Ft void Fn kauth_proc_fork "struct proc *parent" "struct proc *child"
1325 When called, it references the parent's credentials from the child,
1326 and calls the credentials scope's hook with the
1328 action to allow security model-specific handling of the inheritance
1330 .Ss Credentials Memory Management
1331 Data-structures for credentials, listeners, and scopes are allocated from
1332 memory pools managed by the
1338 objects have their own memory management routines:
1339 .Bl -tag -width compact
1340 .It Ft kauth_cred_t Fn kauth_cred_alloc "void"
1343 initializes its lock, and sets its reference count to one.
1345 .Ss Conversion Routines
1346 Sometimes it might be necessary to convert a
1348 to userland's view of credentials, a
1352 The following routines are available for these cases:
1353 .Bl -tag -width compact
1354 .It Ft void Fn kauth_uucred_to_cred "kauth_cred_t cred" "const struct uucred *uucred"
1355 Convert userland's view of credentials to a
1358 This includes effective user- and group-ids, a number of groups, and a group
1360 The reference count is set to one.
1364 will try to copy as many groups as can be held inside a
1366 .It Ft void Fn kauth_cred_to_uucred "struct uucred *uucred" "const kauth_cred_t cred"
1369 to userland's view of credentials.
1371 This includes effective user- and group-ids, a number of groups, and a group
1376 will try to copy as many groups as can be held inside a
1378 .It Ft int Fn kauth_cred_uucmp "kauth_cred_t cred" "struct uucred *uucred"
1381 with the userland credentials in
1384 Common values that will be compared are effective user- and group-ids, and
1387 .Ss Miscellaneous Routines
1388 Other routines provided by
1391 .Bl -tag -width compact
1392 .It Ft void Fn kauth_cred_clone "kauth_cred_t cred1" "kauth_cred_t cred2"
1393 Clone credentials from
1397 except for the lock and reference count.
1399 .It Ft kauth_cred_t Fn kauth_cred_dup "kauth_cred_t cred"
1403 What this routine does is call
1404 .Fn kauth_cred_alloc
1405 followed by a call to
1406 .Fn kauth_cred_clone .
1407 .It Ft kauth_cred_t Fn kauth_cred_copy "kauth_cred_t cred"
1409 .Fn kauth_cred_dup ,
1410 except for a few differences.
1414 already has a reference count of one, it will be returned.
1417 will be allocated and the credentials from
1419 will be cloned to it.
1425 .It Ft kauth_cred_t Fn kauth_cred_get "void"
1426 Return the credentials associated with the current LWP.
1428 .Ss Scope Management
1430 provides routines to manage the creation and deletion of scopes on the
1433 Note that the built-in scopes, the
1437 scope, can't be deleted.
1438 .Bl -tag -width compact
1439 .It Ft kauth_scope_t Fn kauth_register_scope "const char *id" \
1440 "kauth_scope_callback_t cb" "void *cookie"
1441 Register a new scope on the system.
1443 is the name of the scope, usually in reverse DNS-like notation.
1445 .Dq org.netbsd.kauth.myscope .
1447 is the default listener, to which authorization requests for this scope
1448 will be dispatched to.
1450 is optional user-data that will be passed to all listeners
1451 during authorization on the scope.
1452 .It Ft void Fn kauth_deregister_scope "kauth_scope_t scope"
1455 from the scopes available on the system, and free the
1460 .Ss Listener Management
1463 are authorization callbacks that are called during an authorization
1464 request in the scope which they belong to.
1466 When an authorization request is made, all listeners associated with
1467 a scope are called to allow, deny, or defer the request.
1469 It is enough for one listener to deny the request in order for the
1470 request to be denied; but all listeners are called during an authorization
1471 process none-the-less.
1472 All listeners are required to allow the request for it to be granted,
1473 and in a case where all listeners defer the request -- leaving the decision
1474 for other listeners -- the request is denied.
1476 The following KPI is provided for the management of listeners:
1477 .Bl -tag -width compact
1478 .It Ft kauth_listener_t Fn kauth_listen_scope "const char *id" \
1479 "kauth_scope_callback_t cb" "void *cookie"
1480 Create a new listener on the scope with the id
1482 setting the default listener to
1485 is optional user-data that will be passed to the listener when called
1486 during an authorization request.
1487 .It Ft void Fn kauth_unlisten_scope "kauth_listener_t listener"
1490 from the scope which it belongs to, ensuring it won't be called again,
1492 .Ft kauth_listener_t
1498 provides no means for synchronization within listeners.
1499 It is the programmer's responsibility to make sure data used by the
1500 listener is properly locked during its use, as it can be accessed
1501 simultaneously from the same listener called multiple times.
1502 It is also the programmer's responsibility to do garbage collection after
1503 the listener, possibly freeing any allocated data it used.
1505 The common method to do the above is by having a reference count to
1507 On entry to the listener, this reference count should be raised, and
1510 During the removal of a listener, first
1511 .Fn kauth_scope_unlisten
1512 should be called to make sure the listener code will not be entered in
1514 Then, the code should wait (possibly sleeping) until the reference count
1516 When that happens, it is safe to do the final cleanup.
1518 Listeners might sleep, so no locks can be held when calling an authorization
1521 Older code had no abstraction of the security model, so most privilege
1522 checks looked like this:
1523 .Bd -literal -offset indent
1524 if (suser(cred, \*[Am]acflag) == 0)
1525 /* allow privileged operation */
1528 Using the new interface, you must ask for a specific privilege explicitly.
1529 For example, checking whether it is possible to open a socket would look
1530 something like this:
1531 .Bd -literal -offset indent
1532 if (kauth_authorize_network(cred, KAUTH_NETWORK_SOCKET,
1533 KAUTH_REQ_NETWORK_SOCKET_OPEN, PF_INET, SOCK_STREAM,
1535 /* allow opening the socket */
1540 implications were also integrated into the
1542 framework so you don't have to note anything special in the call to the
1543 authorization wrapper, but rather just have to make sure the security
1544 model handles the request as you expect it to.
1546 To do that you can just
1548 in the relevant security model directory and have a look at the code.
1552 provides a large set of both detailed and more or less generic requests,
1553 it might be needed eventually to introduce more scopes, actions, or
1556 Adding a new scope should happen only when an entire subsystem is
1557 introduced and it is assumed other parts of the kernel may want to
1558 interfere with its inner-workings.
1559 When a subsystem that has the potential of impacting the security
1560 of the system is introduced, existing security modules must be updated
1561 to also handle actions on the newly added scope.
1563 New actions should be added when sets of operations not covered at all
1564 belong in an already existing scope.
1566 Requests (or sub-actions) can be added as subsets of existing actions
1567 when an operation that belongs in an already covered area is introduced.
1569 Note that all additions should include updates to this manual, the
1570 security models shipped with
1572 and the example skeleton security model.
1576 The kernel authorization framework first appeared in Mac OS X 10.4.
1578 The kernel authorization framework in
1582 and is a clean-room implementation based on Apple TN2127, available at
1583 http://developer.apple.com/technotes/tn2005/tn2127.html
1589 is still under active development, it is likely that the ABI, and possibly the
1590 API, will differ between
1593 Developers are to take notice of this fact in order to avoid building code
1594 that expects one version of the ABI and running it in a system with a different
1597 .An Elad Efrat Aq elad@NetBSD.org
1598 implemented the kernel authorization framework in
1601 .An Jason R. Thorpe Aq thorpej@NetBSD.org
1602 provided guidance and answered questions about the Darwin implementation.
1606 framework is dedicated to Brian Mitchell, one of the most talented people
1608 Thanks for everything.