1.\" $NetBSD: kauth.9,v 1.114 2023/10/04 22:17:10 ad Exp $ 2.\" 3.\" Copyright (c) 2005, 2006 Elad Efrat <elad@NetBSD.org> 4.\" All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 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. 16.\" 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. 27.\" 28.Dd October 4, 2023 29.Dt KAUTH 9 30.Os 31.Sh NAME 32.Nm kauth 33.Nd kernel authorization framework 34.Sh SYNOPSIS 35.In sys/kauth.h 36.Sh DESCRIPTION 37.Nm , 38or kernel authorization, is the subsystem managing all authorization requests 39inside the kernel. 40It manages user credentials and rights, and can be used 41to implement a system-wide security policy. 42It allows external modules to plug-in the authorization process. 43.Pp 44.Nm 45introduces some new concepts, namely 46.Dq scopes 47and 48.Dq listeners , 49which will be detailed together with other useful information for kernel 50developers in this document. 51.Ss Types 52Some 53.Nm 54types include the following: 55.Bl -tag -width kauth_listener_t 56.It kauth_cred_t 57Representing credentials that can be associated with an object. 58Includes user- and group-ids (real, effective, and save) as well as group 59membership information. 60.It kauth_scope_t 61Describes a scope. 62.It kauth_listener_t 63Describes a listener. 64.El 65.Ss Terminology 66.Nm 67operates in various 68.Dq scopes , 69each scope holding a group of 70.Dq listeners . 71.Pp 72Each listener works as a callback for when an authorization request within the 73scope is made. 74When such a request is made, all listeners on the scope are passed common 75information such as the credentials of the request context, an identifier for 76the requested operation, and possibly other information as well. 77.Pp 78Every listener examines the passed information and returns its decision 79regarding the requested operation. 80It can either return: 81.Pp 82.Bl -tag -width KAUTH_RESULT_ALLOW -compact 83.It Dv KAUTH_RESULT_ALLOW 84The listener allows the operation. 85.It Dv KAUTH_RESULT_DENY 86The listener denies the operation. 87.It Dv KAUTH_RESULT_DEFER 88The listener defers the decision to other listeners. 89.El 90.Pp 91For an operation to be allowed, at least one listener has to return 92.Dv KAUTH_RESULT_ALLOW 93while no other listener returned 94.Dv KAUTH_RESULT_DENY . 95.Pp 96Scopes manage listeners that operate in the same aspect of the system. 97.Ss Kernel Programming Interface 98.Nm 99exports a KPI that allows developers both of 100.Nx 101and third-party products to authorize requests, access and modify credentials, 102create and remove scopes and listeners, and perform other miscellaneous operations on 103credentials. 104.Ss Authorization Requests 105.Nm 106provides a single authorization request routine, which all authorization 107requests go through. 108This routine dispatches the request to the listeners of the appropriate scope, 109together with four optional user-data variables, and returns the augmented 110result. 111.Pp 112It is declared as 113.Pp 114.Ft int Fn kauth_authorize_action "kauth_scope_t scope" "kauth_cred_t cred" \ 115"kauth_action_t op" "void *arg0" "void *arg1" "void *arg2" "void *arg3" 116.Pp 117An authorization request can return one of two possible values: 118.Bl -tag -width ".It Dv 0 Po zero Pc" -compact 119.It Dv 0 Po zero Pc 120indicates success; operation is allowed. 121.It Dv EPERM 122indicates failure; operation is denied. 123See 124.Xr errno 2 . 125.El 126.Pp 127Each scope has its own authorization wrapper, to make it easy to call from various 128places by eliminating the need to specify the scope and/or cast values. 129The authorization wrappers are detailed in each scope's section. 130.Pp 131.Fn kauth_authorize_action 132has several special cases, when it will always allow the request. 133These are for when the request is issued by the kernel itself (indicated by the 134credentials being either 135.Dv NOCRED 136or 137.Dv FSCRED ) , 138or when there was no definitive decision from any of the listeners (i.e., it 139was not explicitly allowed or denied) and no security model was loaded. 140.Ss Generic Scope 141The generic scope, 142.Dq org.netbsd.kauth.generic , 143manages generic authorization requests in the kernel. 144.Pp 145The authorization wrapper for this scope is declared as 146.Pp 147.Ft int Fn kauth_authorize_generic "kauth_cred_t cred" "kauth_action_t op" \ 148"void *arg0" 149.Pp 150The following operations are available for this scope: 151.Bl -tag -width compact 152.It Dv KAUTH_GENERIC_ISSUSER 153Checks whether the credentials belong to the super-user. 154.Pp 155Using this request is strongly discouraged and should only be done as a 156temporary place-holder, as it is breaking the separation between the 157interface for authorization requests from the back-end implementation. 158.El 159.Ss System Scope 160The system scope, 161.Dq org.netbsd.kauth.system , 162manages authorization requests affecting the entire system. 163.Pp 164The authorization wrapper for this scope is declared as 165.Pp 166.Ft int Fn kauth_authorize_system "kauth_cred_t cred" \ 167"kauth_action_t op" "enum kauth_system_req req" "void *arg1" "void *arg2" \ 168"void *arg3" 169.Pp 170The following requests are available for this scope: 171.Bl -tag -width compact 172.It Dv KAUTH_SYSTEM_ACCOUNTING 173Check if enabling/disabling accounting allowed. 174.It Dv KAUTH_SYSTEM_CHROOT 175.Ar req 176can be any of the following: 177.Bl -tag -width compact 178.It Dv KAUTH_REQ_SYSTEM_CHROOT_CHROOT 179Check if calling 180.Xr chroot 2 181is allowed. 182.It Dv KAUTH_REQ_SYSTEM_CHROOT_FCHROOT 183Check if calling 184.Xr fchroot 2 185is allowed. 186.El 187.It Dv KAUTH_SYSTEM_CPU 188Check CPU-manipulation access. 189.Pp 190.Ar req 191can be any of the following: 192.Bl -tag -width compact 193.It Dv KAUTH_REQ_SYSTEM_CPU_SETSTATE 194Set CPU state, including setting it online or offline. 195.El 196.It Dv KAUTH_SYSTEM_DEBUG 197This request concentrates several debugging-related operations. 198.It Dv KAUTH_SYSTEM_DEVMAPPER 199Check if operations on the device mapper 200.Xr dm 4 201device are allowed. 202.It Dv KAUTH_SYSTEM_FILEHANDLE 203Check if file handle operations allowed. 204.It Dv KAUTH_SYSTEM_FS_EXTATTR 205Check if starting, stopping, enabling, or disabling extended attributes 206is allowed. 207.Ar arg1 208is a 209.Ft struct mount * 210of the mount-point on which the operation is performed. 211.It Dv KAUTH_SYSTEM_FS_SNAPSHOT 212Check if setting up a file system snapshot is allowed. 213.Ar arg1 214is a 215.Ft struct mount * 216of the mount-point of which the snapshot is taken, and 217.Ar arg2 218is a 219.Ft struct vnode * 220of the vnode where the snapshot is expected to be. 221.It Dv KAUTH_SYSTEM_FS_QUOTA 222Check if file system quota operations are allowed. 223.Pp 224.Ar arg1 225is a 226.Ft struct mount * 227describing the file system mount in question. 228.Ar req 229can be one of the following: 230.Bl -tag -width compact 231.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_GET 232Check if retrieving quota information is allowed. 233.Pp 234.Ar arg2 235is a 236.Ft uid_t 237with the user-id of the user whose quota information is to be retrieved. 238.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_ONOFF 239Check if turning quota on/off is allowed. 240.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_MANAGE 241Check if managing the quota by setting the quota/quota use is allowed. 242.Pp 243.Ar arg2 244is a 245.Ft uid_t 246with the user-id of the user whose quota/quota use is to be set. 247.It Dv KAUTH_REQ_SYSTEM_FS_QUOTA_NOLIMIT 248Check if bypassing the quota (not enforcing it) is allowed. 249.El 250.It Dv KAUTH_SYSTEM_FS_RESERVEDSPACE 251Check if using the file system reserved space is allowed. 252.It Dv KAUTH_SYSTEM_LFS 253Check if LFS-related operations are allowed. 254.Ar req 255can be one of the following: 256.Bl -tag -width compact 257.It Dv KAUTH_REQ_SYSTEM_LFS_MARKV 258Check if calling 259.Xr lfs_markv 2 260is allowed. 261.It Dv KAUTH_REQ_SYSTEM_LFS_BMAPV 262Check if calling 263.Xr lfs_bmapv 2 264is allowed. 265.It Dv KAUTH_REQ_SYSTEM_LFS_SEGCLEAN 266Check if calling 267.Xr lfs_segclean 2 268is allowed. 269.It Dv KAUTH_REQ_SYSTEM_LFS_SEGWAIT 270Check if calling 271.Xr lfs_segwait 2 272is allowed. 273.It Dv KAUTH_REQ_SYSTEM_LFS_FCNTL 274Check if operations on LFS through 275.Xr fcntl 2 276are allowed. 277.El 278.It Dv KAUTH_SYSTEM_MAP_VA_ZERO 279Check if changing the status of memory mapping of virtual address zero 280is allowed. 281.It Dv KAUTH_SYSTEM_MODULE 282Check if a module request is allowed. 283.Pp 284.Ar arg1 285is the command. 286.It Dv KAUTH_SYSTEM_MKNOD 287Check if creating devices is allowed. 288.It Dv KAUTH_SYSTEM_MOUNT 289Check if mount-related operations are allowed. 290.Pp 291.Ar req 292can be any of the following: 293.Bl -tag -width compact 294.It Dv KAUTH_REQ_SYSTEM_MOUNT_DEVICE 295Check if mounting a device is allowed. 296.Ar arg1 297is a 298.Ft vnode_t * 299of the device, 300.Ar arg2 301is a 302.Ft struct mount * 303with the mount-point, and 304.Ar arg3 305is a 306.Ft mode_t 307with the desired access mode. 308.It Dv KAUTH_REQ_SYSTEM_MOUNT_GET 309Check if retrieving information about a mount is allowed. 310.Ar arg1 311is a 312.Ft struct mount * 313with the mount structure in question, 314.Ar arg2 315is a 316.Ft void * 317with file system specific data, if any. 318.It Dv KAUTH_REQ_SYSTEM_MOUNT_NEW 319Check if mounting a new file system is allowed. 320.Pp 321.Ar arg1 322is the 323.Ft struct vnode * 324on which the file system is to be mounted, 325.Ar arg2 326is an 327.Ft int 328with the mount flags, and 329.Ar arg3 330is a 331.Ft void * 332with file system specific data, if any. 333.It Dv KAUTH_REQ_SYSTEM_MOUNT_UNMOUNT 334Checks if unmounting a file system is allowed. 335.Pp 336.Ar arg1 337is a 338.Ft struct mount * 339with the mount in question. 340.It Dv KAUTH_REQ_SYSTEM_MOUNT_UPDATE 341Checks if updating an existing mount is allowed. 342.Pp 343.Ar arg1 344is the 345.Ft struct mount * 346of the existing mount, 347.Ar arg2 348is an 349.Ft int 350with the new mount flags, and 351.Ar arg3 352is a 353.Ft void * 354with file system specific data, if any. 355.It Dv KAUTH_REQ_SYSTEM_MOUNT_UMAP 356Check if mounting the user and group id remapping file system. 357See 358.Xr mount_umap 8 . 359.El 360.It Dv KAUTH_SYSTEM_MQUEUE 361Check if bypassing permissions on a message queue object are allowed. 362.Ar arg1 363is a 364.Ft mqueue_t * 365describing the message queue. 366.It Dv KAUTH_SYSTEM_PSET 367Check processor-set manipulation. 368.Pp 369.Ar req 370can be any of the following: 371.Bl -tag -width compact 372.It Dv KAUTH_REQ_SYSTEM_PSET_ASSIGN 373Change processor-set processor assignment. 374.It Dv KAUTH_REQ_SYSTEM_PSET_BIND 375Bind an LWP to a processor-set. 376.It Dv KAUTH_REQ_SYSTEM_PSET_CREATE 377Create a processor-set. 378.It Dv KAUTH_REQ_SYSTEM_PSET_DESTROY 379Destroy a processor-set. 380.El 381.It Dv KAUTH_SYSTEM_REBOOT 382Check if rebooting is allowed. 383.It Dv KAUTH_SYSTEM_SETIDCORE 384Check if changing coredump settings for set-id processes is allowed. 385.It Dv KAUTH_SYSTEM_SEMAPHORE 386Check if access to a kernel semaphore is allowed. 387.Ar arg1 388is a 389.Ft ksem_t * 390describing the semaphore. 391.It Dv KAUTH_SYSTEM_SWAPCTL 392Check if privileged 393.Xr swapctl 2 394requests are allowed. 395.It Dv KAUTH_SYSTEM_SYSCTL 396This requests operations related to 397.Xr sysctl 9 . 398.Ar req 399indicates the specific request and can be one of the following: 400.Bl -tag -width compact 401.It Dv KAUTH_REQ_SYSTEM_SYSCTL_ADD 402Check if adding a 403.Xr sysctl 9 404node is allowed. 405.It Dv KAUTH_REQ_SYSTEM_SYSCTL_DELETE 406Check if deleting a 407.Xr sysctl 9 408node is allowed. 409.It Dv KAUTH_REQ_SYSTEM_SYSCTL_DESC 410Check if adding description to a 411.Xr sysctl 9 412node is allowed. 413.It Dv KAUTH_REQ_SYSTEM_SYSCTL_MODIFY 414Check if modifying a 415.Xr sysctl 9 416node variable that doesn't have a custom sysctl helper function is allowed. 417.Pp 418This request might be deprecated in the future. 419.It Dv KAUTH_REQ_SYSTEM_SYSCTL_PRVT 420Check if accessing private 421.Xr sysctl 9 422nodes is allowed. 423.El 424.It Dv KAUTH_SYSTEM_SYSVIPC 425Check SysV IPC related operations. 426.Ar req 427indicates the specific request and can be one of the following: 428.Bl -tag -width compact 429.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_BYPASS 430Check if bypassing a SysV IPC object's permissions is allowed. 431.Ar arg1 432is a 433.Ft struct ipc_perm * 434with the object's permissions and 435.Ar arg2 436is a 437.Ft mode_t 438indicating the requested access mode. 439.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_SHM_LOCK 440Check if shared memory locking is allowed. 441.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_SHM_UNLOCK 442Check if shared memory unlocking is allowed. 443.It Dv KAUTH_REQ_SYSTEM_SYSVIPC_MSGQ_OVERSIZE 444Check if oversizing a message queue is allowed. 445.Ar arg1 446is a 447.Ft msglen_t 448indicating the size of the message buffer, and 449.Ar arg2 450is a 451.Ft msglen_t 452indicating the size of the message queue. 453.El 454.It Dv KAUTH_SYSTEM_TIME 455This request groups time-related operations. 456.Ar req 457can be any of the following: 458.Bl -tag -width compact 459.It Dv KAUTH_REQ_SYSTEM_TIME_ADJTIME 460Check if changing the time using 461.Xr adjtime 2 462is allowed. 463.It Dv KAUTH_REQ_SYSTEM_TIME_NTPADJTIME 464Check if setting the time using 465.Xr ntp_adjtime 2 466is allowed. 467.It Dv KAUTH_REQ_SYSTEM_TIME_SYSTEM 468Check if changing the time (usually via 469.Xr settimeofday 2 ) 470is allowed. 471.Pp 472.Ar arg1 473is a 474.Ft struct timespec * 475with the new time, 476.Ar arg2 477is a 478.Ft struct timeval * 479with the delta from the current time, 480.Ar arg3 481is a 482.Ft bool 483indicating whether the caller is a device context (e.g. 484.Pa /dev/clockctl ) 485or not. 486.It Dv KAUTH_REQ_SYSTEM_TIME_RTCOFFSET 487Check if changing the RTC offset is allowed. 488.It Dv KAUTH_REQ_SYSTEM_TIME_TIMECOUNTERS 489Check if manipulating timecounters is allowed. 490.El 491.It Dv KAUTH_SYSTEM_VERIEXEC 492Check if operations on the 493.Xr veriexec 8 494subsystem are allowed. 495.Ar req 496can be one of the following: 497.Bl -tag -width compact 498.It Dv KAUTH_REQ_SYSTEM_VERIEXEC_ACCESS 499Check if access to the 500.Xr veriexec 8 501subsystem is allowed. 502.It Dv KAUTH_REQ_SYSTEM_VERIEXEC_MODIFY 503Check if modifications to the state of 504.Xr veriexec 8 505are allowed. 506.El 507.El 508.Ss Process Scope 509The process scope, 510.Dq org.netbsd.kauth.process , 511manages authorization requests related to processes in the system. 512.Pp 513The authorization wrapper for this scope is declared as 514.Pp 515.Ft int Fn kauth_authorize_process "kauth_cred_t cred" \ 516"kauth_action_t op" "struct proc *p" "void *arg1" "void *arg2" \ 517"void *arg3" 518.Pp 519The following operations are available for this scope: 520.Bl -tag -width compact 521.It Dv KAUTH_PROCESS_KTRACE 522Checks whether an object with one set of credentials can 523.Xr ktrace 1 524another process 525.Ar p , 526possibly with a different set of credentials. 527.Pp 528If 529.Ar arg1 530is 531.Dv KAUTH_REQ_PROCESS_KTRACE_PERSISTENT , 532this checks if persistent tracing can be done. 533Persistent tracing maintains the trace across a set-user-id/set-group-id 534.Xr exec 3 , 535and normally requires privileged credentials. 536.It Dv KAUTH_PROCESS_PROCFS 537Checks whether object with passed credentials can use 538.Em procfs 539to access process 540.Ar p . 541.Pp 542.Ar arg1 543is the 544.Ft struct pfsnode * 545for the target element in the target process, and 546.Ar arg2 547is the access type, which can be either 548.Dv KAUTH_REQ_PROCESS_PROCFS_READ , 549.Dv KAUTH_REQ_PROCESS_PROCFS_RW , 550or 551.Dv KAUTH_REQ_PROCESS_PROCFS_WRITE , 552indicating 553.Em control , 554.Em read , 555.Em read-write , 556or 557.Em write 558access respectively. 559.It Dv KAUTH_PROCESS_PTRACE 560Checks whether object with passed credentials can use 561.Xr ptrace 2 562to access process 563.Ar p . 564.Pp 565.Ar arg1 566is the 567.Xr ptrace 2 568command. 569.It Dv KAUTH_PROCESS_CANSEE 570Checks whether an object with one set of credentials can access 571information about another process, possibly with a different set of 572credentials. 573.Pp 574.Ar arg1 575indicates the class of information being viewed, and can be either of 576.Dv KAUTH_REQ_PROCESS_CANSEE_ARGS , 577.Dv KAUTH_REQ_PROCESS_CANSEE_ENTRY , 578.Dv KAUTH_REQ_PROCESS_CANSEE_ENV , 579or 580.Dv KAUTH_REQ_PROCESS_CANSEE_OPENFILES . 581.It Dv KAUTH_PROCESS_SCHEDULER_GETAFFINITY 582Checks whether viewing the scheduler affinity is allowed. 583.It Dv KAUTH_PROCESS_SCHEDULER_SETAFFINITY 584Checks whether setting the scheduler affinity is allowed. 585.It Dv KAUTH_PROCESS_SCHEDULER_GETPARAM 586Checks whether viewing the scheduler policy and parameters is allowed. 587.It Dv KAUTH_PROCESS_SCHEDULER_SETPARAM 588Checks whether modifying the scheduler policy and parameters is allowed. 589.It Dv KAUTH_PROCESS_SIGNAL 590Checks whether an object with one set of credentials can post signals 591to another process. 592.Pp 593.Ar p 594is the process the signal is being posted to, and 595.Ar arg1 596is the signal number. 597.It Dv KAUTH_PROCESS_CORENAME 598Controls access to process corename. 599.Pp 600.Ar arg1 601can be 602.Dv KAUTH_REQ_PROCESS_CORENAME_GET 603or 604.Dv KAUTH_REQ_PROCESS_CORENAME_SET , 605indicating access to read or write the process' corename, respectively. 606.Pp 607When modifying the corename, 608.Ar arg2 609holds the new corename to be used. 610.It Dv KAUTH_PROCESS_FORK 611Checks if the process can fork. 612.Ar arg1 613is an 614.Ft int 615indicating how many processes exist on the system at the time of the check. 616.It Dv KAUTH_PROCESS_KEVENT_FILTER 617Checks whether setting a process 618.Xr kevent 2 619filter is allowed. 620.It Dv KAUTH_PROCESS_NICE 621Checks whether the 622.Em nice 623value of 624.Ar p 625can be changed to 626.Ar arg1 . 627.It Dv KAUTH_PROCESS_RLIMIT 628Controls access to process resource limits. 629.Pp 630.Ar arg1 631can be 632.Dv KAUTH_REQ_PROCESS_RLIMIT_GET 633or 634.Dv KAUTH_REQ_PROCESS_RLIMIT_SET , 635indicating access to read or write the process' resource limits, respectively, or 636.Dv KAUTH_REQ_PROCESS_RLIMIT_BYPASS 637to check if the limit enforcement can be bypassed. 638.Pp 639When modifying resource limits, 640.Ar arg2 641is the new value to be used and 642.Ar arg3 643indicates which resource limit is to be modified. 644.It Dv KAUTH_PROCESS_SETID 645Check if changing the user- or group-ids, groups, or login-name for 646.Ar p 647is allowed. 648.It Dv KAUTH_PROCESS_STOPFLAG 649Check if setting the stop flags for 650.Xr exec 3 , 651.Xr exit 3 , 652and 653.Xr fork 2 654is allowed. 655.Pp 656.Ar arg1 657indicates the flag, and can be either 658.Dv P_STOPEXEC , 659.Dv P_STOPEXIT , 660or 661.Dv P_STOPFORK 662respectively. 663.El 664.Ss Network Scope 665The network scope, 666.Dq org.netbsd.kauth.network , 667manages networking-related authorization requests in the kernel. 668.Pp 669The authorization wrapper for this scope is declared as 670.Pp 671.Ft int Fn kauth_authorize_network "kauth_cred_t cred" "kauth_action_t op" \ 672"enum kauth_network_req req" "void *arg1" "void *arg2" "void *arg3" 673.Pp 674The following operations are available for this scope: 675.Bl -tag -width compact 676.It Dv KAUTH_NETWORK_ALTQ 677Checks if an ALTQ operation is allowed. 678.Pp 679.Ar req 680indicates the ALTQ subsystem in question, and can be one of the following: 681.Pp 682.Bl -tag -compact -width compact 683.It Dv KAUTH_REQ_NETWORK_ALTQ_AFMAP 684.It Dv KAUTH_REQ_NETWORK_ALTQ_BLUE 685.It Dv KAUTH_REQ_NETWORK_ALTQ_CBQ 686.It Dv KAUTH_REQ_NETWORK_ALTQ_CDNR 687.It Dv KAUTH_REQ_NETWORK_ALTQ_CONF 688.It Dv KAUTH_REQ_NETWORK_ALTQ_FIFOQ 689.It Dv KAUTH_REQ_NETWORK_ALTQ_HFSC 690.It Dv KAUTH_REQ_NETWORK_ALTQ_JOBS 691.It Dv KAUTH_REQ_NETWORK_ALTQ_PRIQ 692.It Dv KAUTH_REQ_NETWORK_ALTQ_RED 693.It Dv KAUTH_REQ_NETWORK_ALTQ_RIO 694.It Dv KAUTH_REQ_NETWORK_ALTQ_WFQ 695.El 696.It Dv KAUTH_NETWORK_BIND 697Checks if a 698.Xr bind 2 699request is allowed. 700.Pp 701.Ar req 702allows to indicate the type of the request to structure listeners and callers 703easier. 704Supported request types: 705.Bl -tag -width compact 706.It Dv KAUTH_REQ_NETWORK_BIND_PORT 707Checks if binding to a non-privileged/reserved port is allowed. 708.It Dv KAUTH_REQ_NETWORK_BIND_PRIVPORT 709Checks if binding to a privileged/reserved port is allowed. 710.El 711.It Dv KAUTH_NETWORK_FIREWALL 712Checks if firewall-related operations are allowed. 713.Pp 714.Ar req 715indicates the sub-action, and can be one of the following: 716.Bl -tag -width compact 717.It Dv KAUTH_REQ_NETWORK_FIREWALL_FW 718Modification of packet filtering rules. 719.It Dv KAUTH_REQ_NETWORK_FIREWALL_NAT 720Modification of NAT rules. 721.El 722.It Dv KAUTH_NETWORK_INTERFACE 723Checks if network interface-related operations are allowed. 724.Pp 725.Ar arg1 726is (optionally) the 727.Ft struct ifnet * 728associated with the interface. 729.Ar arg2 730is (optionally) an 731.Ft int 732describing the interface-specific operation. 733.Ar arg3 734is (optionally) a pointer to the interface-specific request structure. 735.Ar req 736indicates the sub-action, and can be one of the following: 737.Bl -tag -width compact 738.It Dv KAUTH_REQ_NETWORK_INTERFACE_GET 739Check if retrieving information from the device is allowed. 740.It Dv KAUTH_REQ_NETWORK_INTERFACE_GETPRIV 741Check if retrieving privileged information from the device is allowed. 742.It Dv KAUTH_REQ_NETWORK_INTERFACE_SET 743Check if setting parameters on the device is allowed. 744.It Dv KAUTH_REQ_NETWORK_INTERFACE_SETPRIV 745Check if setting privileged parameters on the device is allowed. 746.It Dv KAUTH_REQ_NETWORK_INTERFACE_FIRMWARE 747Check if manipulating the firmware on a network interface device is allowed. 748.El 749.Pp 750Note that unless the 751.Ft struct ifnet * 752for the interface was passed in 753.Ar arg1 , 754there's no way to tell what structure 755.Ar arg3 756is. 757.It Dv KAUTH_NETWORK_INTERFACE_BRIDGE 758Check if operations performed on the 759.Xr bridge 4 760network interface are allowed. 761.Pp 762.Ar req 763can be one of the following: 764.Bl -tag -width compact 765.It Dv KAUTH_REQ_NETWORK_INTERFACE_BRIDGE_GETPRIV 766Check if getting privileges parameters is allowed. 767.It Dv KAUTH_REQ_NETWORK_INTERFACE_BRIDGE_SETPRIV 768Check if setting privileges parameters is allowed. 769.El 770.It Dv KAUTH_NETWORK_INTERFACE_PPP 771Checks if operations performed on the 772.Xr ppp 4 773network interface are allowed. 774.Pp 775.Ar req 776can be one of the following: 777.Bl -tag -width compact 778.It Dv KAUTH_REQ_NETWORK_INTERFACE_PPP_ADD 779Checks if adding and enabling a 780.Xr ppp 4 781interface to the system is allowed. 782.El 783.It Dv KAUTH_NETWORK_INTERFACE_PVC 784Check if operations performed on a PVC device (e.g. 785.Xr en 4 ) 786are allowed. 787.Ar req 788can be one of the following: 789.Bl -tag -width compact 790.It Dv KAUTH_REQ_NETWORK_INTERFACE_PVC_ADD 791Check if adding a PVC device is allowed. 792.El 793.It Dv KAUTH_NETWORK_INTERFACE_SLIP 794Checks if operations performed on the 795.Xr sl 4 796network interface are allowed. 797.Pp 798.Ar req 799can be one of the following: 800.Bl -tag -width compact 801.It Dv KAUTH_REQ_NETWORK_INTERFACE_SLIP_ADD 802Checks if adding and enabling a 803.Xr sl 4 804interface to the system is allowed. 805.El 806.It Dv KAUTH_NETWORK_INTERFACE_STRIP 807Checks if operations performed on the 808.Xr strip 4 809network interface are allowed. 810.Pp 811.Ar req 812can be one of the following: 813.Bl -tag -width compact 814.It Dv KAUTH_REQ_NETWORK_INTERFACE_STRIP_ADD 815Check if adding and enabling a 816.Xr strip 4 817interface to the system is allowed. 818.El 819.It Dv KAUTH_NETWORK_INTERFACE_TUN 820Checks if operations performed on the 821.Xr tun 4 822network interface are allowed. 823.Pp 824.Ar req 825can be one of the following: 826.Bl -tag -width compact 827.It Dv KAUTH_REQ_NETWORK_INTERFACE_TUN_ADD 828Checks if adding and enabling a 829.Xr tun 4 830interface to the system is allowed. 831.El 832.It Dv KAUTH_NETWORK_IPSEC 833Check if operations related to 834.Xr ipsec 4 835connections are allowed. 836.Ar req 837can be one of the following: 838.Bl -tag -width compact 839.It Dv KAUTH_REQ_NETWORK_IPSEC_BYPASS 840Check if bypassing 841.Xr ipsec 4 842policy is allowed. 843.El 844.It Dv KAUTH_NETWORK_IPV6 845Check if IPv6-specific operations are allowed. 846.Ar req 847can be one of the following: 848.Bl -tag -width compact 849.It Dv KAUTH_REQ_NETWORK_IPV6_HOPBYHOP 850Check if setting hop-by-hop packet options is allowed. 851.It Dv KAUTH_REQ_NETWORK_IPV6_JOIN_MULTICAST 852Check if joining a multicast network is allowed. 853.El 854.It Dv KAUTH_NETWORK_FORWSRCRT 855Checks whether status of forwarding of source-routed packets can be modified 856or not. 857.It Dv KAUTH_NETWORK_NFS 858Check if an NFS related operation is allowed. 859.Pp 860.Ar req 861can be any of the following: 862.Bl -tag -width compact 863.It Dv KAUTH_REQ_NETWORK_NFS_EXPORT 864Check if modifying the NFS export table is allowed. 865.It Dv KAUTH_REQ_NETWORK_NFS_SVC 866Check if access to the NFS 867.Xr nfssvc 2 868syscall is allowed. 869.El 870.It Dv KAUTH_NETWORK_ROUTE 871Checks if a routing-related request is allowed. 872.Pp 873.Ar arg1 874is the 875.Ft struct rt_msghdr * 876for the request. 877.It Dv KAUTH_NETWORK_SMB 878Check if operations related to SMB are allowed. 879.Pp 880.Ar req 881can be one of the following: 882.Bl -tag -width compact 883.It Dv KAUTH_REQ_NETWORK_SMB_SHARE_ACCESS 884Check if accessing an SMB share is allowed. 885.Pp 886.Ar arg1 887is a 888.Ft struct smb_share * 889describing the SMB share, and 890.Ar arg2 891is a 892.Ft mode_t 893with the desired access mode. 894.It Dv KAUTH_REQ_NETWORK_SMB_SHARE_CREATE 895Check if creating an SMB share is allowed. 896.Pp 897.Ar arg1 898is a 899.Ft struct smb_sharespec * 900describing the share to be created. 901.It Dv KAUTH_REQ_NETWORK_SMB_VC_ACCESS 902Check if accessing an SMB VC is allowed. 903.Pp 904.Ar arg1 905is a 906.Ft struct smb_vc * 907describing the SMB VC, and 908.Ar arg2 909is a 910.Ft mode_t 911with the desired access mode. 912.It Dv KAUTH_REQ_NETWORK_SMB_VC_CREATE 913Check if creating an SMB VC is allowed. 914.Pp 915.Ar arg1 916is a 917.Ft struct smb_vcspec * 918describing the VC to be created. 919.El 920.It Dv KAUTH_NETWORK_SOCKET 921Checks if a socket related operation is allowed. 922.Pp 923.Ar req 924allows to indicate the type of the request to structure listeners and callers 925easier. 926Supported request types: 927.Bl -tag -width compact 928.It Dv KAUTH_REQ_NETWORK_SOCKET_RAWSOCK 929Checks if opening a raw socket is allowed. 930.It Dv KAUTH_REQ_NETWORK_SOCKET_OPEN 931Checks if opening a socket is allowed. 932.Ar arg1 , arg2 , 933and 934.Ar arg3 935are all 936.Ft int 937parameters describing the domain, socket type, and protocol, 938respectively. 939.It Dv KAUTH_REQ_NETWORK_SOCKET_CANSEE 940Checks if looking at the socket passed is allowed. 941.Pp 942.Ar arg1 943is a 944.Ft struct socket * 945describing the socket. 946.It Dv KAUTH_REQ_NETWORK_SOCKET_DROP 947Checks if a connection can be dropped. 948.Pp 949.Ar arg1 950is a 951.Ft struct socket * 952describing the socket. 953.It Dv KAUTH_REQ_NETWORK_SOCKET_SETPRIV 954Checks if setting privileged socket options is allowed. 955.Pp 956.Ar arg1 957is a 958.Ft struct socket * 959describing the socket, 960.Ar arg2 961is a 962.Ft u_long 963describing the socket option. 964.El 965.El 966.Ss Machine-dependent Scope 967The machine-dependent (machdep) scope, 968.Dq org.netbsd.kauth.machdep , 969manages machine-dependent authorization requests in the kernel. 970.Pp 971The authorization wrapper for this scope is declared as 972.Pp 973.Ft int Fn kauth_authorize_machdep "kauth_cred_t cred" "kauth_action_t op" \ 974"void *arg0" "void *arg1" "void *arg2" "void *arg3" 975.Pp 976The actions on this scope provide a set that may or may not affect all 977platforms. 978Below is a list of available actions, along with which platforms are affected 979by each. 980.Bl -tag -width compact 981.It Dv KAUTH_MACHDEP_CACHEFLUSH 982Request to flush the whole CPU cache. 983Affects 984.Em m68k 985Linux emulation. 986.It Dv KAUTH_MACHDEP_CPU_UCODE_APPLY 987Request to apply a CPU microcode to a CPU. 988This is related to 989.Em CPU_UCODE , 990see 991.Xr options 4 . 992Affects 993.Em i386 994and 995.Em xen . 996.It Dv KAUTH_MACHDEP_IOPERM_GET 997Request to get the I/O permission level. 998Affects 999.Em amd64 , 1000.Em i386 , 1001.Em xen . 1002.It Dv KAUTH_MACHDEP_IOPERM_SET 1003Request to set the I/O permission level. 1004Affects 1005.Em amd64 , 1006.Em i386 , 1007.Em xen . 1008.It Dv KAUTH_MACHDEP_IOPL 1009Request to set the I/O privilege level. 1010Affects 1011.Em amd64 , 1012.Em i386 , 1013.Em xen . 1014.It Dv KAUTH_MACHDEP_LDT_GET 1015Request to get the LDT (local descriptor table). 1016Affects 1017.Em amd64 , 1018.Em i386 , 1019.Em xen . 1020.It Dv KAUTH_MACHDEP_LDT_SET 1021Request to set the LDT (local descriptor table). 1022Affects 1023.Em amd64 , 1024.Em i386 , 1025.Em xen . 1026.It Dv KAUTH_MACHDEP_MTRR_GET 1027Request to get the MTRR (memory type range registers). 1028Affects 1029.Em amd64 , 1030.Em i386 , 1031.Em xen . 1032.It Dv KAUTH_MACHDEP_MTRR_SET 1033Request to set the MTRR (memory type range registers). 1034Affects 1035.Em amd64 , 1036.Em i386 , 1037.Em xen . 1038.It Dv KAUTH_MACHDEP_NVRAM 1039Request to access (read/write) the NVRAM. 1040Affects 1041.Em i386 . 1042.It Dv KAUTH_MACHDEP_PXG 1043Request to start or stop the 1044.Xr pxg 4 1045CPU. 1046.Ar arg0 1047is 1048.Ft true 1049or 1050.Ft false , 1051respectively. 1052Affects 1053.Em pmax . 1054.It Dv KAUTH_MACHDEP_UNMANAGEDMEM 1055Request to access unmanaged memory. 1056Affects 1057.Em alpha , 1058.Em amd64 , 1059.Em arm , 1060.Em i386 , 1061.Em powerpc , 1062.Em sh3 , 1063.Em vax , 1064.Em x68k , 1065.Em xen . 1066.El 1067.Ss Device Scope 1068The device scope, 1069.Dq org.netbsd.kauth.device , 1070manages authorization requests related to devices on the system. 1071Devices can be, for example, terminals, tape drives, Bluetooth accessories, and 1072any other hardware. 1073Network devices specifically are handled by the 1074.Em network 1075scope. 1076.Pp 1077In addition to the standard authorization wrapper: 1078.Pp 1079.Ft int Fn kauth_authorize_device "kauth_cred_t cred" "kauth_action_t op" \ 1080"void *arg0" "void *arg1" "void *arg2" "void *arg3" 1081.Pp 1082this scope provides authorization wrappers for various device types. 1083.Pp 1084.Ft int Fn kauth_authorize_device_tty "kauth_cred_t cred" "kauth_action_t op" \ 1085"struct tty *tty" 1086.Pp 1087Authorizes requests for 1088.Em terminal devices 1089on the system. 1090The third argument, 1091.Ar tty , 1092is the terminal device in question. 1093It is passed to the listener as 1094.Ar arg0 . 1095The second argument, 1096.Ar op , 1097is the action and can be one of the following: 1098.Bl -tag -width compact 1099.It Dv KAUTH_DEVICE_TTY_OPEN 1100Open the terminal device pointed to by 1101.Ar tty . 1102.It Dv KAUTH_DEVICE_TTY_PRIVSET 1103Set privileged settings on the terminal device pointed to by 1104.Ar tty . 1105.It Dv KAUTH_DEVICE_TTY_STI 1106Use the 1107.Dq TIOCSTI 1108device 1109.Xr ioctl 2 , 1110allowing to inject characters into the terminal buffer, simulating terminal 1111input. 1112.It Dv KAUTH_DEVICE_TTY_VIRTUAL 1113Control the virtual console. 1114.Ar tty 1115is the current console 1116.Xr tty 4 . 1117.El 1118.Pp 1119.Ft int Fn kauth_authorize_device_spec "kauth_cred_t cred" \ 1120"enum kauth_device_req req" "struct vnode *vp" 1121.Pp 1122Authorizes requests for 1123.Em special files , 1124usually disk devices, but also direct memory access, on the system. 1125.Pp 1126It passes 1127.Dv KAUTH_DEVICE_RAWIO_SPEC 1128as the action to the listener, and accepts two arguments. 1129.Ar req , 1130passed to the listener as 1131.Ar arg0 , 1132is access requested, and can be one of 1133.Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_READ , 1134.Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_WRITE , 1135or 1136.Dv KAUTH_REQ_DEVICE_RAWIO_SPEC_RW , 1137representing read, write, or both read/write access respectively. 1138.Ar vp 1139is the vnode of the special file in question, and is passed to the listener as 1140.Ar arg1 . 1141.Pp 1142Keep in mind that it is the responsibility of the security model developer to 1143check whether the underlying device is a disk or the system memory, using 1144.Fn iskmemdev : 1145.Bd -literal -offset indent 1146if ((vp->v_type == VCHR) && 1147 iskmemdev(vp->v_un.vu_specinfo->si_rdev)) 1148 /* system memory access */ 1149.Ed 1150.Pp 1151.Ft int Fn kauth_authorize_device_passthru "kauth_cred_t cred" "dev_t dev" \ 1152"u_long mode" "void *data" 1153.Pp 1154Authorizes hardware 1155.Em passthru 1156requests, or user commands passed directly to the hardware. 1157These have the potential of resulting in direct disk and/or memory access. 1158.Pp 1159It passes 1160.Dv KAUTH_DEVICE_RAWIO_PASSTHRU 1161as the action to the listener, and accepts three arguments. 1162.Ar dev , 1163passed as 1164.Ar arg1 1165to the listener, is the device for which the request is made. 1166.Ar mode , 1167passed as 1168.Ar arg0 1169to the listener, is a generic representation of the access mode requested. 1170It can be one or more (binary-OR'd) of the following: 1171.Pp 1172.Bl -tag -width compact -offset indent -compact 1173.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READ 1174.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_READCONF 1175.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITE 1176.It KAUTH_REQ_DEVICE_RAWIO_PASSTHRU_WRITECONF 1177.El 1178.Pp 1179.Ar data , 1180passed as 1181.Ar arg2 1182to the listener, is device-specific data that may be associated with the 1183request. 1184.Ss Bluetooth Devices 1185Authorizing actions relevant to Bluetooth devices is done using the standard 1186authorization wrapper, with the following actions: 1187.Bl -tag -width compact 1188.It KAUTH_DEVICE_BLUETOOTH_BCSP 1189Check if operations on a 1190.Xr bcsp 4 1191device are allowed. 1192.Pp 1193.Ar arg0 1194is an 1195.Ft enum kauth_device_req 1196with one of the following values: 1197.Bl -tag -width compact 1198.It Dv KAUTH_REQ_DEVICE_BLUETOOTH_BCSP_ADD 1199Check if adding and enabling a 1200.Xr bcsp 4 1201device is allowed. 1202.El 1203.It KAUTH_DEVICE_BLUETOOTH_BTUART 1204Check if operations on a 1205.Xr btuart 4 1206device are allowed. 1207.Pp 1208.Ar arg0 1209is an 1210.Ft enum kauth_device_req 1211with one of the following values: 1212.Bl -tag -width compact 1213.It Dv KAUTH_REQ_DEVICE_BLUETOOTH_BTUART_ADD 1214Check if adding and enabling a 1215.Xr btuart 4 1216device is allowed. 1217.El 1218.It KAUTH_DEVICE_BLUETOOTH_RECV 1219Check if a packet can be received from the device. 1220.Pp 1221.Ar arg0 1222is the packet type. 1223For 1224.Dv HCI_CMD_PKT 1225packets, 1226.Ar arg1 1227is the opcode, for 1228.Dv HCI_EVENT_PKT 1229packets, 1230.Ar arg1 1231is the event ID, and for 1232.Dv HCI_ACLDATA_PKT 1233or 1234.Dv HCI_SCODATA_PKT 1235packets, 1236.Ar arg1 1237is the connection handle. 1238.It KAUTH_DEVICE_BLUETOOTH_SEND 1239Check if a packet can be sent to the device. 1240.Pp 1241.Ar arg0 1242is a 1243.Ft struct hci_unit * 1244describing the HCI unit, 1245.Ar arg1 1246is a 1247.Ft hci_cmd_hdr_t * 1248describing the packet header. 1249.It KAUTH_DEVICE_BLUETOOTH_SETPRIV 1250Check if privileged settings can be changed. 1251.Pp 1252.Ar arg0 1253is a 1254.Ft struct hci_unit * 1255describing the HCI unit, 1256.Ar arg1 1257is a 1258.Ft struct btreq * 1259describing the request, and 1260.Ar arg2 1261is a 1262.Ft u_long 1263describing the command. 1264.El 1265.Ss Kernel random device 1266Authorization actions relevant to the kernel random device, 1267.Xr rnd 4 , 1268is done using the standard authorization wrapper, with the following actions: 1269.Bl -tag -width compact 1270.It KAUTH_DEVICE_RND_ADDDATA 1271Check if adding data to the entropy pool is allowed. 1272.It KAUTH_DEVICE_RND_GETPRIV 1273Check if privileged settings and information can be retrieved. 1274.It KAUTH_DEVICE_RND_SETPRIV 1275Check if privileged settings can be changed. 1276.El 1277.Ss Wscons devices 1278Authorization actions relevant to 1279.Xr wscons 4 1280are done using the standard authorization wrapper, with the following actions: 1281.Bl -tag -width compact 1282.It KAUTH_DEVICE_WSCONS_KEYBOARD_BELL 1283Check if setting the default bell is allowed. 1284.It KAUTH_DEVICE_WSCONS_KEYBOARD_KEYREPEAT 1285Check if setting the default key-repeat is allowed. 1286.El 1287.Ss Vnode Scope 1288The vnode scope, 1289.Dq org.netbsd.kauth.vnode , 1290authorizes operations made on vnodes representing file system objects. 1291.Pp 1292The authorization wrapper for this scope is declared as 1293.Pp 1294.Ft int Fn kauth_authorize_vnode "kauth_cred_t cred" "kauth_action_t action" \ 1295"vnode_t *vp" "vnode_t *dvp" "int fs_decision" 1296.Pp 1297This scope is heavily used in file system code and can potentially affect 1298system-wide performance. 1299Therefore, there are several things developers should know when using it. 1300.Pp 1301First, the 1302.Ar action 1303parameter is a bit-mask and multiple actions can be binary-OR'd and authorized 1304in a single call. 1305Two helper functions help generate the 1306.Ar action 1307value for a couple of common cases: translating file system access to a 1308.Nm 1309action and checking access to a vnode. 1310.Pp 1311The first, 1312.Fn kauth_mode_to_action "mode_t access_mode" , 1313and returns a 1314.Ft kauth_action_t 1315representing the desired access modes. 1316Another function, 1317.Fn kauth_access_action "mode_t access_mode" "enum vtype v_type" \ 1318"mode_t file_mode" , 1319returns a 1320.Ft kauth_action_t 1321suitable for use in many file system 1322.Xr access 2 1323implementations. 1324It calls the aforementioned 1325.Fn kauth_mode_to_action , 1326but before returning also adds the 1327.Dv KAUTH_VNODE_IS_EXEC 1328flag if needed. 1329See below for the meaning of this flag and how its necessity is 1330determined. 1331.Pp 1332Second, it is recommended to be very careful with adding listeners on this 1333scope. 1334A special parameter, 1335.Ar fs_decision , 1336allows different file systems to instrument different policies without adding 1337their own listener. 1338This parameter is special because it also serves as a fall-back decision when 1339no 1340.Xr secmodel 9 1341is present to prevent a fail-open scenario. 1342It can take either an 1343.Xr errno 2 1344value or 1345.Dq KAUTH_VNODE_REMOTEFS , 1346indicating that the file system on which the authorization is made is remote 1347and cannot provide us with a fall-back decision. 1348In this case, 1349.Nm 1350can only short-circuit the request but the file system will have the last 1351word if there is no definitive allow or deny decision. 1352.Pp 1353The value of 1354.Ar fs_decision 1355can be hard-coded or determined by calling an internal function implementing a 1356policy. 1357For the latter case, 1358.Xr genfs 9 1359provides a set of helper functions that implement common policies that 1360file systems can use. 1361The calling convention is as follows: 1362.Bd -literal -offset indent 1363int error; 1364 1365error = kauth_authorize_vnode(..., genfs_can_foo(...)); 1366.Ed 1367.Pp 1368Actions on the vnode scope are of two types: operations and flags. 1369An operation is similar in concept to actions on other scopes in the sense 1370that it represents an operation desired by the caller. 1371A flag is an indicator of additional information about the vnode that 1372a file system can set in order to allow the listener to make a more 1373informed decision. 1374.Pp 1375Actions include the following: 1376.Bl -tag -width compact -offset indent 1377.It KAUTH_VNODE_READ_DATA 1378Read file data. 1379.It KAUTH_VNODE_LIST_DIRECTORY 1380Read directory listing. 1381Identical to the above. 1382.It KAUTH_VNODE_WRITE_DATA 1383Write file data. 1384.It KAUTH_VNODE_ADD_FILE 1385Add a file to a directory. 1386Identical to the above. 1387.It KAUTH_VNODE_EXECUTE 1388Execute a file. 1389.It KAUTH_VNODE_SEARCH 1390Search (enter) a directory. 1391Identical to the above. 1392.It KAUTH_VNODE_DELETE 1393Delete a file. 1394.It KAUTH_VNODE_APPEND_DATA 1395Append data to a file. 1396.It KAUTH_VNODE_ADD_SUBDIRECTORY 1397Add a subdirectory to a directory. 1398Identical to the above. 1399.It KAUTH_VNODE_READ_TIMES 1400Read the created, last accessed, and last modified times of a file. 1401.It KAUTH_VNODE_WRITE_TIMES 1402Modify the created, last accessed, or last modified times of a file. 1403.It KAUTH_VNODE_READ_FLAGS 1404Read file flags. 1405.It KAUTH_VNODE_WRITE_FLAGS 1406Modify file flags. 1407.It KAUTH_VNODE_READ_SYSFLAGS 1408Read file system flags. 1409.It KAUTH_VNODE_WRITE_SYSFLAGS 1410Modify file system flags. 1411.It KAUTH_VNODE_RENAME 1412Rename a file. 1413.It KAUTH_VNODE_CHANGE_OWNERSHIP 1414Change ownership of a file. 1415.It KAUTH_VNODE_READ_SECURITY 1416Read the permissions of a file. 1417.It KAUTH_VNODE_WRITE_SECURITY 1418Change the permissions of a file, for example by using 1419.Xr chmod 2 . 1420.It KAUTH_VNODE_READ_ATTRIBUTES 1421Read attributes of a file. 1422.It KAUTH_VNODE_WRITE_ATTRIBUTES 1423Modify attributes of a file. 1424.It KAUTH_VNODE_READ_EXTATTRIBUTES 1425Read extended attributes of a file. 1426.It KAUTH_VNODE_WRITE_EXTATTRIBUTES 1427Modify extended attributes of a file. 1428.It KAUTH_VNODE_RETAIN_SUID 1429Check if retaining the set-user-id bit on files after 1430.Xr chown 2 1431is allowed. 1432.It KAUTH_VNODE_RETAIN_SGID 1433Check if retaining the set-group-id bit on files after 1434.Xr chown 2 1435is allowed. 1436.It KAUTH_VNODE_REVOKE 1437Revoke a file. 1438.El 1439.Pp 1440Flags include the following: 1441.Bl -tag -width compact -offset indent 1442.It KAUTH_VNODE_IS_EXEC 1443The vnode is executable. 1444.Pp 1445The macro 1446.Fn FS_OBJECT_CAN_EXEC 1447can be used to help determine if this flag should be set. 1448This macro determines a file system object to be executable if it is a 1449directory (in which case we say it is searchable) or if it has at least one 1450executable bit set in its mode. 1451.Pp 1452Setting this flag helps a listener know that a vnode is executable and is used 1453in implementing privileged access to files and directories while maintaining 1454semantics that prevent execution until a file is marked as an executable. 1455An example for using this in listener code is: 1456.Bd -literal -offset indent 1457if (privileged) { 1458 /* Always allow read/write; execute only if executable. */ 1459 if ((action & KAUTH_VNODE_EXECUTE) == 0 || 1460 (action & KAUTH_VNODE_IS_EXEC)) 1461 result = KAUTH_RESULT_ALLOW; 1462} 1463.Ed 1464.Pp 1465Finally, the vnode scope authorization wrapper returns 1466.Er EACCES 1467in case of an error, to maintain file system semantics. 1468File systems can override this value if needed. 1469.It KAUTH_VNODE_HAS_SYSFLAGS 1470The file system object represented by the vnode has system flags set. 1471.It KAUTH_VNODE_ACCESS 1472The authorization is advisory only and no actual operation is to be 1473performed. 1474This is not implemented. 1475.El 1476.Ss Credentials Scope 1477The credentials scope, 1478.Dq org.netbsd.kauth.cred , 1479is a special scope used internally by the 1480.Nm 1481framework to provide hooking to credential-related operations. 1482.Pp 1483It is a 1484.Dq notify-only 1485scope, allowing hooking operations such as initialization of new credentials, 1486credential inheritance during a fork, and copying and freeing of credentials. 1487The main purpose for this scope is to give a security model a way to control 1488the aforementioned operations, especially in cases where the credentials 1489hold security model-private data. 1490.Pp 1491Notifications are made using the following function, which is internal to 1492.Nm : 1493.Pp 1494.Ft int Fn kauth_cred_hook "kauth_cred_t cred" "kauth_action_t action" \ 1495"void *arg0" "void *arg1" 1496.Pp 1497With the following actions: 1498.Bl -tag -width compact 1499.It Dv KAUTH_CRED_COPY 1500The credentials are being copied. 1501.Ar cred 1502are the credentials of the lwp context doing the copy, and 1503.Ar arg0 1504and 1505.Ar arg1 1506are both 1507.Ft kauth_cred_t 1508representing the 1509.Dq from 1510and 1511.Dq to 1512credentials, respectively. 1513.It Dv KAUTH_CRED_FORK 1514The credentials are being inherited from a parent to a child process during a 1515fork. 1516.Pp 1517.Ar cred 1518are the credentials of the lwp context doing the fork, and 1519.Ar arg0 1520and 1521.Ar arg1 1522are both 1523.Ft struct proc * 1524of the parent and child processes, respectively. 1525.It Dv KAUTH_CRED_CHROOT 1526The credentials in cred belong to a process whose root directory is 1527changed through 1528.Fn change_root 1529(see 1530.Xr vfs 9 ). 1531.Pp 1532.Ar Arg0 1533is the new 1534.Ft struct cwdinfo * 1535of the process. 1536.It Dv KAUTH_CRED_FREE 1537The credentials in 1538.Ar cred 1539are being freed. 1540.It Dv KAUTH_CRED_INIT 1541The credentials in 1542.Ar cred 1543are being initialized. 1544.El 1545.Pp 1546Since this is a notify-only scope, all listeners are required to return 1547.Dv KAUTH_RESULT_ALLOW . 1548.Ss Credentials Accessors and Mutators 1549.Nm 1550has a variety of accessor and mutator routines to handle 1551.Ft kauth_cred_t 1552objects. 1553.Pp 1554The following routines can be used to access and modify the user- and 1555group-ids in a 1556.Ft kauth_cred_t : 1557.Bl -tag -width compact 1558.It Ft uid_t Fn kauth_cred_getuid "kauth_cred_t cred" 1559Returns the real user-id from 1560.Ar cred . 1561.It Ft uid_t Fn kauth_cred_geteuid "kauth_cred_t cred" 1562Returns the effective user-id from 1563.Ar cred . 1564.It Ft uid_t Fn kauth_cred_getsvuid "kauth_cred_t cred" 1565Returns the saved user-id from 1566.Ar cred . 1567.It Ft void Fn kauth_cred_setuid "kauth_cred_t cred" "uid_t uid" 1568Sets the real user-id in 1569.Ar cred 1570to 1571.Ar uid . 1572.It Ft void Fn kauth_cred_seteuid "kauth_cred_t cred" "uid_t uid" 1573Sets the effective user-id in 1574.Ar cred 1575to 1576.Ar uid . 1577.It Ft void Fn kauth_cred_setsvuid "kauth_cred_t cred" "uid_t uid" 1578Sets the saved user-id in 1579.Ar cred 1580to 1581.Ar uid . 1582.It Ft gid_t Fn kauth_cred_getgid "kauth_cred_t cred" 1583Returns the real group-id from 1584.Ar cred . 1585.It Ft gid_t Fn kauth_cred_getegid "kauth_cred_t cred" 1586Returns the effective group-id from 1587.Ar cred . 1588.It Ft gid_t Fn kauth_cred_getsvgid "kauth_cred_t cred" 1589Returns the saved group-id from 1590.Ar cred . 1591.It Ft void Fn kauth_cred_setgid "kauth_cred_t cred" "gid_t gid" 1592Sets the real group-id in 1593.Ar cred 1594to 1595.Ar gid . 1596.It Ft void Fn kauth_cred_setegid "kauth_cred_t cred" "gid_t gid" 1597Sets the effective group-id in 1598.Ar cred 1599to 1600.Ar gid . 1601.It Ft void Fn kauth_cred_setsvgid "kauth_cred_t cred" "gid_t gid" 1602Sets the saved group-id in 1603.Ar cred 1604to 1605.Ar gid . 1606.It Ft u_int Fn kauth_cred_getrefcnt "kauth_cred_t cred" 1607Return the reference count for 1608.Ar cred . 1609.El 1610.Pp 1611The following routines can be used to access and modify the group 1612list in a 1613.Ft kauth_cred_t : 1614.Bl -tag -width compact 1615.It Ft int Fn kauth_cred_ismember_gid "kauth_cred_t cred" "gid_t gid" \ 1616"int *resultp" 1617Checks if the group-id 1618.Ar gid 1619is a member in the group list of 1620.Ar cred . 1621.Pp 1622If it is, 1623.Ar resultp 1624will be set to one, otherwise, to zero. 1625.Pp 1626The return value is an error code, or zero for success. 1627.It Ft u_int Fn kauth_cred_ngroups "kauth_cred_t cred" 1628Return the number of groups in the group list of 1629.Ar cred . 1630.It Ft gid_t Fn kauth_cred_group "kauth_cred_t cred" "u_int idx" 1631Return the group-id of the group at index 1632.Ar idx 1633in the group list of 1634.Ar cred . 1635.It Ft int Fn kauth_cred_setgroups "kauth_cred_t cred" "const gid_t *groups" \ 1636"size_t ngroups" "uid_t gmuid" "enum uio_seg seg" 1637Copy 1638.Ar ngroups 1639groups from array pointed to by 1640.Ar groups 1641to the group list in 1642.Ar cred , 1643adjusting the number of groups in 1644.Ar cred 1645appropriately. 1646.Ar seg 1647should be either 1648.Dv UIO_USERSPACE 1649or 1650.Dv UIO_SYSSPACE 1651indicating whether 1652.Ar groups 1653is a user or kernel space address. 1654.Pp 1655Any groups remaining will be set to an invalid value. 1656.Pp 1657.Ar gmuid 1658is unused for now, and to maintain interface compatibility with the Darwin 1659KPI. 1660.Pp 1661The return value is an error code, or zero for success. 1662.It Ft int Fn kauth_cred_getgroups "kauth_cred_t cred" "gid_t *groups" \ 1663"size_t ngroups" "enum uio_seg seg" 1664Copy 1665.Ar ngroups 1666groups from the group list in 1667.Ar cred 1668to the buffer pointed to by 1669.Ar groups . 1670.Ar seg 1671should be either 1672.Dv UIO_USERSPACE 1673or 1674.Dv UIO_SYSSPACE 1675indicating whether 1676.Ar groups 1677is a user or kernel space address. 1678.Pp 1679The return value is an error code, or zero for success. 1680.El 1681.Ss Credential Private Data 1682.Nm 1683provides an interface to allow attaching security-model private data to 1684credentials. 1685.Pp 1686The use of this interface has two parts that can be divided to direct and 1687indirect control of the private-data. 1688Directly controlling the private data is done by using the below routines, 1689while the indirect control is often dictated by events such as process 1690fork, and is handled by listening on the credentials scope (see above). 1691.Pp 1692Attaching private data to credentials works by registering a key to serve 1693as a unique identifier, distinguishing various sets of private data that 1694may be associated with the credentials. 1695Registering, and deregistering, a key is done by using these routines: 1696.Bl -tag -width compact 1697.It Ft int Fn kauth_register_key "secmodel_t sm" "kauth_key_t *keyp" 1698Register new key for private data for security model 1699.Ar sm . 1700.Ar keyp 1701will be used to return the key to be used in further calls. 1702.Pp 1703The function returns 0 on success and an error code (see 1704.Xr errno 2 ) 1705on failure. 1706.It Ft int Fn kauth_deregister_key "kauth_key_t key" 1707Deregister private data key 1708.Ar key . 1709.El 1710.Pp 1711Once registered, private data may be manipulated by the following routines: 1712.Bl -tag -width compact 1713.It Ft void Fn kauth_cred_setdata "kauth_cred_t cred" "kauth_key_t key" \ 1714"void *data" 1715Set private data for 1716.Ar key 1717in 1718.Ar cred 1719to be 1720.Ar data . 1721.It Ft void * Fn kauth_cred_getdata "kauth_cred_t cred" "kauth_key_t key" 1722Retrieve private data for 1723.Ar key 1724in 1725.Ar cred . 1726.El 1727.Pp 1728Note that it is required to use the above routines every time the private 1729data is changed, i.e., using 1730.Fn kauth_cred_getdata 1731and later modifying the private data should be accompanied by a call to 1732.Fn kauth_cred_setdata 1733with the 1734.Dq new 1735private data. 1736.Ss Credential Inheritance and Reference Counting 1737.Nm 1738provides an interface for handling shared credentials. 1739.Pp 1740When a 1741.Ft kauth_cred_t 1742is first allocated, its reference count is set to 1. 1743However, with time, its reference count can grow as more objects (processes, 1744LWPs, files, etc.) reference it. 1745.Pp 1746The following routines are available for managing credentials reference 1747counting: 1748.Bl -tag -width compact 1749.It Ft kauth_cred_t Fn kauth_cred_hold "kauth_cred_t cred" 1750Increases reference count to 1751.Ar cred 1752by one and returns 1753.Ar cred 1754verbatim. 1755.It Ft void Fn kauth_cred_free "kauth_cred_t cred" 1756Decreases the reference count to 1757.Ar cred 1758by one. 1759.Pp 1760If the reference count dropped to zero, the memory used by 1761.Ar cred 1762will be freed. 1763.El 1764.Pp 1765Credential inheritance happens during a 1766.Xr fork 2 , 1767and is handled by the following function: 1768.Pp 1769.Ft void Fn kauth_proc_fork "struct proc *parent" "struct proc *child" 1770.Pp 1771When called, it references the parent's credentials from the child, 1772and calls the credentials scope's hook with the 1773.Dv KAUTH_CRED_FORK 1774action to allow security model-specific handling of the inheritance 1775to take place. 1776.Ss Credentials Memory Management 1777Data-structures for credentials, listeners, and scopes are allocated from 1778memory pools managed by the 1779.Xr pool 9 1780subsystem. 1781.Pp 1782The 1783.Ft kauth_cred_t 1784objects have their own memory management routines: 1785.Bl -tag -width compact 1786.It Ft kauth_cred_t Fn kauth_cred_alloc "void" 1787Allocates a new 1788.Ft kauth_cred_t , 1789initializes its lock, and sets its reference count to one. 1790.El 1791.Ss Conversion Routines 1792Sometimes it might be necessary to convert a 1793.Ft kauth_cred_t 1794to userland's view of credentials, a 1795.Ft struct uucred , 1796or vice versa. 1797.Pp 1798The following routines are available for these cases: 1799.Bl -tag -width compact 1800.It Ft void Fn kauth_uucred_to_cred "kauth_cred_t cred" "const struct uucred *uucred" 1801Convert userland's view of credentials to a 1802.Ft kauth_cred_t . 1803.Pp 1804This includes effective user- and group-ids, a number of groups, and a group 1805list. 1806The reference count is set to one. 1807.Pp 1808Note that 1809.Nm 1810will try to copy as many groups as can be held inside a 1811.Ft kauth_cred_t . 1812.It Ft void Fn kauth_cred_to_uucred "struct uucred *uucred" "const kauth_cred_t cred" 1813Convert 1814.Ft kauth_cred_t 1815to userland's view of credentials. 1816.Pp 1817This includes effective user- and group-ids, a number of groups, and a group 1818list. 1819.Pp 1820Note that 1821.Nm 1822will try to copy as many groups as can be held inside a 1823.Ft struct uucred . 1824.It Ft int Fn kauth_cred_uucmp "kauth_cred_t cred" "struct uucred *uucred" 1825Compares 1826.Ar cred 1827with the userland credentials in 1828.Ar uucred . 1829.Pp 1830Common values that will be compared are effective user- and group-ids, and 1831the group list. 1832.El 1833.Ss Miscellaneous Routines 1834Other routines provided by 1835.Nm 1836are: 1837.Bl -tag -width compact 1838.It Ft void Fn kauth_cred_clone "kauth_cred_t cred1" "kauth_cred_t cred2" 1839Clone credentials from 1840.Ar cred1 1841to 1842.Ar cred2 , 1843except for the lock and reference count. 1844.It Ft kauth_cred_t Fn kauth_cred_dup "kauth_cred_t cred" 1845Duplicate 1846.Ar cred . 1847.Pp 1848What this routine does is call 1849.Fn kauth_cred_alloc 1850followed by a call to 1851.Fn kauth_cred_clone . 1852.It Ft kauth_cred_t Fn kauth_cred_copy "kauth_cred_t cred" 1853Works like 1854.Fn kauth_cred_dup , 1855except for a few differences. 1856.Pp 1857If 1858.Ar cred 1859already has a reference count of one, it will be returned. 1860Otherwise, a new 1861.Ft kauth_cred_t 1862will be allocated and the credentials from 1863.Ar cred 1864will be cloned to it. 1865Last, a call to 1866.Fn kauth_cred_free 1867for 1868.Ar cred 1869will be done. 1870.It Ft kauth_cred_t Fn kauth_cred_get "void" 1871Return the credentials associated with the current LWP. 1872This does not change the reference count of the resulting 1873.Ft kauth_cred_t 1874object. 1875.El 1876.Ss Scope Management 1877.Nm 1878provides routines to manage the creation and deletion of scopes on the 1879system. 1880.Pp 1881Note that the built-in scopes, the 1882.Dq generic 1883scope and the 1884.Dq process 1885scope, can't be deleted. 1886.Bl -tag -width compact 1887.It Ft kauth_scope_t Fn kauth_register_scope "const char *id" \ 1888"kauth_scope_callback_t cb" "void *cookie" 1889Register a new scope on the system. 1890.Ar id 1891is the name of the scope, usually in reverse DNS-like notation. 1892For example, 1893.Dq org.netbsd.kauth.myscope . 1894.Ar cb 1895is the default listener, to which authorization requests for this scope 1896will be dispatched to. 1897.Ar cookie 1898is optional user-data that will be passed to all listeners 1899during authorization on the scope. 1900.It Ft void Fn kauth_deregister_scope "kauth_scope_t scope" 1901Deregister 1902.Ar scope 1903from the scopes available on the system, and free the 1904.Ft kauth_scope_t 1905object 1906.Ar scope . 1907.El 1908.Ss Listener Management 1909Listeners in 1910.Nm 1911are authorization callbacks that are called during an authorization 1912request in the scope which they belong to. 1913.Pp 1914When an authorization request is made, all listeners associated with 1915a scope are called to allow, deny, or defer the request. 1916.Pp 1917It is enough for one listener to deny the request in order for the 1918request to be denied; but all listeners are called during an authorization 1919process none-the-less. 1920All listeners are required to allow the request for it to be granted, 1921and in a case where all listeners defer the request \(em leaving the 1922decision for other listeners \(em the request is denied. 1923.Pp 1924The following KPI is provided for the management of listeners: 1925.Bl -tag -width compact 1926.It Ft kauth_listener_t Fn kauth_listen_scope "const char *id" \ 1927"kauth_scope_callback_t cb" "void *cookie" 1928Create a new listener on the scope with the id 1929.Ar id , 1930setting the default listener to 1931.Ar cb . 1932.Ar cookie 1933is optional user-data that will be passed to the listener when called 1934during an authorization request. 1935.It Ft void Fn kauth_unlisten_scope "kauth_listener_t listener" 1936Removes 1937.Ar listener 1938from the scope which it belongs to, ensuring it won't be called again, 1939and frees the 1940.Ft kauth_listener_t 1941object 1942.Ar listener . 1943.El 1944.Pp 1945.Nm 1946provides no means for synchronization within listeners. 1947It is the programmer's responsibility to make sure data used by the 1948listener is properly locked during its use, as it can be accessed 1949simultaneously from the same listener called multiple times. 1950It is also the programmer's responsibility to do garbage collection after 1951the listener, possibly freeing any allocated data it used. 1952.Pp 1953The common method to do the above is by having a reference count to 1954each listener. 1955On entry to the listener, this reference count should be raised; on 1956exit, lowered. 1957.Pp 1958During the removal of a listener, first 1959.Fn kauth_scope_unlisten 1960should be called to make sure the listener code will not be entered in 1961the future. 1962Then, the code should wait (possibly sleeping) until the reference count 1963drops to zero. 1964When that happens, it is safe to do the final cleanup. 1965.Pp 1966Listeners might sleep, so no locks can be held when calling an authorization 1967wrapper. 1968.Sh EXAMPLES 1969Older code had no abstraction of the security model, so most privilege 1970checks looked like this: 1971.Bd -literal -offset indent 1972if (suser(cred, &acflag) == 0) 1973 /* allow privileged operation */ 1974.Ed 1975.Pp 1976Using the new interface, you must ask for a specific privilege explicitly. 1977For example, checking whether it is possible to open a socket would look 1978something like this: 1979.Bd -literal -offset indent 1980if (kauth_authorize_network(cred, KAUTH_NETWORK_SOCKET, 1981 KAUTH_REQ_NETWORK_SOCKET_OPEN, PF_INET, SOCK_STREAM, 1982 IPPROTO_TCP) == 0) 1983 /* allow opening the socket */ 1984.Ed 1985.Pp 1986Note that the 1987.Em securelevel 1988implications were also integrated into the 1989.Nm 1990framework so you don't have to note anything special in the call to the 1991authorization wrapper, but rather just have to make sure the security 1992model handles the request as you expect it to. 1993.Pp 1994To do that you can just 1995.Xr grep 1 1996in the relevant security model directory and have a look at the code. 1997.Sh EXTENDING KAUTH 1998Although 1999.Nm 2000provides a large set of both detailed and more or less generic requests, 2001it might be needed eventually to introduce more scopes, actions, or 2002requests. 2003.Pp 2004Adding a new scope should happen only when an entire subsystem is 2005introduced and it is assumed other parts of the kernel may want to 2006interfere with its inner-workings. 2007When a subsystem that has the potential of impacting the security 2008of the system is introduced, existing security modules must be updated 2009to also handle actions on the newly added scope. 2010.Pp 2011New actions should be added when sets of operations not covered at all 2012belong in an already existing scope. 2013.Pp 2014Requests (or sub-actions) can be added as subsets of existing actions 2015when an operation that belongs in an already covered area is introduced. 2016.Pp 2017Note that all additions should include updates to this manual, the 2018security models shipped with 2019.Nx , 2020and the example skeleton security model. 2021.Sh SEE ALSO 2022.Xr secmodel 9 2023.Sh HISTORY 2024The kernel authorization framework first appeared in Mac OS X 10.4. 2025.Pp 2026The kernel authorization framework in 2027.Nx 2028first appeared in 2029.Nx 4.0 , 2030and is a clean-room implementation based on Apple TN2127, available at 2031.Lk http://developer.apple.com/technotes/tn2005/tn2127.html 2032.Sh NOTES 2033As 2034.Nm 2035in 2036.Nx 2037is still under active development, it is likely that the ABI, and possibly the 2038API, will differ between 2039.Nx 2040versions. 2041Developers are to take notice of this fact in order to avoid building code 2042that expects one version of the ABI and running it in a system with a different 2043one. 2044.Sh AUTHORS 2045.An Elad Efrat Aq Mt elad@NetBSD.org 2046implemented the kernel authorization framework in 2047.Nx . 2048.Pp 2049.An Jason R. Thorpe Aq Mt thorpej@NetBSD.org 2050provided guidance and answered questions about the Darwin implementation. 2051