1*0f335007Sad.\" $NetBSD: kauth.9,v 1.114 2023/10/04 22:17:10 ad Exp $ 21674cef5Selad.\" 31674cef5Selad.\" Copyright (c) 2005, 2006 Elad Efrat <elad@NetBSD.org> 41674cef5Selad.\" All rights reserved. 51674cef5Selad.\" 61674cef5Selad.\" Redistribution and use in source and binary forms, with or without 71674cef5Selad.\" modification, are permitted provided that the following conditions 81674cef5Selad.\" are met: 91674cef5Selad.\" 1. Redistributions of source code must retain the above copyright 101674cef5Selad.\" notice, this list of conditions and the following disclaimer. 111674cef5Selad.\" 2. Redistributions in binary form must reproduce the above copyright 121674cef5Selad.\" notice, this list of conditions and the following disclaimer in the 131674cef5Selad.\" documentation and/or other materials provided with the distribution. 14d2e4f716Selad.\" 3. The name of the author may not be used to endorse or promote products 151674cef5Selad.\" derived from this software without specific prior written permission. 161674cef5Selad.\" 171674cef5Selad.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 181674cef5Selad.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 191674cef5Selad.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 201674cef5Selad.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 211674cef5Selad.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 221674cef5Selad.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 231674cef5Selad.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 241674cef5Selad.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 251674cef5Selad.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 261674cef5Selad.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 271674cef5Selad.\" 28*0f335007Sad.Dd October 4, 2023 291674cef5Selad.Dt KAUTH 9 301674cef5Selad.Os 311674cef5Selad.Sh NAME 321674cef5Selad.Nm kauth 331674cef5Selad.Nd kernel authorization framework 341674cef5Selad.Sh SYNOPSIS 351674cef5Selad.In sys/kauth.h 361674cef5Selad.Sh DESCRIPTION 371674cef5Selad.Nm , 381674cef5Selador kernel authorization, is the subsystem managing all authorization requests 391674cef5Seladinside the kernel. 401674cef5SeladIt manages user credentials and rights, and can be used 411674cef5Seladto implement a system-wide security policy. 421674cef5SeladIt allows external modules to plug-in the authorization process. 431674cef5Selad.Pp 441674cef5Selad.Nm 451674cef5Seladintroduces some new concepts, namely 461674cef5Selad.Dq scopes 471674cef5Seladand 481674cef5Selad.Dq listeners , 491674cef5Seladwhich will be detailed together with other useful information for kernel 501674cef5Seladdevelopers in this document. 51620ee93fSelad.Ss Types 521674cef5SeladSome 531674cef5Selad.Nm 541674cef5Seladtypes include the following: 55925e8d03Sjoerg.Bl -tag -width kauth_listener_t 561674cef5Selad.It kauth_cred_t 571674cef5SeladRepresenting credentials that can be associated with an object. 581674cef5SeladIncludes user- and group-ids (real, effective, and save) as well as group 591674cef5Seladmembership information. 601674cef5Selad.It kauth_scope_t 611674cef5SeladDescribes a scope. 621674cef5Selad.It kauth_listener_t 631674cef5SeladDescribes a listener. 641674cef5Selad.El 651674cef5Selad.Ss Terminology 661674cef5Selad.Nm 671674cef5Seladoperates in various 681674cef5Selad.Dq scopes , 691674cef5Seladeach scope holding a group of 701674cef5Selad.Dq listeners . 711674cef5Selad.Pp 721674cef5SeladEach listener works as a callback for when an authorization request within the 731674cef5Seladscope is made. 741674cef5SeladWhen such a request is made, all listeners on the scope are passed common 751674cef5Seladinformation such as the credentials of the request context, an identifier for 761674cef5Seladthe requested operation, and possibly other information as well. 771674cef5Selad.Pp 781674cef5SeladEvery listener examines the passed information and returns its decision 791674cef5Seladregarding the requested operation. 8028ecaa21SjymIt can either return: 811674cef5Selad.Pp 8228ecaa21Sjym.Bl -tag -width KAUTH_RESULT_ALLOW -compact 8328ecaa21Sjym.It Dv KAUTH_RESULT_ALLOW 8428ecaa21SjymThe listener allows the operation. 8528ecaa21Sjym.It Dv KAUTH_RESULT_DENY 8628ecaa21SjymThe listener denies the operation. 8728ecaa21Sjym.It Dv KAUTH_RESULT_DEFER 8828ecaa21SjymThe listener defers the decision to other listeners. 8928ecaa21Sjym.El 9028ecaa21Sjym.Pp 9128ecaa21SjymFor an operation to be allowed, at least one listener has to return 9228ecaa21Sjym.Dv KAUTH_RESULT_ALLOW 9328ecaa21Sjymwhile no other listener returned 9428ecaa21Sjym.Dv KAUTH_RESULT_DENY . 951674cef5Selad.Pp 961674cef5SeladScopes manage listeners that operate in the same aspect of the system. 971674cef5Selad.Ss Kernel Programming Interface 981674cef5Selad.Nm 991674cef5Seladexports a KPI that allows developers both of 1001674cef5Selad.Nx 1011674cef5Seladand third-party products to authorize requests, access and modify credentials, 1021674cef5Seladcreate and remove scopes and listeners, and perform other miscellaneous operations on 1031674cef5Seladcredentials. 1041674cef5Selad.Ss Authorization Requests 1051674cef5Selad.Nm 1061674cef5Seladprovides a single authorization request routine, which all authorization 1071674cef5Seladrequests go through. 1081674cef5SeladThis routine dispatches the request to the listeners of the appropriate scope, 1091674cef5Seladtogether with four optional user-data variables, and returns the augmented 1101674cef5Seladresult. 1111674cef5Selad.Pp 1121674cef5SeladIt is declared as 1131674cef5Selad.Pp 1141674cef5Selad.Ft int Fn kauth_authorize_action "kauth_scope_t scope" "kauth_cred_t cred" \ 1151674cef5Selad"kauth_action_t op" "void *arg0" "void *arg1" "void *arg2" "void *arg3" 1161674cef5Selad.Pp 11728ecaa21SjymAn authorization request can return one of two possible values: 11828ecaa21Sjym.Bl -tag -width ".It Dv 0 Po zero Pc" -compact 11928ecaa21Sjym.It Dv 0 Po zero Pc 12028ecaa21Sjymindicates success; operation is allowed. 12128ecaa21Sjym.It Dv EPERM 122156fd028Swizindicates failure; operation is denied. 123156fd028SwizSee 12428ecaa21Sjym.Xr errno 2 . 12528ecaa21Sjym.El 1261674cef5Selad.Pp 1271674cef5SeladEach scope has its own authorization wrapper, to make it easy to call from various 1281674cef5Seladplaces by eliminating the need to specify the scope and/or cast values. 1291674cef5SeladThe authorization wrappers are detailed in each scope's section. 130c2e4f788Selad.Pp 131c2e4f788Selad.Fn kauth_authorize_action 132c2e4f788Seladhas several special cases, when it will always allow the request. 133c2e4f788SeladThese are for when the request is issued by the kernel itself (indicated by the 134c2e4f788Seladcredentials being either 135c2e4f788Selad.Dv NOCRED 136c2e4f788Selador 137c2e4f788Selad.Dv FSCRED ) , 138c2e4f788Selador when there was no definitive decision from any of the listeners (i.e., it 139c2e4f788Seladwas not explicitly allowed or denied) and no security model was loaded. 1401674cef5Selad.Ss Generic Scope 1411674cef5SeladThe generic scope, 1421674cef5Selad.Dq org.netbsd.kauth.generic , 1431674cef5Seladmanages generic authorization requests in the kernel. 1441674cef5Selad.Pp 1451674cef5SeladThe authorization wrapper for this scope is declared as 1461674cef5Selad.Pp 1471674cef5Selad.Ft int Fn kauth_authorize_generic "kauth_cred_t cred" "kauth_action_t op" \ 1481674cef5Selad"void *arg0" 1491674cef5Selad.Pp 1501674cef5SeladThe following operations are available for this scope: 151925e8d03Sjoerg.Bl -tag -width compact 1521674cef5Selad.It Dv KAUTH_GENERIC_ISSUSER 1531674cef5SeladChecks whether the credentials belong to the super-user. 1541674cef5Selad.Pp 155620ee93fSeladUsing this request is strongly discouraged and should only be done as a 156620ee93fSeladtemporary place-holder, as it is breaking the separation between the 157620ee93fSeladinterface for authorization requests from the back-end implementation. 1581674cef5Selad.El 159620ee93fSelad.Ss System Scope 160620ee93fSeladThe system scope, 161620ee93fSelad.Dq org.netbsd.kauth.system , 162620ee93fSeladmanages authorization requests affecting the entire system. 163620ee93fSelad.Pp 164620ee93fSeladThe authorization wrapper for this scope is declared as 165620ee93fSelad.Pp 166620ee93fSelad.Ft int Fn kauth_authorize_system "kauth_cred_t cred" \ 167620ee93fSelad"kauth_action_t op" "enum kauth_system_req req" "void *arg1" "void *arg2" \ 168620ee93fSelad"void *arg3" 169620ee93fSelad.Pp 170620ee93fSeladThe following requests are available for this scope: 171925e8d03Sjoerg.Bl -tag -width compact 172620ee93fSelad.It Dv KAUTH_SYSTEM_ACCOUNTING 173620ee93fSeladCheck if enabling/disabling accounting allowed. 174620ee93fSelad.It Dv KAUTH_SYSTEM_CHROOT 17583a5239bSelad.Ar req 176620ee93fSeladcan be any of the following: 177925e8d03Sjoerg.Bl -tag -width compact 178620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_CHROOT_CHROOT 179620ee93fSeladCheck if calling 180620ee93fSelad.Xr chroot 2 181620ee93fSeladis allowed. 182620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_CHROOT_FCHROOT 183620ee93fSeladCheck if calling 184620ee93fSelad.Xr fchroot 2 185620ee93fSeladis allowed. 186620ee93fSelad.El 187cd23f363Selad.It Dv KAUTH_SYSTEM_CPU 188cd23f363SeladCheck CPU-manipulation access. 189cd23f363Selad.Pp 190cd23f363Selad.Ar req 191cd23f363Seladcan be any of the following: 192925e8d03Sjoerg.Bl -tag -width compact 193cd23f363Selad.It Dv KAUTH_REQ_SYSTEM_CPU_SETSTATE 194cd23f363SeladSet CPU state, including setting it online or offline. 195cd23f363Selad.El 196620ee93fSelad.It Dv KAUTH_SYSTEM_DEBUG 197620ee93fSeladThis request concentrates several debugging-related operations. 1980c9d8d15Selad.It Dv KAUTH_SYSTEM_DEVMAPPER 1990c9d8d15SeladCheck if operations on the device mapper 2000c9d8d15Selad.Xr dm 4 2010c9d8d15Seladdevice are allowed. 202620ee93fSelad.It Dv KAUTH_SYSTEM_FILEHANDLE 203620ee93fSeladCheck if file handle operations allowed. 2040c9d8d15Selad.It Dv KAUTH_SYSTEM_FS_EXTATTR 2050c9d8d15SeladCheck if starting, stopping, enabling, or disabling extended attributes 2060c9d8d15Seladis allowed. 2070c9d8d15Selad.Ar arg1 2080c9d8d15Seladis a 2090c9d8d15Selad.Ft struct mount * 2100c9d8d15Seladof the mount-point on which the operation is performed. 2110c9d8d15Selad.It Dv KAUTH_SYSTEM_FS_SNAPSHOT 212948a1519SwizCheck if setting up a file system snapshot is allowed. 2130c9d8d15Selad.Ar arg1 2140c9d8d15Seladis a 2150c9d8d15Selad.Ft struct mount * 2160c9d8d15Seladof the mount-point of which the snapshot is taken, and 2170c9d8d15Selad.Ar arg2 2180c9d8d15Seladis a 2190c9d8d15Selad.Ft struct vnode * 2200c9d8d15Seladof the vnode where the snapshot is expected to be. 2219e9887ccSelad.It Dv KAUTH_SYSTEM_FS_QUOTA 222948a1519SwizCheck if file system quota operations are allowed. 2239e9887ccSelad.Pp 2249e9887ccSelad.Ar arg1 2259e9887ccSeladis a 2269e9887ccSelad.Ft struct mount * 227948a1519Swizdescribing the file system mount in question. 2289e9887ccSelad.Ar req 2299e9887ccSeladcan be one of the following: 2309e9887ccSelad.Bl -tag -width compact 2319e9887ccSelad.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_GET 2329e9887ccSeladCheck if retrieving quota information is allowed. 2339e9887ccSelad.Pp 2349e9887ccSelad.Ar arg2 2359e9887ccSeladis a 2369e9887ccSelad.Ft uid_t 2379e9887ccSeladwith the user-id of the user whose quota information is to be retrieved. 2389e9887ccSelad.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF 2399e9887ccSeladCheck if turning quota on/off is allowed. 2409e9887ccSelad.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE 2419e9887ccSeladCheck if managing the quota by setting the quota/quota use is allowed. 2429e9887ccSelad.Pp 2439e9887ccSelad.Ar arg2 2449e9887ccSeladis a 2459e9887ccSelad.Ft uid_t 2469e9887ccSeladwith the user-id of the user whose quota/quota use is to be set. 2479e9887ccSelad.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_NOLIMIT 24877da6fadSwizCheck if bypassing the quota (not enforcing it) is allowed. 2499e9887ccSelad.El 2509e9887ccSelad.It Dv KAUTH_SYSTEM_FS_RESERVEDSPACE 251948a1519SwizCheck if using the file system reserved space is allowed. 2520c9d8d15Selad.It Dv KAUTH_SYSTEM_LFS 2530c9d8d15SeladCheck if LFS-related operations are allowed. 2540c9d8d15Selad.Ar req 2550c9d8d15Seladcan be one of the following: 2560c9d8d15Selad.Bl -tag -width compact 2570c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_LFS_MARKV 2580c9d8d15SeladCheck if calling 2590c9d8d15Selad.Xr lfs_markv 2 2600c9d8d15Seladis allowed. 2610c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_LFS_BMAPV 2620c9d8d15SeladCheck if calling 2630c9d8d15Selad.Xr lfs_bmapv 2 2640c9d8d15Seladis allowed. 2650c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_LFS_SEGCLEAN 2660c9d8d15SeladCheck if calling 2670c9d8d15Selad.Xr lfs_segclean 2 2680c9d8d15Seladis allowed. 2690c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_LFS_SEGWAIT 2700c9d8d15SeladCheck if calling 2710c9d8d15Selad.Xr lfs_segwait 2 2720c9d8d15Seladis allowed. 2730c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_LFS_FCNTL 2740c9d8d15SeladCheck if operations on LFS through 2750c9d8d15Selad.Xr fcntl 2 2760c9d8d15Seladare allowed. 2770c9d8d15Selad.El 2780c9d8d15Selad.It Dv KAUTH_SYSTEM_MAP_VA_ZERO 2790c9d8d15SeladCheck if changing the status of memory mapping of virtual address zero 2800c9d8d15Seladis allowed. 2810efea177Sad.It Dv KAUTH_SYSTEM_MODULE 2820efea177SadCheck if a module request is allowed. 283620ee93fSelad.Pp 28483a5239bSelad.Ar arg1 285620ee93fSeladis the command. 286620ee93fSelad.It Dv KAUTH_SYSTEM_MKNOD 287620ee93fSeladCheck if creating devices is allowed. 288a13160f4Selad.It Dv KAUTH_SYSTEM_MOUNT 289a13160f4SeladCheck if mount-related operations are allowed. 290a13160f4Selad.Pp 291a13160f4Selad.Ar req 292a13160f4Seladcan be any of the following: 293925e8d03Sjoerg.Bl -tag -width compact 2940c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_MOUNT_DEVICE 2950c9d8d15SeladCheck if mounting a device is allowed. 2960c9d8d15Selad.Ar arg1 2970c9d8d15Seladis a 2980c9d8d15Selad.Ft vnode_t * 2990c9d8d15Seladof the device, 3000c9d8d15Selad.Ar arg2 3010c9d8d15Seladis a 3020c9d8d15Selad.Ft struct mount * 3030c9d8d15Seladwith the mount-point, and 3040c9d8d15Selad.Ar arg3 3050c9d8d15Seladis a 3060c9d8d15Selad.Ft mode_t 3070c9d8d15Seladwith the desired access mode. 308a13160f4Selad.It Dv KAUTH_REQ_SYSTEM_MOUNT_GET 309a13160f4SeladCheck if retrieving information about a mount is allowed. 310a13160f4Selad.Ar arg1 311a13160f4Seladis a 312a13160f4Selad.Ft struct mount * 313a13160f4Seladwith the mount structure in question, 314a13160f4Selad.Ar arg2 315a13160f4Seladis a 316a13160f4Selad.Ft void * 317948a1519Swizwith file system specific data, if any. 318a13160f4Selad.It Dv KAUTH_REQ_SYSTEM_MOUNT_NEW 319948a1519SwizCheck if mounting a new file system is allowed. 320a13160f4Selad.Pp 321a13160f4Selad.Ar arg1 322a13160f4Seladis the 323a13160f4Selad.Ft struct vnode * 324948a1519Swizon which the file system is to be mounted, 325a13160f4Selad.Ar arg2 326a13160f4Seladis an 327a13160f4Selad.Ft int 328a13160f4Seladwith the mount flags, and 329a13160f4Selad.Ar arg3 330a13160f4Seladis a 331a13160f4Selad.Ft void * 332948a1519Swizwith file system specific data, if any. 333a13160f4Selad.It Dv KAUTH_REQ_SYSTEM_MOUNT_UNMOUNT 334948a1519SwizChecks if unmounting a file system is allowed. 335a13160f4Selad.Pp 336a13160f4Selad.Ar arg1 337a13160f4Seladis a 338a13160f4Selad.Ft struct mount * 339a13160f4Seladwith the mount in question. 340a13160f4Selad.It Dv KAUTH_REQ_SYSTEM_MOUNT_UPDATE 341a13160f4SeladChecks if updating an existing mount is allowed. 342a13160f4Selad.Pp 343a13160f4Selad.Ar arg1 344a13160f4Seladis the 345a13160f4Selad.Ft struct mount * 346a13160f4Seladof the existing mount, 347a13160f4Selad.Ar arg2 348a13160f4Seladis an 349a13160f4Selad.Ft int 350a13160f4Seladwith the new mount flags, and 351a13160f4Selad.Ar arg3 352a13160f4Seladis a 353a13160f4Selad.Ft void * 354948a1519Swizwith file system specific data, if any. 3550c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_MOUNT_UMAP 356948a1519SwizCheck if mounting the user and group id remapping file system. 3570c9d8d15SeladSee 3580c9d8d15Selad.Xr mount_umap 8 . 359a13160f4Selad.El 3600c9d8d15Selad.It Dv KAUTH_SYSTEM_MQUEUE 3610c9d8d15SeladCheck if bypassing permissions on a message queue object are allowed. 3620c9d8d15Selad.Ar arg1 3630c9d8d15Seladis a 3640c9d8d15Selad.Ft mqueue_t * 3650c9d8d15Seladdescribing the message queue. 366fb37bad4Selad.It Dv KAUTH_SYSTEM_PSET 367fb37bad4SeladCheck processor-set manipulation. 368fb37bad4Selad.Pp 369fb37bad4Selad.Ar req 370fb37bad4Seladcan be any of the following: 371925e8d03Sjoerg.Bl -tag -width compact 372fb37bad4Selad.It Dv KAUTH_REQ_SYSTEM_PSET_ASSIGN 373fb37bad4SeladChange processor-set processor assignment. 374fb37bad4Selad.It Dv KAUTH_REQ_SYSTEM_PSET_BIND 375fb37bad4SeladBind an LWP to a processor-set. 376fb37bad4Selad.It Dv KAUTH_REQ_SYSTEM_PSET_CREATE 377fb37bad4SeladCreate a processor-set. 378fb37bad4Selad.It Dv KAUTH_REQ_SYSTEM_PSET_DESTROY 379fb37bad4SeladDestroy a processor-set. 380fb37bad4Selad.El 381620ee93fSelad.It Dv KAUTH_SYSTEM_REBOOT 382620ee93fSeladCheck if rebooting is allowed. 383620ee93fSelad.It Dv KAUTH_SYSTEM_SETIDCORE 384620ee93fSeladCheck if changing coredump settings for set-id processes is allowed. 3850c9d8d15Selad.It Dv KAUTH_SYSTEM_SEMAPHORE 3860c9d8d15SeladCheck if access to a kernel semaphore is allowed. 3870c9d8d15Selad.Ar arg1 3880c9d8d15Seladis a 3890c9d8d15Selad.Ft ksem_t * 3900c9d8d15Seladdescribing the semaphore. 391620ee93fSelad.It Dv KAUTH_SYSTEM_SWAPCTL 392620ee93fSeladCheck if privileged 393620ee93fSelad.Xr swapctl 2 394620ee93fSeladrequests are allowed. 395620ee93fSelad.It Dv KAUTH_SYSTEM_SYSCTL 396620ee93fSeladThis requests operations related to 397620ee93fSelad.Xr sysctl 9 . 39883a5239bSelad.Ar req 399620ee93fSeladindicates the specific request and can be one of the following: 400925e8d03Sjoerg.Bl -tag -width compact 401620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_SYSCTL_ADD 402620ee93fSeladCheck if adding a 403620ee93fSelad.Xr sysctl 9 404620ee93fSeladnode is allowed. 405620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_SYSCTL_DELETE 406620ee93fSeladCheck if deleting a 407620ee93fSelad.Xr sysctl 9 408620ee93fSeladnode is allowed. 409620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_SYSCTL_DESC 410620ee93fSeladCheck if adding description to a 411620ee93fSelad.Xr sysctl 9 412620ee93fSeladnode is allowed. 4132d1c9683Selad.It Dv KAUTH_REQ_SYSTEM_SYSCTL_MODIFY 4142d1c9683SeladCheck if modifying a 4152d1c9683Selad.Xr sysctl 9 4162d1c9683Seladnode variable that doesn't have a custom sysctl helper function is allowed. 4172d1c9683Selad.Pp 4182d1c9683SeladThis request might be deprecated in the future. 419620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_SYSCTL_PRVT 420620ee93fSeladCheck if accessing private 421620ee93fSelad.Xr sysctl 9 422620ee93fSeladnodes is allowed. 423620ee93fSelad.El 4240c9d8d15Selad.It Dv KAUTH_SYSTEM_SYSVIPC 4250c9d8d15SeladCheck SysV IPC related operations. 4260c9d8d15Selad.Ar req 4270c9d8d15Seladindicates the specific request and can be one of the following: 4280c9d8d15Selad.Bl -tag -width compact 4290c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_BYPASS 4300c9d8d15SeladCheck if bypassing a SysV IPC object's permissions is allowed. 4310c9d8d15Selad.Ar arg1 4320c9d8d15Seladis a 4330c9d8d15Selad.Ft struct ipc_perm * 4340c9d8d15Seladwith the object's permissions and 4350c9d8d15Selad.Ar arg2 4360c9d8d15Seladis a 4370c9d8d15Selad.Ft mode_t 4380c9d8d15Seladindicating the requested access mode. 4390c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_SHM_LOCK 4400c9d8d15SeladCheck if shared memory locking is allowed. 4410c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_SHM_UNLOCK 4420c9d8d15SeladCheck if shared memory unlocking is allowed. 4430c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_MSGQ_OVERSIZE 4440c9d8d15SeladCheck if oversizing a message queue is allowed. 4450c9d8d15Selad.Ar arg1 4460c9d8d15Seladis a 4470c9d8d15Selad.Ft msglen_t 4480c9d8d15Seladindicating the size of the message buffer, and 4490c9d8d15Selad.Ar arg2 4500c9d8d15Seladis a 4510c9d8d15Selad.Ft msglen_t 4520c9d8d15Seladindicating the size of the message queue. 4530c9d8d15Selad.El 454620ee93fSelad.It Dv KAUTH_SYSTEM_TIME 455620ee93fSeladThis request groups time-related operations. 45683a5239bSelad.Ar req 45783a5239bSeladcan be any of the following: 458925e8d03Sjoerg.Bl -tag -width compact 459620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_TIME_ADJTIME 460620ee93fSeladCheck if changing the time using 461620ee93fSelad.Xr adjtime 2 462620ee93fSeladis allowed. 463620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_TIME_NTPADJTIME 464620ee93fSeladCheck if setting the time using 465620ee93fSelad.Xr ntp_adjtime 2 466620ee93fSeladis allowed. 467620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_TIME_SYSTEM 468620ee93fSeladCheck if changing the time (usually via 469620ee93fSelad.Xr settimeofday 2 ) 470620ee93fSeladis allowed. 471abb7851fSelad.Pp 472abb7851fSelad.Ar arg1 473abb7851fSeladis a 474abb7851fSelad.Ft struct timespec * 475abb7851fSeladwith the new time, 476abb7851fSelad.Ar arg2 477abb7851fSeladis a 478abb7851fSelad.Ft struct timeval * 479abb7851fSeladwith the delta from the current time, 480abb7851fSelad.Ar arg3 481abb7851fSeladis a 482abb7851fSelad.Ft bool 48377da6fadSwizindicating whether the caller is a device context (e.g. 484abb7851fSelad.Pa /dev/clockctl ) 485abb7851fSelador not. 486620ee93fSelad.It Dv KAUTH_REQ_SYSTEM_TIME_RTCOFFSET 487620ee93fSeladCheck if changing the RTC offset is allowed. 48818558073Selad.It Dv KAUTH_REQ_SYSTEM_TIME_TIMECOUNTERS 48918558073SeladCheck if manipulating timecounters is allowed. 490620ee93fSelad.El 4910c9d8d15Selad.It Dv KAUTH_SYSTEM_VERIEXEC 4920c9d8d15SeladCheck if operations on the 4930c9d8d15Selad.Xr veriexec 8 4940c9d8d15Seladsubsystem are allowed. 4950c9d8d15Selad.Ar req 4960c9d8d15Seladcan be one of the following: 4970c9d8d15Selad.Bl -tag -width compact 4980c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_VERIEXEC_ACCESS 4990c9d8d15SeladCheck if access to the 5000c9d8d15Selad.Xr veriexec 8 5010c9d8d15Seladsubsystem is allowed. 5020c9d8d15Selad.It Dv KAUTH_REQ_SYSTEM_VERIEXEC_MODIFY 5030c9d8d15SeladCheck if modifications to the state of 5040c9d8d15Selad.Xr veriexec 8 5050c9d8d15Seladare allowed. 5060c9d8d15Selad.El 507620ee93fSelad.El 5081674cef5Selad.Ss Process Scope 5091674cef5SeladThe process scope, 5101674cef5Selad.Dq org.netbsd.kauth.process , 5111674cef5Seladmanages authorization requests related to processes in the system. 5121674cef5Selad.Pp 5131674cef5SeladThe authorization wrapper for this scope is declared as 5141674cef5Selad.Pp 5151674cef5Selad.Ft int Fn kauth_authorize_process "kauth_cred_t cred" \ 5161674cef5Selad"kauth_action_t op" "struct proc *p" "void *arg1" "void *arg2" \ 5171674cef5Selad"void *arg3" 5181674cef5Selad.Pp 5191674cef5SeladThe following operations are available for this scope: 520925e8d03Sjoerg.Bl -tag -width compact 521c27d5f30Selad.It Dv KAUTH_PROCESS_KTRACE 5228bb202afSeladChecks whether an object with one set of credentials can 5238bb202afSelad.Xr ktrace 1 5248bb202afSeladanother process 5258bb202afSelad.Ar p , 5268bb202afSeladpossibly with a different set of credentials. 527e43f626dSelad.Pp 528e43f626dSeladIf 529e43f626dSelad.Ar arg1 530e43f626dSeladis 531e43f626dSelad.Dv KAUTH_REQ_PROCESS_KTRACE_PERSISTENT , 532e43f626dSeladthis checks if persistent tracing can be done. 533e43f626dSeladPersistent tracing maintains the trace across a set-user-id/set-group-id 53414ec16f8Swiz.Xr exec 3 , 535e43f626dSeladand normally requires privileged credentials. 536c27d5f30Selad.It Dv KAUTH_PROCESS_PROCFS 5378bb202afSeladChecks whether object with passed credentials can use 5388bb202afSelad.Em procfs 5398bb202afSeladto access process 5408bb202afSelad.Ar p . 5418bb202afSelad.Pp 5428bb202afSelad.Ar arg1 5438bb202afSeladis the 5448bb202afSelad.Ft struct pfsnode * 5458bb202afSeladfor the target element in the target process, and 5468bb202afSelad.Ar arg2 5478bb202afSeladis the access type, which can be either 548c27d5f30Selad.Dv KAUTH_REQ_PROCESS_PROCFS_READ , 549c27d5f30Selad.Dv KAUTH_REQ_PROCESS_PROCFS_RW , 5508bb202afSelador 551c27d5f30Selad.Dv KAUTH_REQ_PROCESS_PROCFS_WRITE , 5528bb202afSeladindicating 553f1a69ab3Selad.Em control , 5548bb202afSelad.Em read , 5558bb202afSelad.Em read-write , 5568bb202afSelador 5578bb202afSelad.Em write 5588bb202afSeladaccess respectively. 559c27d5f30Selad.It Dv KAUTH_PROCESS_PTRACE 5608bb202afSeladChecks whether object with passed credentials can use 5618bb202afSelad.Xr ptrace 2 5628bb202afSeladto access process 5638bb202afSelad.Ar p . 5648bb202afSelad.Pp 5658bb202afSelad.Ar arg1 5668bb202afSeladis the 5678bb202afSelad.Xr ptrace 2 5688bb202afSeladcommand. 5698bb202afSelad.It Dv KAUTH_PROCESS_CANSEE 5708bb202afSeladChecks whether an object with one set of credentials can access 5718bb202afSeladinformation about another process, possibly with a different set of 5728bb202afSeladcredentials. 573c27d5f30Selad.Pp 574c27d5f30Selad.Ar arg1 575d154cf14Swizindicates the class of information being viewed, and can be either of 576c27d5f30Selad.Dv KAUTH_REQ_PROCESS_CANSEE_ARGS , 577c27d5f30Selad.Dv KAUTH_REQ_PROCESS_CANSEE_ENTRY , 578c27d5f30Selad.Dv KAUTH_REQ_PROCESS_CANSEE_ENV , 579c27d5f30Selador 580c27d5f30Selad.Dv KAUTH_REQ_PROCESS_CANSEE_OPENFILES . 581e99760e7Selad.It Dv KAUTH_PROCESS_SCHEDULER_GETAFFINITY 582e99760e7SeladChecks whether viewing the scheduler affinity is allowed. 583e99760e7Selad.It Dv KAUTH_PROCESS_SCHEDULER_SETAFFINITY 584e99760e7SeladChecks whether setting the scheduler affinity is allowed. 585bdb161bbSjym.It Dv KAUTH_PROCESS_SCHEDULER_GETPARAM 58667470a76SeladChecks whether viewing the scheduler policy and parameters is allowed. 587bdb161bbSjym.It Dv KAUTH_PROCESS_SCHEDULER_SETPARAM 58867470a76SeladChecks whether modifying the scheduler policy and parameters is allowed. 589c27d5f30Selad.It Dv KAUTH_PROCESS_SIGNAL 5901674cef5SeladChecks whether an object with one set of credentials can post signals 5911674cef5Seladto another process. 5921674cef5Selad.Pp 5930730babcSelad.Ar p 5940730babcSeladis the process the signal is being posted to, and 5951674cef5Selad.Ar arg1 5960730babcSeladis the signal number. 597620ee93fSelad.It Dv KAUTH_PROCESS_CORENAME 598c27d5f30SeladControls access to process corename. 599238ad51dSelad.Pp 600238ad51dSelad.Ar arg1 601c27d5f30Seladcan be 602c27d5f30Selad.Dv KAUTH_REQ_PROCESS_CORENAME_GET 603c27d5f30Selador 604c27d5f30Selad.Dv KAUTH_REQ_PROCESS_CORENAME_SET , 605c27d5f30Seladindicating access to read or write the process' corename, respectively. 606c27d5f30Selad.Pp 607c27d5f30SeladWhen modifying the corename, 608c27d5f30Selad.Ar arg2 609c27d5f30Seladholds the new corename to be used. 610964f16c2Selad.It Dv KAUTH_PROCESS_FORK 611964f16c2SeladChecks if the process can fork. 612964f16c2Selad.Ar arg1 613964f16c2Seladis an 614964f16c2Selad.Ft int 615964f16c2Seladindicating how many processes exist on the system at the time of the check. 616c27d5f30Selad.It Dv KAUTH_PROCESS_KEVENT_FILTER 617c27d5f30SeladChecks whether setting a process 618c27d5f30Selad.Xr kevent 2 619c27d5f30Seladfilter is allowed. 620a78693aaSelad.It Dv KAUTH_PROCESS_NICE 621620ee93fSeladChecks whether the 622620ee93fSelad.Em nice 623620ee93fSeladvalue of 624620ee93fSelad.Ar p 625620ee93fSeladcan be changed to 626a78693aaSelad.Ar arg1 . 627a78693aaSelad.It Dv KAUTH_PROCESS_RLIMIT 628c27d5f30SeladControls access to process resource limits. 629c27d5f30Selad.Pp 630c27d5f30Selad.Ar arg1 631c27d5f30Seladcan be 632c27d5f30Selad.Dv KAUTH_REQ_PROCESS_RLIMIT_GET 633c27d5f30Selador 634c27d5f30Selad.Dv KAUTH_REQ_PROCESS_RLIMIT_SET , 6350c9d8d15Seladindicating access to read or write the process' resource limits, respectively, or 6360c9d8d15Selad.Dv KAUTH_REQ_PROCESS_RLIMIT_BYPASS 6370c9d8d15Seladto check if the limit enforcement can be bypassed. 638c27d5f30Selad.Pp 639c27d5f30SeladWhen modifying resource limits, 640a78693aaSelad.Ar arg2 641c27d5f30Seladis the new value to be used and 642c27d5f30Selad.Ar arg3 643c27d5f30Seladindicates which resource limit is to be modified. 644620ee93fSelad.It Dv KAUTH_PROCESS_SETID 645620ee93fSeladCheck if changing the user- or group-ids, groups, or login-name for 646620ee93fSelad.Ar p 647620ee93fSeladis allowed. 648238ad51dSelad.It Dv KAUTH_PROCESS_STOPFLAG 649238ad51dSeladCheck if setting the stop flags for 6507713de66Swiz.Xr exec 3 , 6517713de66Swiz.Xr exit 3 , 652238ad51dSeladand 653238ad51dSelad.Xr fork 2 654238ad51dSeladis allowed. 655238ad51dSelad.Pp 656238ad51dSelad.Ar arg1 657238ad51dSeladindicates the flag, and can be either 658987a2558Swiz.Dv P_STOPEXEC , 659987a2558Swiz.Dv P_STOPEXIT , 660238ad51dSelador 661987a2558Swiz.Dv P_STOPFORK 662238ad51dSeladrespectively. 663620ee93fSelad.El 664620ee93fSelad.Ss Network Scope 665620ee93fSeladThe network scope, 666620ee93fSelad.Dq org.netbsd.kauth.network , 667620ee93fSeladmanages networking-related authorization requests in the kernel. 668620ee93fSelad.Pp 669620ee93fSeladThe authorization wrapper for this scope is declared as 670620ee93fSelad.Pp 671620ee93fSelad.Ft int Fn kauth_authorize_network "kauth_cred_t cred" "kauth_action_t op" \ 67283a5239bSelad"enum kauth_network_req req" "void *arg1" "void *arg2" "void *arg3" 673620ee93fSelad.Pp 674620ee93fSeladThe following operations are available for this scope: 675925e8d03Sjoerg.Bl -tag -width compact 676620ee93fSelad.It Dv KAUTH_NETWORK_ALTQ 677620ee93fSeladChecks if an ALTQ operation is allowed. 678620ee93fSelad.Pp 67983a5239bSelad.Ar req 680620ee93fSeladindicates the ALTQ subsystem in question, and can be one of the following: 681f831edb7Selad.Pp 682925e8d03Sjoerg.Bl -tag -compact -width compact 683620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_AFMAP 684620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_BLUE 685620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_CBQ 686620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_CDNR 687620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_CONF 688620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_FIFOQ 689620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_HFSC 690fab05f40Selad.It Dv KAUTH_REQ_NETWORK_ALTQ_JOBS 691620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_PRIQ 692620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_RED 693620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_RIO 694620ee93fSelad.It Dv KAUTH_REQ_NETWORK_ALTQ_WFQ 695620ee93fSelad.El 696620ee93fSelad.It Dv KAUTH_NETWORK_BIND 697620ee93fSeladChecks if a 698620ee93fSelad.Xr bind 2 699620ee93fSeladrequest is allowed. 700620ee93fSelad.Pp 70183a5239bSelad.Ar req 702620ee93fSeladallows to indicate the type of the request to structure listeners and callers 703620ee93fSeladeasier. 704620ee93fSeladSupported request types: 705925e8d03Sjoerg.Bl -tag -width compact 706e84ac529Selad.It Dv KAUTH_REQ_NETWORK_BIND_PORT 707e84ac529SeladChecks if binding to a non-privileged/reserved port is allowed. 708620ee93fSelad.It Dv KAUTH_REQ_NETWORK_BIND_PRIVPORT 709620ee93fSeladChecks if binding to a privileged/reserved port is allowed. 710620ee93fSelad.El 711620ee93fSelad.It Dv KAUTH_NETWORK_FIREWALL 7120b0ce0e4SwizChecks if firewall-related operations are allowed. 713620ee93fSelad.Pp 71483a5239bSelad.Ar req 715620ee93fSeladindicates the sub-action, and can be one of the following: 716925e8d03Sjoerg.Bl -tag -width compact 717620ee93fSelad.It Dv KAUTH_REQ_NETWORK_FIREWALL_FW 718620ee93fSeladModification of packet filtering rules. 719620ee93fSelad.It Dv KAUTH_REQ_NETWORK_FIREWALL_NAT 720620ee93fSeladModification of NAT rules. 721620ee93fSelad.El 722305fe091Selad.It Dv KAUTH_NETWORK_INTERFACE 723305fe091SeladChecks if network interface-related operations are allowed. 724305fe091Selad.Pp 725d53df4edSelad.Ar arg1 726ed853f63Seladis (optionally) the 727d53df4edSelad.Ft struct ifnet * 728d53df4edSeladassociated with the interface. 729d53df4edSelad.Ar arg2 730ed853f63Seladis (optionally) an 731ed853f63Selad.Ft int 732ed853f63Seladdescribing the interface-specific operation. 733ed853f63Selad.Ar arg3 734ed853f63Seladis (optionally) a pointer to the interface-specific request structure. 735305fe091Selad.Ar req 736305fe091Seladindicates the sub-action, and can be one of the following: 737925e8d03Sjoerg.Bl -tag -width compact 738305fe091Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_GET 739305fe091SeladCheck if retrieving information from the device is allowed. 740305fe091Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_GETPRIV 741305fe091SeladCheck if retrieving privileged information from the device is allowed. 742305fe091Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_SET 743305fe091SeladCheck if setting parameters on the device is allowed. 744305fe091Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_SETPRIV 745305fe091SeladCheck if setting privileged parameters on the device is allowed. 7468dfc5e0cSnjoly.It Dv KAUTH_REQ_NETWORK_INTERFACE_FIRMWARE 7470c9d8d15SeladCheck if manipulating the firmware on a network interface device is allowed. 748305fe091Selad.El 74904e6d5f9Selad.Pp 75004e6d5f9SeladNote that unless the 75104e6d5f9Selad.Ft struct ifnet * 75204e6d5f9Seladfor the interface was passed in 75304e6d5f9Selad.Ar arg1 , 75404e6d5f9Seladthere's no way to tell what structure 75504e6d5f9Selad.Ar arg3 75604e6d5f9Seladis. 7570c9d8d15Selad.It Dv KAUTH_NETWORK_INTERFACE_BRIDGE 7580c9d8d15SeladCheck if operations performed on the 7590c9d8d15Selad.Xr bridge 4 7600c9d8d15Seladnetwork interface are allowed. 7610c9d8d15Selad.Pp 7620c9d8d15Selad.Ar req 7630c9d8d15Seladcan be one of the following: 7640c9d8d15Selad.Bl -tag -width compact 7650c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_BRIDGE_GETPRIV 7660c9d8d15SeladCheck if getting privileges parameters is allowed. 7670c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_BRIDGE_SETPRIV 768948a1519SwizCheck if setting privileges parameters is allowed. 7690c9d8d15Selad.El 770b8530420Selad.It Dv KAUTH_NETWORK_INTERFACE_PPP 77117c0c1e6SeladChecks if operations performed on the 772b8530420Selad.Xr ppp 4 773b8530420Seladnetwork interface are allowed. 774b8530420Selad.Pp 775b8530420Selad.Ar req 776b8530420Seladcan be one of the following: 777b8530420Selad.Bl -tag -width compact 778b8530420Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_PPP_ADD 779b8530420SeladChecks if adding and enabling a 780b8530420Selad.Xr ppp 4 781b8530420Seladinterface to the system is allowed. 782b8530420Selad.El 7830c9d8d15Selad.It Dv KAUTH_NETWORK_INTERFACE_PVC 7840c9d8d15SeladCheck if operations performed on a PVC device (e.g. 7852dc39176Swiz.Xr en 4 ) 7860c9d8d15Seladare allowed. 7870c9d8d15Selad.Ar req 7880c9d8d15Seladcan be one of the following: 7890c9d8d15Selad.Bl -tag -width compact 7900c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_PVC_ADD 7910c9d8d15SeladCheck if adding a PVC device is allowed. 7920c9d8d15Selad.El 793b8530420Selad.It Dv KAUTH_NETWORK_INTERFACE_SLIP 79417c0c1e6SeladChecks if operations performed on the 795b8530420Selad.Xr sl 4 796b8530420Seladnetwork interface are allowed. 797b8530420Selad.Pp 798b8530420Selad.Ar req 799b8530420Seladcan be one of the following: 800b8530420Selad.Bl -tag -width compact 801b8530420Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_SLIP_ADD 802b8530420SeladChecks if adding and enabling a 803b8530420Selad.Xr sl 4 804b8530420Seladinterface to the system is allowed. 805b8530420Selad.El 806b8530420Selad.It Dv KAUTH_NETWORK_INTERFACE_STRIP 80717c0c1e6SeladChecks if operations performed on the 808b8530420Selad.Xr strip 4 809b8530420Seladnetwork interface are allowed. 810b8530420Selad.Pp 811b8530420Selad.Ar req 812b8530420Seladcan be one of the following: 813b8530420Selad.Bl -tag -width compact 814b8530420Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_STRIP_ADD 815b8530420SeladCheck if adding and enabling a 816b8530420Selad.Xr strip 4 817b8530420Seladinterface to the system is allowed. 818b8530420Selad.El 81917c0c1e6Selad.It Dv KAUTH_NETWORK_INTERFACE_TUN 82017c0c1e6SeladChecks if operations performed on the 82117c0c1e6Selad.Xr tun 4 82217c0c1e6Seladnetwork interface are allowed. 82317c0c1e6Selad.Pp 82417c0c1e6Selad.Ar req 82517c0c1e6Seladcan be one of the following: 82617c0c1e6Selad.Bl -tag -width compact 82717c0c1e6Selad.It Dv KAUTH_REQ_NETWORK_INTERFACE_TUN_ADD 82817c0c1e6SeladChecks if adding and enabling a 82917c0c1e6Selad.Xr tun 4 83017c0c1e6Seladinterface to the system is allowed. 83117c0c1e6Selad.El 8320c9d8d15Selad.It Dv KAUTH_NETWORK_IPSEC 8330c9d8d15SeladCheck if operations related to 8340c9d8d15Selad.Xr ipsec 4 8350c9d8d15Seladconnections are allowed. 8360c9d8d15Selad.Ar req 8370c9d8d15Seladcan be one of the following: 8380c9d8d15Selad.Bl -tag -width compact 8390c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_IPSEC_BYPASS 8400c9d8d15SeladCheck if bypassing 8410c9d8d15Selad.Xr ipsec 4 8420c9d8d15Seladpolicy is allowed. 8430c9d8d15Selad.El 8440c9d8d15Selad.It Dv KAUTH_NETWORK_IPV6 8450c9d8d15SeladCheck if IPv6-specific operations are allowed. 8460c9d8d15Selad.Ar req 8470c9d8d15Seladcan be one of the following: 8480c9d8d15Selad.Bl -tag -width compact 8490c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_IPV6_HOPBYHOP 8500c9d8d15SeladCheck if setting hop-by-hop packet options is allowed. 8510c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_IPV6_JOIN_MULTICAST 8520c9d8d15SeladCheck if joining a multicast network is allowed. 8530c9d8d15Selad.El 854620ee93fSelad.It Dv KAUTH_NETWORK_FORWSRCRT 855620ee93fSeladChecks whether status of forwarding of source-routed packets can be modified 856620ee93fSelador not. 857cd05a6eeSelad.It Dv KAUTH_NETWORK_NFS 858901cdb56SwizCheck if an NFS related operation is allowed. 859cd05a6eeSelad.Pp 860cd05a6eeSelad.Ar req 861cd05a6eeSeladcan be any of the following: 862925e8d03Sjoerg.Bl -tag -width compact 863cd05a6eeSelad.It Dv KAUTH_REQ_NETWORK_NFS_EXPORT 864cd05a6eeSeladCheck if modifying the NFS export table is allowed. 865cd05a6eeSelad.It Dv KAUTH_REQ_NETWORK_NFS_SVC 866cd05a6eeSeladCheck if access to the NFS 867cd05a6eeSelad.Xr nfssvc 2 868cd05a6eeSeladsyscall is allowed. 869cd05a6eeSelad.El 870620ee93fSelad.It Dv KAUTH_NETWORK_ROUTE 871620ee93fSeladChecks if a routing-related request is allowed. 872620ee93fSelad.Pp 87383a5239bSelad.Ar arg1 874620ee93fSeladis the 875620ee93fSelad.Ft struct rt_msghdr * 876620ee93fSeladfor the request. 8770c9d8d15Selad.It Dv KAUTH_NETWORK_SMB 8780c9d8d15SeladCheck if operations related to SMB are allowed. 8790c9d8d15Selad.Pp 8800c9d8d15Selad.Ar req 8810c9d8d15Seladcan be one of the following: 8820c9d8d15Selad.Bl -tag -width compact 8830c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_SMB_SHARE_ACCESS 8840c9d8d15SeladCheck if accessing an SMB share is allowed. 8850c9d8d15Selad.Pp 8860c9d8d15Selad.Ar arg1 8870c9d8d15Seladis a 8880c9d8d15Selad.Ft struct smb_share * 8890c9d8d15Seladdescribing the SMB share, and 8900c9d8d15Selad.Ar arg2 8910c9d8d15Seladis a 8920c9d8d15Selad.Ft mode_t 8930c9d8d15Seladwith the desired access mode. 8940c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_SMB_SHARE_CREATE 8950c9d8d15SeladCheck if creating an SMB share is allowed. 8960c9d8d15Selad.Pp 8970c9d8d15Selad.Ar arg1 8980c9d8d15Seladis a 8990c9d8d15Selad.Ft struct smb_sharespec * 9000c9d8d15Seladdescribing the share to be created. 9010c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_SMB_VC_ACCESS 9020c9d8d15SeladCheck if accessing an SMB VC is allowed. 9030c9d8d15Selad.Pp 9040c9d8d15Selad.Ar arg1 9050c9d8d15Seladis a 9060c9d8d15Selad.Ft struct smb_vc * 9070c9d8d15Seladdescribing the SMB VC, and 9080c9d8d15Selad.Ar arg2 9090c9d8d15Seladis a 9100c9d8d15Selad.Ft mode_t 9110c9d8d15Seladwith the desired access mode. 9120c9d8d15Selad.It Dv KAUTH_REQ_NETWORK_SMB_VC_CREATE 9130c9d8d15SeladCheck if creating an SMB VC is allowed. 9140c9d8d15Selad.Pp 9150c9d8d15Selad.Ar arg1 9160c9d8d15Seladis a 9170c9d8d15Selad.Ft struct smb_vcspec * 9180c9d8d15Seladdescribing the VC to be created. 9190c9d8d15Selad.El 920620ee93fSelad.It Dv KAUTH_NETWORK_SOCKET 921adf8d7aaSeladChecks if a socket related operation is allowed. 922620ee93fSelad.Pp 92383a5239bSelad.Ar req 924620ee93fSeladallows to indicate the type of the request to structure listeners and callers 925620ee93fSeladeasier. 926620ee93fSeladSupported request types: 927925e8d03Sjoerg.Bl -tag -width compact 928620ee93fSelad.It Dv KAUTH_REQ_NETWORK_SOCKET_RAWSOCK 929620ee93fSeladChecks if opening a raw socket is allowed. 930adf8d7aaSelad.It Dv KAUTH_REQ_NETWORK_SOCKET_OPEN 931adf8d7aaSeladChecks if opening a socket is allowed. 932adf8d7aaSelad.Ar arg1 , arg2 , 933adf8d7aaSeladand 934adf8d7aaSelad.Ar arg3 935adf8d7aaSeladare all 93652d87447Selad.Ft int 93752d87447Seladparameters describing the domain, socket type, and protocol, 938adf8d7aaSeladrespectively. 9398c494ca7Selad.It Dv KAUTH_REQ_NETWORK_SOCKET_CANSEE 9408c494ca7SeladChecks if looking at the socket passed is allowed. 9418c494ca7Selad.Pp 9428c494ca7Selad.Ar arg1 9438c494ca7Seladis a 9448c494ca7Selad.Ft struct socket * 9458c494ca7Seladdescribing the socket. 9462d1c9683Selad.It Dv KAUTH_REQ_NETWORK_SOCKET_DROP 9472d1c9683SeladChecks if a connection can be dropped. 9482d1c9683Selad.Pp 9492d1c9683Selad.Ar arg1 9502d1c9683Seladis a 9512d1c9683Selad.Ft struct socket * 9522d1c9683Seladdescribing the socket. 9532d1c9683Selad.It Dv KAUTH_REQ_NETWORK_SOCKET_SETPRIV 9542d1c9683SeladChecks if setting privileged socket options is allowed. 9552d1c9683Selad.Pp 9562d1c9683Selad.Ar arg1 9572d1c9683Seladis a 9582d1c9683Selad.Ft struct socket * 9592d1c9683Seladdescribing the socket, 9602d1c9683Selad.Ar arg2 9612d1c9683Seladis a 9622d1c9683Selad.Ft u_long 9632d1c9683Seladdescribing the socket option. 964620ee93fSelad.El 965620ee93fSelad.El 966620ee93fSelad.Ss Machine-dependent Scope 967620ee93fSeladThe machine-dependent (machdep) scope, 968620ee93fSelad.Dq org.netbsd.kauth.machdep , 969620ee93fSeladmanages machine-dependent authorization requests in the kernel. 970620ee93fSelad.Pp 971620ee93fSeladThe authorization wrapper for this scope is declared as 972620ee93fSelad.Pp 973620ee93fSelad.Ft int Fn kauth_authorize_machdep "kauth_cred_t cred" "kauth_action_t op" \ 974504c71d9Selad"void *arg0" "void *arg1" "void *arg2" "void *arg3" 975620ee93fSelad.Pp 976504c71d9SeladThe actions on this scope provide a set that may or may not affect all 977504c71d9Seladplatforms. 978504c71d9SeladBelow is a list of available actions, along with which platforms are affected 979504c71d9Seladby each. 980925e8d03Sjoerg.Bl -tag -width compact 9812d1c9683Selad.It Dv KAUTH_MACHDEP_CACHEFLUSH 9822d1c9683SeladRequest to flush the whole CPU cache. 9832d1c9683SeladAffects 9842d1c9683Selad.Em m68k 9852d1c9683SeladLinux emulation. 9860c9d8d15Selad.It Dv KAUTH_MACHDEP_CPU_UCODE_APPLY 9870c9d8d15SeladRequest to apply a CPU microcode to a CPU. 9880c9d8d15SeladThis is related to 9890c9d8d15Selad.Em CPU_UCODE , 9900c9d8d15Seladsee 9910c9d8d15Selad.Xr options 4 . 9920c9d8d15SeladAffects 9930c9d8d15Selad.Em i386 9940c9d8d15Seladand 9950c9d8d15Selad.Em xen . 996504c71d9Selad.It Dv KAUTH_MACHDEP_IOPERM_GET 997504c71d9SeladRequest to get the I/O permission level. 998504c71d9SeladAffects 999504c71d9Selad.Em amd64 , 1000504c71d9Selad.Em i386 , 1001504c71d9Selad.Em xen . 1002504c71d9Selad.It Dv KAUTH_MACHDEP_IOPERM_SET 1003504c71d9SeladRequest to set the I/O permission level. 1004504c71d9SeladAffects 1005504c71d9Selad.Em amd64 , 1006504c71d9Selad.Em i386 , 1007504c71d9Selad.Em xen . 1008504c71d9Selad.It Dv KAUTH_MACHDEP_IOPL 1009504c71d9SeladRequest to set the I/O privilege level. 1010504c71d9SeladAffects 1011504c71d9Selad.Em amd64 , 1012504c71d9Selad.Em i386 , 1013504c71d9Selad.Em xen . 1014504c71d9Selad.It Dv KAUTH_MACHDEP_LDT_GET 1015504c71d9SeladRequest to get the LDT (local descriptor table). 1016504c71d9SeladAffects 1017504c71d9Selad.Em amd64 , 1018504c71d9Selad.Em i386 , 1019504c71d9Selad.Em xen . 1020504c71d9Selad.It Dv KAUTH_MACHDEP_LDT_SET 1021504c71d9SeladRequest to set the LDT (local descriptor table). 1022504c71d9SeladAffects 1023504c71d9Selad.Em amd64 , 1024504c71d9Selad.Em i386 , 1025504c71d9Selad.Em xen . 1026504c71d9Selad.It Dv KAUTH_MACHDEP_MTRR_GET 1027504c71d9SeladRequest to get the MTRR (memory type range registers). 1028504c71d9SeladAffects 1029504c71d9Selad.Em amd64 , 1030504c71d9Selad.Em i386 , 1031504c71d9Selad.Em xen . 1032504c71d9Selad.It Dv KAUTH_MACHDEP_MTRR_SET 1033504c71d9SeladRequest to set the MTRR (memory type range registers). 1034504c71d9SeladAffects 1035504c71d9Selad.Em amd64 , 1036504c71d9Selad.Em i386 , 1037504c71d9Selad.Em xen . 10382d1c9683Selad.It Dv KAUTH_MACHDEP_NVRAM 10392d1c9683SeladRequest to access (read/write) the NVRAM. 10402d1c9683SeladAffects 10412d1c9683Selad.Em i386 . 10420c9d8d15Selad.It Dv KAUTH_MACHDEP_PXG 10430c9d8d15SeladRequest to start or stop the 10440c9d8d15Selad.Xr pxg 4 10450c9d8d15SeladCPU. 10460c9d8d15Selad.Ar arg0 10470c9d8d15Seladis 10480c9d8d15Selad.Ft true 10490c9d8d15Selador 10500c9d8d15Selad.Ft false , 10510c9d8d15Seladrespectively. 10520c9d8d15SeladAffects 10530c9d8d15Selad.Em pmax . 1054504c71d9Selad.It Dv KAUTH_MACHDEP_UNMANAGEDMEM 1055504c71d9SeladRequest to access unmanaged memory. 1056504c71d9SeladAffects 1057504c71d9Selad.Em alpha , 1058504c71d9Selad.Em amd64 , 1059504c71d9Selad.Em arm , 1060504c71d9Selad.Em i386 , 1061504c71d9Selad.Em powerpc , 1062504c71d9Selad.Em sh3 , 1063504c71d9Selad.Em vax , 10645aeec4b8Sisaki.Em x68k , 1065504c71d9Selad.Em xen . 10661674cef5Selad.El 1067b8a33934Selad.Ss Device Scope 1068b8a33934SeladThe device scope, 1069b8a33934Selad.Dq org.netbsd.kauth.device , 10705eebb711Swizmanages authorization requests related to devices on the system. 107177da6fadSwizDevices can be, for example, terminals, tape drives, Bluetooth accessories, and 1072fda35a52Seladany other hardware. 1073b8a33934SeladNetwork devices specifically are handled by the 1074b8a33934Selad.Em network 1075b8a33934Seladscope. 1076b8a33934Selad.Pp 10772db3a96bSeladIn addition to the standard authorization wrapper: 10782db3a96bSelad.Pp 10792db3a96bSelad.Ft int Fn kauth_authorize_device "kauth_cred_t cred" "kauth_action_t op" \ 10802db3a96bSelad"void *arg0" "void *arg1" "void *arg2" "void *arg3" 10812db3a96bSelad.Pp 10822db3a96bSeladthis scope provides authorization wrappers for various device types. 1083b8a33934Selad.Pp 1084b8a33934Selad.Ft int Fn kauth_authorize_device_tty "kauth_cred_t cred" "kauth_action_t op" \ 1085b8a33934Selad"struct tty *tty" 1086b8a33934Selad.Pp 1087b8a33934SeladAuthorizes requests for 1088b8a33934Selad.Em terminal devices 1089b8a33934Seladon the system. 1090b8a33934SeladThe third argument, 1091b8a33934Selad.Ar tty , 1092b8a33934Seladis the terminal device in question. 10931121d7d9SeladIt is passed to the listener as 10941121d7d9Selad.Ar arg0 . 10951121d7d9SeladThe second argument, 10961121d7d9Selad.Ar op , 10971121d7d9Seladis the action and can be one of the following: 1098925e8d03Sjoerg.Bl -tag -width compact 1099b8a33934Selad.It Dv KAUTH_DEVICE_TTY_OPEN 1100b8a33934SeladOpen the terminal device pointed to by 1101b8a33934Selad.Ar tty . 1102b8a33934Selad.It Dv KAUTH_DEVICE_TTY_PRIVSET 1103b8a33934SeladSet privileged settings on the terminal device pointed to by 1104b8a33934Selad.Ar tty . 1105c27d5f30Selad.It Dv KAUTH_DEVICE_TTY_STI 1106c27d5f30SeladUse the 1107c27d5f30Selad.Dq TIOCSTI 1108c27d5f30Seladdevice 1109c27d5f30Selad.Xr ioctl 2 , 1110c27d5f30Seladallowing to inject characters into the terminal buffer, simulating terminal 1111c27d5f30Seladinput. 11120c9d8d15Selad.It Dv KAUTH_DEVICE_TTY_VIRTUAL 11130c9d8d15SeladControl the virtual console. 11140c9d8d15Selad.Ar tty 11150c9d8d15Seladis the current console 11160c9d8d15Selad.Xr tty 4 . 11171121d7d9Selad.El 111852d87447Selad.Pp 11191121d7d9Selad.Ft int Fn kauth_authorize_device_spec "kauth_cred_t cred" \ 11201121d7d9Selad"enum kauth_device_req req" "struct vnode *vp" 11211121d7d9Selad.Pp 11221121d7d9SeladAuthorizes requests for 11231121d7d9Selad.Em special files , 11241121d7d9Seladusually disk devices, but also direct memory access, on the system. 11251121d7d9Selad.Pp 11261121d7d9SeladIt passes 1127987a2558Swiz.Dv KAUTH_DEVICE_RAWIO_SPEC 11281121d7d9Seladas the action to the listener, and accepts two arguments. 11291121d7d9Selad.Ar req , 11301121d7d9Seladpassed to the listener as 11311121d7d9Selad.Ar arg0 , 11321121d7d9Seladis access requested, and can be one of 1133987a2558Swiz.Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_READ , 1134987a2558Swiz.Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_WRITE , 11351121d7d9Selador 1136987a2558Swiz.Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_RW , 11371121d7d9Seladrepresenting read, write, or both read/write access respectively. 11381121d7d9Selad.Ar vp 11391121d7d9Seladis the vnode of the special file in question, and is passed to the listener as 11401121d7d9Selad.Ar arg1 . 11411121d7d9Selad.Pp 11421121d7d9SeladKeep in mind that it is the responsibility of the security model developer to 11431121d7d9Seladcheck whether the underlying device is a disk or the system memory, using 11441121d7d9Selad.Fn iskmemdev : 11451121d7d9Selad.Bd -literal -offset indent 114601869ca4Swizif ((vp->v_type == VCHR) && 114701869ca4Swiz iskmemdev(vp->v_un.vu_specinfo->si_rdev)) 11481121d7d9Selad /* system memory access */ 11491121d7d9Selad.Ed 11501121d7d9Selad.Pp 11511121d7d9Selad.Ft int Fn kauth_authorize_device_passthru "kauth_cred_t cred" "dev_t dev" \ 1152432c3099Selad"u_long mode" "void *data" 11531121d7d9Selad.Pp 11541121d7d9SeladAuthorizes hardware 11551121d7d9Selad.Em passthru 11561121d7d9Seladrequests, or user commands passed directly to the hardware. 11571121d7d9SeladThese have the potential of resulting in direct disk and/or memory access. 11581121d7d9Selad.Pp 11591121d7d9SeladIt passes 1160987a2558Swiz.Dv KAUTH_DEVICE_RAWIO_PASSTHRU 1161432c3099Seladas the action to the listener, and accepts three arguments. 11621121d7d9Selad.Ar dev , 11631121d7d9Seladpassed as 11641121d7d9Selad.Ar arg1 1165432c3099Seladto the listener, is the device for which the request is made. 1166432c3099Selad.Ar mode , 1167432c3099Seladpassed as 1168432c3099Selad.Ar arg0 1169432c3099Seladto the listener, is a generic representation of the access mode requested. 1170432c3099SeladIt can be one or more (binary-OR'd) of the following: 1171432c3099Selad.Pp 1172925e8d03Sjoerg.Bl -tag -width compact -offset indent -compact 1173432c3099Selad.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READ 1174432c3099Selad.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READCONF 1175432c3099Selad.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITE 1176432c3099Selad.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITECONF 1177432c3099Selad.El 1178432c3099Selad.Pp 11791121d7d9Selad.Ar data , 11801121d7d9Seladpassed as 11811121d7d9Selad.Ar arg2 11821121d7d9Seladto the listener, is device-specific data that may be associated with the 11831121d7d9Seladrequest. 1184a756ea62Selad.Ss Bluetooth Devices 118577da6fadSwizAuthorizing actions relevant to Bluetooth devices is done using the standard 1186fda35a52Seladauthorization wrapper, with the following actions: 1187fda35a52Selad.Bl -tag -width compact 1188b8530420Selad.It KAUTH_DEVICE_BLUETOOTH_BCSP 1189b8530420SeladCheck if operations on a 1190b8530420Selad.Xr bcsp 4 1191b8530420Seladdevice are allowed. 1192b8530420Selad.Pp 1193b8530420Selad.Ar arg0 1194b8530420Seladis an 1195b8530420Selad.Ft enum kauth_device_req 1196b8530420Seladwith one of the following values: 1197b8530420Selad.Bl -tag -width compact 1198b8530420Selad.It Dv KAUTH_REQ_DEVICE_BLUETOOTH_BCSP_ADD 1199b8530420SeladCheck if adding and enabling a 1200b8530420Selad.Xr bcsp 4 1201b8530420Seladdevice is allowed. 1202b8530420Selad.El 1203b8530420Selad.It KAUTH_DEVICE_BLUETOOTH_BTUART 1204b8530420SeladCheck if operations on a 1205b8530420Selad.Xr btuart 4 1206b8530420Seladdevice are allowed. 1207b8530420Selad.Pp 1208b8530420Selad.Ar arg0 1209b8530420Seladis an 1210b8530420Selad.Ft enum kauth_device_req 1211b8530420Seladwith one of the following values: 1212b8530420Selad.Bl -tag -width compact 1213b8530420Selad.It Dv KAUTH_REQ_DEVICE_BLUETOOTH_BTUART_ADD 1214b8530420SeladCheck if adding and enabling a 1215b8530420Selad.Xr btuart 4 1216b8530420Seladdevice is allowed. 1217b8530420Selad.El 12184f6ac133Splunky.It KAUTH_DEVICE_BLUETOOTH_RECV 12194f6ac133SplunkyCheck if a packet can be received from the device. 122080c6ec5dSplunky.Pp 122180c6ec5dSplunky.Ar arg0 122280c6ec5dSplunkyis the packet type. 12234f6ac133SplunkyFor 12244f6ac133Splunky.Dv HCI_CMD_PKT 12254f6ac133Splunkypackets, 12264f6ac133Splunky.Ar arg1 12274f6ac133Splunkyis the opcode, for 12284f6ac133Splunky.Dv HCI_EVENT_PKT 12294f6ac133Splunkypackets, 12304f6ac133Splunky.Ar arg1 12314f6ac133Splunkyis the event ID, and for 12324f6ac133Splunky.Dv HCI_ACLDATA_PKT 12334f6ac133Splunkyor 12344f6ac133Splunky.Dv HCI_SCODATA_PKT 12354f6ac133Splunkypackets, 12364f6ac133Splunky.Ar arg1 12374f6ac133Splunkyis the connection handle. 12384f6ac133Splunky.It KAUTH_DEVICE_BLUETOOTH_SEND 12394f6ac133SplunkyCheck if a packet can be sent to the device. 124080c6ec5dSplunky.Pp 124180c6ec5dSplunky.Ar arg0 124280c6ec5dSplunkyis a 124380c6ec5dSplunky.Ft struct hci_unit * 124480c6ec5dSplunkydescribing the HCI unit, 124580c6ec5dSplunky.Ar arg1 124680c6ec5dSplunkyis a 124780c6ec5dSplunky.Ft hci_cmd_hdr_t * 12484f6ac133Splunkydescribing the packet header. 1249fda35a52Selad.It KAUTH_DEVICE_BLUETOOTH_SETPRIV 1250fda35a52SeladCheck if privileged settings can be changed. 1251fda35a52Selad.Pp 1252fda35a52Selad.Ar arg0 1253fda35a52Seladis a 1254fda35a52Selad.Ft struct hci_unit * 1255fda35a52Seladdescribing the HCI unit, 1256fda35a52Selad.Ar arg1 1257fda35a52Seladis a 1258fda35a52Selad.Ft struct btreq * 1259fda35a52Seladdescribing the request, and 1260fda35a52Selad.Ar arg2 1261fda35a52Seladis a 1262fda35a52Selad.Ft u_long 1263fda35a52Seladdescribing the command. 1264fda35a52Selad.El 1265a756ea62Selad.Ss Kernel random device 1266b50c4b9eSeladAuthorization actions relevant to the kernel random device, 1267b50c4b9eSelad.Xr rnd 4 , 1268b50c4b9eSeladis done using the standard authorization wrapper, with the following actions: 1269b50c4b9eSelad.Bl -tag -width compact 1270b50c4b9eSelad.It KAUTH_DEVICE_RND_ADDDATA 1271b50c4b9eSeladCheck if adding data to the entropy pool is allowed. 1272b50c4b9eSelad.It KAUTH_DEVICE_RND_GETPRIV 1273b50c4b9eSeladCheck if privileged settings and information can be retrieved. 1274b50c4b9eSelad.It KAUTH_DEVICE_RND_SETPRIV 1275b50c4b9eSeladCheck if privileged settings can be changed. 1276b50c4b9eSelad.El 12770c9d8d15Selad.Ss Wscons devices 12780c9d8d15SeladAuthorization actions relevant to 12790c9d8d15Selad.Xr wscons 4 12800c9d8d15Seladare done using the standard authorization wrapper, with the following actions: 12810c9d8d15Selad.Bl -tag -width compact 12820c9d8d15Selad.It KAUTH_DEVICE_WSCONS_KEYBOARD_BELL 12830c9d8d15SeladCheck if setting the default bell is allowed. 12840c9d8d15Selad.It KAUTH_DEVICE_WSCONS_KEYBOARD_KEYREPEAT 12850c9d8d15SeladCheck if setting the default key-repeat is allowed. 12860c9d8d15Selad.El 12870c9d8d15Selad.Ss Vnode Scope 12880c9d8d15SeladThe vnode scope, 12890c9d8d15Selad.Dq org.netbsd.kauth.vnode , 1290948a1519Swizauthorizes operations made on vnodes representing file system objects. 12910c9d8d15Selad.Pp 12920c9d8d15SeladThe authorization wrapper for this scope is declared as 12930c9d8d15Selad.Pp 12940c9d8d15Selad.Ft int Fn kauth_authorize_vnode "kauth_cred_t cred" "kauth_action_t action" \ 12950c9d8d15Selad"vnode_t *vp" "vnode_t *dvp" "int fs_decision" 12960c9d8d15Selad.Pp 1297948a1519SwizThis scope is heavily used in file system code and can potentially affect 12980c9d8d15Seladsystem-wide performance. 12990c9d8d15SeladTherefore, there are several things developers should know when using it. 13000c9d8d15Selad.Pp 13010c9d8d15SeladFirst, the 13020c9d8d15Selad.Ar action 13030c9d8d15Seladparameter is a bit-mask and multiple actions can be binary-OR'd and authorized 13040c9d8d15Seladin a single call. 13050c9d8d15SeladTwo helper functions help generate the 13060c9d8d15Selad.Ar action 1307948a1519Swizvalue for a couple of common cases: translating file system access to a 13082dc39176Swiz.Nm 13090c9d8d15Seladaction and checking access to a vnode. 13100c9d8d15Selad.Pp 13110c9d8d15SeladThe first, 13120c9d8d15Selad.Fn kauth_mode_to_action "mode_t access_mode" , 13130c9d8d15Seladand returns a 13140c9d8d15Selad.Ft kauth_action_t 13150c9d8d15Seladrepresenting the desired access modes. 13160c9d8d15SeladAnother function, 13170c9d8d15Selad.Fn kauth_access_action "mode_t access_mode" "enum vtype v_type" \ 13180c9d8d15Selad"mode_t file_mode" , 13190c9d8d15Seladreturns a 13200c9d8d15Selad.Ft kauth_action_t 1321948a1519Swizsuitable for use in many file system 13220c9d8d15Selad.Xr access 2 13230c9d8d15Seladimplementations. 13240c9d8d15SeladIt calls the aforementioned 13250c9d8d15Selad.Fn kauth_mode_to_action , 13260c9d8d15Seladbut before returning also adds the 13270c9d8d15Selad.Dv KAUTH_VNODE_IS_EXEC 13280c9d8d15Seladflag if needed. 13290c9d8d15SeladSee below for the meaning of this flag and how its necessity is 13300c9d8d15Seladdetermined. 13310c9d8d15Selad.Pp 13320c9d8d15SeladSecond, it is recommended to be very careful with adding listeners on this 13330c9d8d15Seladscope. 13340c9d8d15SeladA special parameter, 13350c9d8d15Selad.Ar fs_decision , 1336948a1519Swizallows different file systems to instrument different policies without adding 13370c9d8d15Seladtheir own listener. 13380c9d8d15SeladThis parameter is special because it also serves as a fall-back decision when 13390c9d8d15Seladno 13400c9d8d15Selad.Xr secmodel 9 13410c9d8d15Seladis present to prevent a fail-open scenario. 13420c9d8d15SeladIt can take either an 13430c9d8d15Selad.Xr errno 2 13440c9d8d15Seladvalue or 13450c9d8d15Selad.Dq KAUTH_VNODE_REMOTEFS , 1346948a1519Swizindicating that the file system on which the authorization is made is remote 13470c9d8d15Seladand cannot provide us with a fall-back decision. 13480c9d8d15SeladIn this case, 13492dc39176Swiz.Nm 1350948a1519Swizcan only short-circuit the request but the file system will have the last 13510c9d8d15Seladword if there is no definitive allow or deny decision. 13520c9d8d15Selad.Pp 13530c9d8d15SeladThe value of 13540c9d8d15Selad.Ar fs_decision 13550c9d8d15Seladcan be hard-coded or determined by calling an internal function implementing a 13560c9d8d15Seladpolicy. 13570c9d8d15SeladFor the latter case, 13580c9d8d15Selad.Xr genfs 9 13590c9d8d15Seladprovides a set of helper functions that implement common policies that 1360948a1519Swizfile systems can use. 13610c9d8d15SeladThe calling convention is as follows: 13620c9d8d15Selad.Bd -literal -offset indent 13630c9d8d15Seladint error; 13640c9d8d15Selad 13650c9d8d15Seladerror = kauth_authorize_vnode(..., genfs_can_foo(...)); 13660c9d8d15Selad.Ed 13670c9d8d15Selad.Pp 13680c9d8d15SeladActions on the vnode scope are of two types: operations and flags. 13690c9d8d15SeladAn operation is similar in concept to actions on other scopes in the sense 13700c9d8d15Seladthat it represents an operation desired by the caller. 13710c9d8d15SeladA flag is an indicator of additional information about the vnode that 1372948a1519Swiza file system can set in order to allow the listener to make a more 13730c9d8d15Seladinformed decision. 13740c9d8d15Selad.Pp 13750c9d8d15SeladActions include the following: 13760c9d8d15Selad.Bl -tag -width compact -offset indent 13770c9d8d15Selad.It KAUTH_VNODE_READ_DATA 13780c9d8d15SeladRead file data. 13790c9d8d15Selad.It KAUTH_VNODE_LIST_DIRECTORY 13800c9d8d15SeladRead directory listing. 13810c9d8d15SeladIdentical to the above. 13820c9d8d15Selad.It KAUTH_VNODE_WRITE_DATA 13830c9d8d15SeladWrite file data. 13840c9d8d15Selad.It KAUTH_VNODE_ADD_FILE 13850c9d8d15SeladAdd a file to a directory. 13860c9d8d15SeladIdentical to the above. 13870c9d8d15Selad.It KAUTH_VNODE_EXECUTE 13880c9d8d15SeladExecute a file. 13890c9d8d15Selad.It KAUTH_VNODE_SEARCH 13900c9d8d15SeladSearch (enter) a directory. 13910c9d8d15SeladIdentical to the above. 13920c9d8d15Selad.It KAUTH_VNODE_DELETE 13930c9d8d15SeladDelete a file. 13940c9d8d15Selad.It KAUTH_VNODE_APPEND_DATA 13950c9d8d15SeladAppend data to a file. 13960c9d8d15Selad.It KAUTH_VNODE_ADD_SUBDIRECTORY 13970c9d8d15SeladAdd a subdirectory to a directory. 13980c9d8d15SeladIdentical to the above. 13990c9d8d15Selad.It KAUTH_VNODE_READ_TIMES 14000c9d8d15SeladRead the created, last accessed, and last modified times of a file. 14010c9d8d15Selad.It KAUTH_VNODE_WRITE_TIMES 14020c9d8d15SeladModify the created, last accessed, or last modified times of a file. 14030c9d8d15Selad.It KAUTH_VNODE_READ_FLAGS 14040c9d8d15SeladRead file flags. 14050c9d8d15Selad.It KAUTH_VNODE_WRITE_FLAGS 14060c9d8d15SeladModify file flags. 14070c9d8d15Selad.It KAUTH_VNODE_READ_SYSFLAGS 14080c9d8d15SeladRead file system flags. 14090c9d8d15Selad.It KAUTH_VNODE_WRITE_SYSFLAGS 14100c9d8d15SeladModify file system flags. 14110c9d8d15Selad.It KAUTH_VNODE_RENAME 14120c9d8d15SeladRename a file. 14130c9d8d15Selad.It KAUTH_VNODE_CHANGE_OWNERSHIP 14140c9d8d15SeladChange ownership of a file. 14150c9d8d15Selad.It KAUTH_VNODE_READ_SECURITY 14160c9d8d15SeladRead the permissions of a file. 14170c9d8d15Selad.It KAUTH_VNODE_WRITE_SECURITY 14180c9d8d15SeladChange the permissions of a file, for example by using 14190c9d8d15Selad.Xr chmod 2 . 14200c9d8d15Selad.It KAUTH_VNODE_READ_ATTRIBUTES 14210c9d8d15SeladRead attributes of a file. 14220c9d8d15Selad.It KAUTH_VNODE_WRITE_ATTRIBUTES 14230c9d8d15SeladModify attributes of a file. 14240c9d8d15Selad.It KAUTH_VNODE_READ_EXTATTRIBUTES 14250c9d8d15SeladRead extended attributes of a file. 14260c9d8d15Selad.It KAUTH_VNODE_WRITE_EXTATTRIBUTES 14270c9d8d15SeladModify extended attributes of a file. 14280c9d8d15Selad.It KAUTH_VNODE_RETAIN_SUID 14290c9d8d15SeladCheck if retaining the set-user-id bit on files after 14300c9d8d15Selad.Xr chown 2 14310c9d8d15Seladis allowed. 14320c9d8d15Selad.It KAUTH_VNODE_RETAIN_SGID 14330c9d8d15SeladCheck if retaining the set-group-id bit on files after 14340c9d8d15Selad.Xr chown 2 14350c9d8d15Seladis allowed. 14360c9d8d15Selad.It KAUTH_VNODE_REVOKE 14370c9d8d15SeladRevoke a file. 14380c9d8d15Selad.El 14390c9d8d15Selad.Pp 14400c9d8d15SeladFlags include the following: 14410c9d8d15Selad.Bl -tag -width compact -offset indent 14420c9d8d15Selad.It KAUTH_VNODE_IS_EXEC 14430c9d8d15SeladThe vnode is executable. 14440c9d8d15Selad.Pp 14450c9d8d15SeladThe macro 14460c9d8d15Selad.Fn FS_OBJECT_CAN_EXEC 14470c9d8d15Seladcan be used to help determine if this flag should be set. 1448948a1519SwizThis macro determines a file system object to be executable if it is a 14490c9d8d15Seladdirectory (in which case we say it is searchable) or if it has at least one 14500c9d8d15Seladexecutable bit set in its mode. 14510c9d8d15Selad.Pp 14520c9d8d15SeladSetting this flag helps a listener know that a vnode is executable and is used 14530c9d8d15Seladin implementing privileged access to files and directories while maintaining 14540c9d8d15Seladsemantics that prevent execution until a file is marked as an executable. 14550c9d8d15SeladAn example for using this in listener code is: 14560c9d8d15Selad.Bd -literal -offset indent 14570c9d8d15Seladif (privileged) { 14580c9d8d15Selad /* Always allow read/write; execute only if executable. */ 14590c9d8d15Selad if ((action & KAUTH_VNODE_EXECUTE) == 0 || 14600c9d8d15Selad (action & KAUTH_VNODE_IS_EXEC)) 14610c9d8d15Selad result = KAUTH_RESULT_ALLOW; 14620c9d8d15Selad} 14630c9d8d15Selad.Ed 14640c9d8d15Selad.Pp 14650c9d8d15SeladFinally, the vnode scope authorization wrapper returns 14660c9d8d15Selad.Er EACCES 1467948a1519Swizin case of an error, to maintain file system semantics. 1468948a1519SwizFile systems can override this value if needed. 14690c9d8d15Selad.It KAUTH_VNODE_HAS_SYSFLAGS 1470948a1519SwizThe file system object represented by the vnode has system flags set. 14710c9d8d15Selad.It KAUTH_VNODE_ACCESS 14720c9d8d15SeladThe authorization is advisory only and no actual operation is to be 14730c9d8d15Seladperformed. 14740c9d8d15SeladThis is not implemented. 14750c9d8d15Selad.El 1476c439bcfeSelad.Ss Credentials Scope 1477c439bcfeSeladThe credentials scope, 1478c439bcfeSelad.Dq org.netbsd.kauth.cred , 1479c439bcfeSeladis a special scope used internally by the 1480c439bcfeSelad.Nm 1481c439bcfeSeladframework to provide hooking to credential-related operations. 1482c439bcfeSelad.Pp 1483c439bcfeSeladIt is a 1484c439bcfeSelad.Dq notify-only 1485c439bcfeSeladscope, allowing hooking operations such as initialization of new credentials, 1486c439bcfeSeladcredential inheritance during a fork, and copying and freeing of credentials. 1487c439bcfeSeladThe main purpose for this scope is to give a security model a way to control 1488c439bcfeSeladthe aforementioned operations, especially in cases where the credentials 1489c439bcfeSeladhold security model-private data. 1490c439bcfeSelad.Pp 1491c439bcfeSeladNotifications are made using the following function, which is internal to 1492c439bcfeSelad.Nm : 1493c439bcfeSelad.Pp 1494c439bcfeSelad.Ft int Fn kauth_cred_hook "kauth_cred_t cred" "kauth_action_t action" \ 1495c439bcfeSelad"void *arg0" "void *arg1" 1496c439bcfeSelad.Pp 1497c439bcfeSeladWith the following actions: 1498925e8d03Sjoerg.Bl -tag -width compact 1499c439bcfeSelad.It Dv KAUTH_CRED_COPY 1500c439bcfeSeladThe credentials are being copied. 1501c439bcfeSelad.Ar cred 1502c439bcfeSeladare the credentials of the lwp context doing the copy, and 1503c439bcfeSelad.Ar arg0 1504c439bcfeSeladand 1505c439bcfeSelad.Ar arg1 1506c439bcfeSeladare both 1507c439bcfeSelad.Ft kauth_cred_t 1508c439bcfeSeladrepresenting the 1509c439bcfeSelad.Dq from 1510c439bcfeSeladand 1511c439bcfeSelad.Dq to 1512c439bcfeSeladcredentials, respectively. 1513c439bcfeSelad.It Dv KAUTH_CRED_FORK 1514c439bcfeSeladThe credentials are being inherited from a parent to a child process during a 1515c439bcfeSeladfork. 1516c439bcfeSelad.Pp 1517c439bcfeSelad.Ar cred 1518ea967108Seladare the credentials of the lwp context doing the fork, and 1519c439bcfeSelad.Ar arg0 1520c439bcfeSeladand 1521c439bcfeSelad.Ar arg1 1522c439bcfeSeladare both 1523c439bcfeSelad.Ft struct proc * 1524c439bcfeSeladof the parent and child processes, respectively. 1525b6b59f49Scheusov.It Dv KAUTH_CRED_CHROOT 1526b6b59f49ScheusovThe credentials in cred belong to a process whose root directory is 1527b6b59f49Scheusovchanged through 15282dc39176Swiz.Fn change_root 15292dc39176Swiz(see 15302dc39176Swiz.Xr vfs 9 ). 1531b6b59f49Scheusov.Pp 1532b6b59f49Scheusov.Ar Arg0 1533b6b59f49Scheusovis the new 1534b6b59f49Scheusov.Ft struct cwdinfo * 1535b6b59f49Scheusovof the process. 1536c439bcfeSelad.It Dv KAUTH_CRED_FREE 1537c439bcfeSeladThe credentials in 1538c439bcfeSelad.Ar cred 1539c439bcfeSeladare being freed. 1540c439bcfeSelad.It Dv KAUTH_CRED_INIT 1541c439bcfeSeladThe credentials in 1542c439bcfeSelad.Ar cred 1543c439bcfeSeladare being initialized. 1544c439bcfeSelad.El 1545c439bcfeSelad.Pp 1546c439bcfeSeladSince this is a notify-only scope, all listeners are required to return 1547c439bcfeSelad.Dv KAUTH_RESULT_ALLOW . 15481674cef5Selad.Ss Credentials Accessors and Mutators 15491674cef5Selad.Nm 15501674cef5Seladhas a variety of accessor and mutator routines to handle 15511674cef5Selad.Ft kauth_cred_t 15521674cef5Seladobjects. 15531674cef5Selad.Pp 15541674cef5SeladThe following routines can be used to access and modify the user- and 15551674cef5Seladgroup-ids in a 15561674cef5Selad.Ft kauth_cred_t : 1557925e8d03Sjoerg.Bl -tag -width compact 15581674cef5Selad.It Ft uid_t Fn kauth_cred_getuid "kauth_cred_t cred" 15591674cef5SeladReturns the real user-id from 15601674cef5Selad.Ar cred . 15611674cef5Selad.It Ft uid_t Fn kauth_cred_geteuid "kauth_cred_t cred" 15621674cef5SeladReturns the effective user-id from 15631674cef5Selad.Ar cred . 15641674cef5Selad.It Ft uid_t Fn kauth_cred_getsvuid "kauth_cred_t cred" 15651674cef5SeladReturns the saved user-id from 15661674cef5Selad.Ar cred . 15671674cef5Selad.It Ft void Fn kauth_cred_setuid "kauth_cred_t cred" "uid_t uid" 15681674cef5SeladSets the real user-id in 15691674cef5Selad.Ar cred 15701674cef5Seladto 15711674cef5Selad.Ar uid . 15721674cef5Selad.It Ft void Fn kauth_cred_seteuid "kauth_cred_t cred" "uid_t uid" 15731674cef5SeladSets the effective user-id in 15741674cef5Selad.Ar cred 15751674cef5Seladto 15761674cef5Selad.Ar uid . 15771674cef5Selad.It Ft void Fn kauth_cred_setsvuid "kauth_cred_t cred" "uid_t uid" 15781674cef5SeladSets the saved user-id in 15791674cef5Selad.Ar cred 15801674cef5Seladto 15811674cef5Selad.Ar uid . 15821674cef5Selad.It Ft gid_t Fn kauth_cred_getgid "kauth_cred_t cred" 15831674cef5SeladReturns the real group-id from 15841674cef5Selad.Ar cred . 15851674cef5Selad.It Ft gid_t Fn kauth_cred_getegid "kauth_cred_t cred" 15861674cef5SeladReturns the effective group-id from 15871674cef5Selad.Ar cred . 15881674cef5Selad.It Ft gid_t Fn kauth_cred_getsvgid "kauth_cred_t cred" 15891674cef5SeladReturns the saved group-id from 15901674cef5Selad.Ar cred . 15911674cef5Selad.It Ft void Fn kauth_cred_setgid "kauth_cred_t cred" "gid_t gid" 15921674cef5SeladSets the real group-id in 15931674cef5Selad.Ar cred 15941674cef5Seladto 15951674cef5Selad.Ar gid . 15961674cef5Selad.It Ft void Fn kauth_cred_setegid "kauth_cred_t cred" "gid_t gid" 15971674cef5SeladSets the effective group-id in 15981674cef5Selad.Ar cred 15991674cef5Seladto 16001674cef5Selad.Ar gid . 16011674cef5Selad.It Ft void Fn kauth_cred_setsvgid "kauth_cred_t cred" "gid_t gid" 16021674cef5SeladSets the saved group-id in 16031674cef5Selad.Ar cred 16041674cef5Seladto 16051674cef5Selad.Ar gid . 160670611312Sad.It Ft u_int Fn kauth_cred_getrefcnt "kauth_cred_t cred" 16071674cef5SeladReturn the reference count for 16081674cef5Selad.Ar cred . 16091674cef5Selad.El 16101674cef5Selad.Pp 16111674cef5SeladThe following routines can be used to access and modify the group 16121674cef5Seladlist in a 16131674cef5Selad.Ft kauth_cred_t : 1614925e8d03Sjoerg.Bl -tag -width compact 16151674cef5Selad.It Ft int Fn kauth_cred_ismember_gid "kauth_cred_t cred" "gid_t gid" \ 16161674cef5Selad"int *resultp" 16171674cef5SeladChecks if the group-id 16181674cef5Selad.Ar gid 16191674cef5Seladis a member in the group list of 16201674cef5Selad.Ar cred . 16211674cef5Selad.Pp 16221674cef5SeladIf it is, 16231674cef5Selad.Ar resultp 16241674cef5Seladwill be set to one, otherwise, to zero. 16251674cef5Selad.Pp 16261674cef5SeladThe return value is an error code, or zero for success. 162770611312Sad.It Ft u_int Fn kauth_cred_ngroups "kauth_cred_t cred" 16281674cef5SeladReturn the number of groups in the group list of 16291674cef5Selad.Ar cred . 1630ffa428bfSdsl.It Ft gid_t Fn kauth_cred_group "kauth_cred_t cred" "u_int idx" 16311674cef5SeladReturn the group-id of the group at index 16321674cef5Selad.Ar idx 16331674cef5Seladin the group list of 16341674cef5Selad.Ar cred . 16351179d684Spooka.It Ft int Fn kauth_cred_setgroups "kauth_cred_t cred" "const gid_t *groups" \ 163697427fb0Syamt"size_t ngroups" "uid_t gmuid" "enum uio_seg seg" 16371674cef5SeladCopy 16381674cef5Selad.Ar ngroups 16391674cef5Seladgroups from array pointed to by 16401674cef5Selad.Ar groups 16411674cef5Seladto the group list in 16421674cef5Selad.Ar cred , 16431674cef5Seladadjusting the number of groups in 16441674cef5Selad.Ar cred 16451674cef5Seladappropriately. 164697427fb0Syamt.Ar seg 164797427fb0Syamtshould be either 1648ffa428bfSdsl.Dv UIO_USERSPACE 1649ffa428bfSdslor 1650ffa428bfSdsl.Dv UIO_SYSSPACE 1651ffa428bfSdslindicating whether 1652ffa428bfSdsl.Ar groups 1653ffa428bfSdslis a user or kernel space address. 16541674cef5Selad.Pp 16551674cef5SeladAny groups remaining will be set to an invalid value. 16561674cef5Selad.Pp 16571674cef5Selad.Ar gmuid 16581674cef5Seladis unused for now, and to maintain interface compatibility with the Darwin 16591674cef5SeladKPI. 1660ffa428bfSdsl.Pp 1661ffa428bfSdslThe return value is an error code, or zero for success. 166223e67e66Syamt.It Ft int Fn kauth_cred_getgroups "kauth_cred_t cred" "gid_t *groups" \ 166397427fb0Syamt"size_t ngroups" "enum uio_seg seg" 16641674cef5SeladCopy 16651674cef5Selad.Ar ngroups 16661674cef5Seladgroups from the group list in 16671674cef5Selad.Ar cred 16681674cef5Seladto the buffer pointed to by 16691674cef5Selad.Ar groups . 167097427fb0Syamt.Ar seg 167197427fb0Syamtshould be either 1672ffa428bfSdsl.Dv UIO_USERSPACE 1673ffa428bfSdslor 1674ffa428bfSdsl.Dv UIO_SYSSPACE 1675ffa428bfSdslindicating whether 1676ffa428bfSdsl.Ar groups 1677ffa428bfSdslis a user or kernel space address. 16781674cef5Selad.Pp 1679ffa428bfSdslThe return value is an error code, or zero for success. 16801674cef5Selad.El 1681c439bcfeSelad.Ss Credential Private Data 16821674cef5Selad.Nm 1683c439bcfeSeladprovides an interface to allow attaching security-model private data to 1684c439bcfeSeladcredentials. 1685c439bcfeSelad.Pp 1686c439bcfeSeladThe use of this interface has two parts that can be divided to direct and 1687c439bcfeSeladindirect control of the private-data. 1688c439bcfeSeladDirectly controlling the private data is done by using the below routines, 1689c439bcfeSeladwhile the indirect control is often dictated by events such as process 1690c439bcfeSeladfork, and is handled by listening on the credentials scope (see above). 1691c439bcfeSelad.Pp 1692c439bcfeSeladAttaching private data to credentials works by registering a key to serve 1693c439bcfeSeladas a unique identifier, distinguishing various sets of private data that 1694c439bcfeSeladmay be associated with the credentials. 1695c439bcfeSeladRegistering, and deregistering, a key is done by using these routines: 1696925e8d03Sjoerg.Bl -tag -width compact 1697536626ebScheusov.It Ft int Fn kauth_register_key "secmodel_t sm" "kauth_key_t *keyp" 1698536626ebScheusovRegister new key for private data for security model 1699536626ebScheusov.Ar sm . 1700c439bcfeSelad.Ar keyp 1701c439bcfeSeladwill be used to return the key to be used in further calls. 1702c439bcfeSelad.Pp 1703c439bcfeSeladThe function returns 0 on success and an error code (see 1704c439bcfeSelad.Xr errno 2 ) 1705c439bcfeSeladon failure. 1706c439bcfeSelad.It Ft int Fn kauth_deregister_key "kauth_key_t key" 1707c439bcfeSeladDeregister private data key 1708c439bcfeSelad.Ar key . 1709c439bcfeSelad.El 1710c439bcfeSelad.Pp 1711c439bcfeSeladOnce registered, private data may be manipulated by the following routines: 1712925e8d03Sjoerg.Bl -tag -width compact 1713c439bcfeSelad.It Ft void Fn kauth_cred_setdata "kauth_cred_t cred" "kauth_key_t key" \ 1714c439bcfeSelad"void *data" 1715c439bcfeSeladSet private data for 1716c439bcfeSelad.Ar key 1717c439bcfeSeladin 1718c439bcfeSelad.Ar cred 1719c439bcfeSeladto be 1720c439bcfeSelad.Ar data . 1721c439bcfeSelad.It Ft void * Fn kauth_cred_getdata "kauth_cred_t cred" "kauth_key_t key" 1722c439bcfeSeladRetrieve private data for 1723c439bcfeSelad.Ar key 1724c439bcfeSeladin 1725c439bcfeSelad.Ar cred . 1726c439bcfeSelad.El 1727c439bcfeSelad.Pp 1728c439bcfeSeladNote that it is required to use the above routines every time the private 1729c439bcfeSeladdata is changed, i.e., using 1730c439bcfeSelad.Fn kauth_cred_getdata 1731c439bcfeSeladand later modifying the private data should be accompanied by a call to 1732c439bcfeSelad.Fn kauth_cred_setdata 1733c439bcfeSeladwith the 1734c439bcfeSelad.Dq new 1735c439bcfeSeladprivate data. 1736c439bcfeSelad.Ss Credential Inheritance and Reference Counting 1737c439bcfeSelad.Nm 1738c439bcfeSeladprovides an interface for handling shared credentials. 17391674cef5Selad.Pp 17401674cef5SeladWhen a 17411674cef5Selad.Ft kauth_cred_t 17421674cef5Seladis first allocated, its reference count is set to 1. 17431674cef5SeladHowever, with time, its reference count can grow as more objects (processes, 17445ed2f11fSadLWPs, files, etc.) reference it. 17451674cef5Selad.Pp 17466df6f0eaSeladThe following routines are available for managing credentials reference 1747c439bcfeSeladcounting: 1748925e8d03Sjoerg.Bl -tag -width compact 1749*0f335007Sad.It Ft kauth_cred_t Fn kauth_cred_hold "kauth_cred_t cred" 17501674cef5SeladIncreases reference count to 17511674cef5Selad.Ar cred 1752*0f335007Sadby one and returns 1753*0f335007Sad.Ar cred 1754*0f335007Sadverbatim. 17551674cef5Selad.It Ft void Fn kauth_cred_free "kauth_cred_t cred" 17561674cef5SeladDecreases the reference count to 17571674cef5Selad.Ar cred 17581674cef5Seladby one. 17591674cef5Selad.Pp 17601674cef5SeladIf the reference count dropped to zero, the memory used by 17611674cef5Selad.Ar cred 1762c439bcfeSeladwill be freed. 17631674cef5Selad.El 1764c439bcfeSelad.Pp 1765c439bcfeSeladCredential inheritance happens during a 1766c439bcfeSelad.Xr fork 2 , 1767c439bcfeSeladand is handled by the following function: 1768c439bcfeSelad.Pp 1769c439bcfeSelad.Ft void Fn kauth_proc_fork "struct proc *parent" "struct proc *child" 1770c439bcfeSelad.Pp 1771c439bcfeSeladWhen called, it references the parent's credentials from the child, 1772c439bcfeSeladand calls the credentials scope's hook with the 1773c439bcfeSelad.Dv KAUTH_CRED_FORK 1774c439bcfeSeladaction to allow security model-specific handling of the inheritance 1775c439bcfeSeladto take place. 17761674cef5Selad.Ss Credentials Memory Management 17771674cef5SeladData-structures for credentials, listeners, and scopes are allocated from 17781674cef5Seladmemory pools managed by the 17791674cef5Selad.Xr pool 9 17801674cef5Seladsubsystem. 17811674cef5Selad.Pp 17821674cef5SeladThe 17831674cef5Selad.Ft kauth_cred_t 17841674cef5Seladobjects have their own memory management routines: 1785925e8d03Sjoerg.Bl -tag -width compact 17861674cef5Selad.It Ft kauth_cred_t Fn kauth_cred_alloc "void" 17871674cef5SeladAllocates a new 17881674cef5Selad.Ft kauth_cred_t , 17891674cef5Seladinitializes its lock, and sets its reference count to one. 17901674cef5Selad.El 17911674cef5Selad.Ss Conversion Routines 17921674cef5SeladSometimes it might be necessary to convert a 17931674cef5Selad.Ft kauth_cred_t 17946b1bc777Seladto userland's view of credentials, a 17956b1bc777Selad.Ft struct uucred , 17966b1bc777Selador vice versa. 17971674cef5Selad.Pp 17981674cef5SeladThe following routines are available for these cases: 1799925e8d03Sjoerg.Bl -tag -width compact 1800418e5b1cSpooka.It Ft void Fn kauth_uucred_to_cred "kauth_cred_t cred" "const struct uucred *uucred" 18011674cef5SeladConvert userland's view of credentials to a 18021674cef5Selad.Ft kauth_cred_t . 18031674cef5Selad.Pp 18041674cef5SeladThis includes effective user- and group-ids, a number of groups, and a group 18051674cef5Seladlist. 18061674cef5SeladThe reference count is set to one. 18071674cef5Selad.Pp 18081674cef5SeladNote that 18091674cef5Selad.Nm 18101674cef5Seladwill try to copy as many groups as can be held inside a 18111674cef5Selad.Ft kauth_cred_t . 1812418e5b1cSpooka.It Ft void Fn kauth_cred_to_uucred "struct uucred *uucred" "const kauth_cred_t cred" 1813418e5b1cSpookaConvert 1814418e5b1cSpooka.Ft kauth_cred_t 18156b1bc777Seladto userland's view of credentials. 1816418e5b1cSpooka.Pp 18176b1bc777SeladThis includes effective user- and group-ids, a number of groups, and a group 18186b1bc777Seladlist. 18196b1bc777Selad.Pp 18206b1bc777SeladNote that 18216b1bc777Selad.Nm 18226b1bc777Seladwill try to copy as many groups as can be held inside a 18236b1bc777Selad.Ft struct uucred . 18241674cef5Selad.It Ft int Fn kauth_cred_uucmp "kauth_cred_t cred" "struct uucred *uucred" 18251674cef5SeladCompares 18261674cef5Selad.Ar cred 18271674cef5Seladwith the userland credentials in 18281674cef5Selad.Ar uucred . 18291674cef5Selad.Pp 18301674cef5SeladCommon values that will be compared are effective user- and group-ids, and 18311674cef5Seladthe group list. 18321674cef5Selad.El 18331674cef5Selad.Ss Miscellaneous Routines 18341674cef5SeladOther routines provided by 18351674cef5Selad.Nm 18361674cef5Seladare: 1837925e8d03Sjoerg.Bl -tag -width compact 18381674cef5Selad.It Ft void Fn kauth_cred_clone "kauth_cred_t cred1" "kauth_cred_t cred2" 18391674cef5SeladClone credentials from 18401674cef5Selad.Ar cred1 18411674cef5Seladto 18421674cef5Selad.Ar cred2 , 18431674cef5Seladexcept for the lock and reference count. 18441674cef5Selad.It Ft kauth_cred_t Fn kauth_cred_dup "kauth_cred_t cred" 18451674cef5SeladDuplicate 18461674cef5Selad.Ar cred . 18471674cef5Selad.Pp 18481674cef5SeladWhat this routine does is call 18491674cef5Selad.Fn kauth_cred_alloc 18501674cef5Seladfollowed by a call to 18511674cef5Selad.Fn kauth_cred_clone . 18521674cef5Selad.It Ft kauth_cred_t Fn kauth_cred_copy "kauth_cred_t cred" 18531674cef5SeladWorks like 18541674cef5Selad.Fn kauth_cred_dup , 18551674cef5Seladexcept for a few differences. 18561674cef5Selad.Pp 18571674cef5SeladIf 18581674cef5Selad.Ar cred 18591674cef5Seladalready has a reference count of one, it will be returned. 18601674cef5SeladOtherwise, a new 18611674cef5Selad.Ft kauth_cred_t 18621674cef5Seladwill be allocated and the credentials from 18631674cef5Selad.Ar cred 18641674cef5Seladwill be cloned to it. 18651674cef5SeladLast, a call to 18661674cef5Selad.Fn kauth_cred_free 18671674cef5Seladfor 18681674cef5Selad.Ar cred 18691674cef5Seladwill be done. 18701674cef5Selad.It Ft kauth_cred_t Fn kauth_cred_get "void" 18715ed2f11fSadReturn the credentials associated with the current LWP. 187262b12952SriastradhThis does not change the reference count of the resulting 187362b12952Sriastradh.Ft kauth_cred_t 187462b12952Sriastradhobject. 18751674cef5Selad.El 18761674cef5Selad.Ss Scope Management 18771674cef5Selad.Nm 18781674cef5Seladprovides routines to manage the creation and deletion of scopes on the 18791674cef5Seladsystem. 18801674cef5Selad.Pp 18811674cef5SeladNote that the built-in scopes, the 18821674cef5Selad.Dq generic 18831674cef5Seladscope and the 18841674cef5Selad.Dq process 18851674cef5Seladscope, can't be deleted. 1886925e8d03Sjoerg.Bl -tag -width compact 18871674cef5Selad.It Ft kauth_scope_t Fn kauth_register_scope "const char *id" \ 18881674cef5Selad"kauth_scope_callback_t cb" "void *cookie" 18891674cef5SeladRegister a new scope on the system. 18901674cef5Selad.Ar id 18911674cef5Seladis the name of the scope, usually in reverse DNS-like notation. 18921674cef5SeladFor example, 18931674cef5Selad.Dq org.netbsd.kauth.myscope . 18941674cef5Selad.Ar cb 18951674cef5Seladis the default listener, to which authorization requests for this scope 18961674cef5Seladwill be dispatched to. 18971674cef5Selad.Ar cookie 18981674cef5Seladis optional user-data that will be passed to all listeners 18991674cef5Seladduring authorization on the scope. 19001674cef5Selad.It Ft void Fn kauth_deregister_scope "kauth_scope_t scope" 19011674cef5SeladDeregister 19021674cef5Selad.Ar scope 1903c6e8423fSeladfrom the scopes available on the system, and free the 1904c6e8423fSelad.Ft kauth_scope_t 1905c6e8423fSeladobject 1906c6e8423fSelad.Ar scope . 19071674cef5Selad.El 19081674cef5Selad.Ss Listener Management 19091674cef5SeladListeners in 19101674cef5Selad.Nm 19111674cef5Seladare authorization callbacks that are called during an authorization 19121674cef5Seladrequest in the scope which they belong to. 19131674cef5Selad.Pp 19141674cef5SeladWhen an authorization request is made, all listeners associated with 19151674cef5Selada scope are called to allow, deny, or defer the request. 19161674cef5Selad.Pp 19171674cef5SeladIt is enough for one listener to deny the request in order for the 19181674cef5Seladrequest to be denied; but all listeners are called during an authorization 19191674cef5Seladprocess none-the-less. 19201674cef5SeladAll listeners are required to allow the request for it to be granted, 192188f86411Sriastradhand in a case where all listeners defer the request \(em leaving the 192288f86411Sriastradhdecision for other listeners \(em the request is denied. 19231674cef5Selad.Pp 19241674cef5SeladThe following KPI is provided for the management of listeners: 1925925e8d03Sjoerg.Bl -tag -width compact 19261674cef5Selad.It Ft kauth_listener_t Fn kauth_listen_scope "const char *id" \ 19271674cef5Selad"kauth_scope_callback_t cb" "void *cookie" 19281674cef5SeladCreate a new listener on the scope with the id 19291674cef5Selad.Ar id , 19301674cef5Seladsetting the default listener to 19311674cef5Selad.Ar cb . 1932c6e8423fSelad.Ar cookie 1933c6e8423fSeladis optional user-data that will be passed to the listener when called 1934c6e8423fSeladduring an authorization request. 19351674cef5Selad.It Ft void Fn kauth_unlisten_scope "kauth_listener_t listener" 1936c6e8423fSeladRemoves 19371674cef5Selad.Ar listener 1938c6e8423fSeladfrom the scope which it belongs to, ensuring it won't be called again, 1939c6e8423fSeladand frees the 1940c6e8423fSelad.Ft kauth_listener_t 1941c6e8423fSeladobject 1942c6e8423fSelad.Ar listener . 19431674cef5Selad.El 19441674cef5Selad.Pp 19451674cef5Selad.Nm 19461674cef5Seladprovides no means for synchronization within listeners. 1947ea9e4b37SmbalmerIt is the programmer's responsibility to make sure data used by the 19481674cef5Seladlistener is properly locked during its use, as it can be accessed 19491674cef5Seladsimultaneously from the same listener called multiple times. 19501674cef5SeladIt is also the programmer's responsibility to do garbage collection after 19511674cef5Seladthe listener, possibly freeing any allocated data it used. 19521674cef5Selad.Pp 19531674cef5SeladThe common method to do the above is by having a reference count to 19541674cef5Seladeach listener. 195588f86411SriastradhOn entry to the listener, this reference count should be raised; on 195688f86411Sriastradhexit, lowered. 19571674cef5Selad.Pp 19581674cef5SeladDuring the removal of a listener, first 19591674cef5Selad.Fn kauth_scope_unlisten 19601674cef5Seladshould be called to make sure the listener code will not be entered in 19611674cef5Seladthe future. 19621674cef5SeladThen, the code should wait (possibly sleeping) until the reference count 19631674cef5Seladdrops to zero. 19641674cef5SeladWhen that happens, it is safe to do the final cleanup. 19655fed711bSelad.Pp 1966686626bdSeladListeners might sleep, so no locks can be held when calling an authorization 1967686626bdSeladwrapper. 1968cbaf7914Selad.Sh EXAMPLES 1969cbaf7914SeladOlder code had no abstraction of the security model, so most privilege 1970cbaf7914Seladchecks looked like this: 1971cbaf7914Selad.Bd -literal -offset indent 197201869ca4Swizif (suser(cred, &acflag) == 0) 1973cbaf7914Selad /* allow privileged operation */ 1974cbaf7914Selad.Ed 1975cbaf7914Selad.Pp 1976cbaf7914SeladUsing the new interface, you must ask for a specific privilege explicitly. 1977cbaf7914SeladFor example, checking whether it is possible to open a socket would look 1978cbaf7914Seladsomething like this: 1979cbaf7914Selad.Bd -literal -offset indent 1980cbaf7914Seladif (kauth_authorize_network(cred, KAUTH_NETWORK_SOCKET, 1981cbaf7914Selad KAUTH_REQ_NETWORK_SOCKET_OPEN, PF_INET, SOCK_STREAM, 1982cbaf7914Selad IPPROTO_TCP) == 0) 1983cbaf7914Selad /* allow opening the socket */ 1984cbaf7914Selad.Ed 1985cbaf7914Selad.Pp 1986cbaf7914SeladNote that the 1987cbaf7914Selad.Em securelevel 1988cbaf7914Seladimplications were also integrated into the 1989cbaf7914Selad.Nm 1990cbaf7914Seladframework so you don't have to note anything special in the call to the 1991cbaf7914Seladauthorization wrapper, but rather just have to make sure the security 1992cbaf7914Seladmodel handles the request as you expect it to. 1993cbaf7914Selad.Pp 1994cbaf7914SeladTo do that you can just 1995cbaf7914Selad.Xr grep 1 1996cbaf7914Seladin the relevant security model directory and have a look at the code. 1997cbaf7914Selad.Sh EXTENDING KAUTH 1998cbaf7914SeladAlthough 1999cbaf7914Selad.Nm 2000cbaf7914Seladprovides a large set of both detailed and more or less generic requests, 2001cbaf7914Seladit might be needed eventually to introduce more scopes, actions, or 2002cbaf7914Seladrequests. 2003cbaf7914Selad.Pp 2004cbaf7914SeladAdding a new scope should happen only when an entire subsystem is 2005cbaf7914Seladintroduced and it is assumed other parts of the kernel may want to 2006cbaf7914Seladinterfere with its inner-workings. 2007cbaf7914SeladWhen a subsystem that has the potential of impacting the security 20082d1c9683Seladof the system is introduced, existing security modules must be updated 2009cbaf7914Seladto also handle actions on the newly added scope. 2010cbaf7914Selad.Pp 2011cbaf7914SeladNew actions should be added when sets of operations not covered at all 2012cbaf7914Seladbelong in an already existing scope. 2013cbaf7914Selad.Pp 2014cbaf7914SeladRequests (or sub-actions) can be added as subsets of existing actions 2015cbaf7914Seladwhen an operation that belongs in an already covered area is introduced. 2016cbaf7914Selad.Pp 2017cbaf7914SeladNote that all additions should include updates to this manual, the 2018cbaf7914Seladsecurity models shipped with 2019cbaf7914Selad.Nx , 2020cbaf7914Seladand the example skeleton security model. 202183a5239bSelad.Sh SEE ALSO 202283a5239bSelad.Xr secmodel 9 20231674cef5Selad.Sh HISTORY 20241674cef5SeladThe kernel authorization framework first appeared in Mac OS X 10.4. 20251674cef5Selad.Pp 20261674cef5SeladThe kernel authorization framework in 20271674cef5Selad.Nx 20281674cef5Seladfirst appeared in 2029e1815821Selad.Nx 4.0 , 20301674cef5Seladand is a clean-room implementation based on Apple TN2127, available at 2031bed7cf5aSnjoly.Lk http://developer.apple.com/technotes/tn2005/tn2127.html 20323862950eSelad.Sh NOTES 20333862950eSeladAs 20343862950eSelad.Nm 20353862950eSeladin 20363862950eSelad.Nx 20373862950eSeladis still under active development, it is likely that the ABI, and possibly the 20383862950eSeladAPI, will differ between 20393862950eSelad.Nx 20403862950eSeladversions. 20413862950eSeladDevelopers are to take notice of this fact in order to avoid building code 20423862950eSeladthat expects one version of the ABI and running it in a system with a different 20433862950eSeladone. 20441674cef5Selad.Sh AUTHORS 2045a5684d07Swiz.An Elad Efrat Aq Mt elad@NetBSD.org 20461674cef5Seladimplemented the kernel authorization framework in 20471674cef5Selad.Nx . 20481674cef5Selad.Pp 2049a5684d07Swiz.An Jason R. Thorpe Aq Mt thorpej@NetBSD.org 20501674cef5Seladprovided guidance and answered questions about the Darwin implementation. 2051