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

error = kauth_authorize_vnode(..., genfs_can_foo(...));
.Ed
.Pp
Actions on the vnode scope are of two types: operations and flags.
An operation is similar in concept to actions on other scopes in the sense
that it represents an operation desired by the caller.
A flag is an indicator of additional information about the vnode that
a file system can set in order to allow the listener to make a more
informed decision.
.Pp
Actions include the following:
.Bl -tag -width compact -offset indent
.It KAUTH_VNODE_READ_DATA
Read file data.
.It KAUTH_VNODE_LIST_DIRECTORY
Read directory listing.
Identical to the above.
.It KAUTH_VNODE_WRITE_DATA
Write file data.
.It KAUTH_VNODE_ADD_FILE
Add a file to a directory.
Identical to the above.
.It KAUTH_VNODE_EXECUTE
Execute a file.
.It KAUTH_VNODE_SEARCH
Search (enter) a directory.
Identical to the above.
.It KAUTH_VNODE_DELETE
Delete a file.
.It KAUTH_VNODE_APPEND_DATA
Append data to a file.
.It KAUTH_VNODE_ADD_SUBDIRECTORY
Add a subdirectory to a directory.
Identical to the above.
.It KAUTH_VNODE_READ_TIMES
Read the created, last accessed, and last modified times of a file.
.It KAUTH_VNODE_WRITE_TIMES
Modify the created, last accessed, or last modified times of a file.
.It KAUTH_VNODE_READ_FLAGS
Read file flags.
.It KAUTH_VNODE_WRITE_FLAGS
Modify file flags.
.It KAUTH_VNODE_READ_SYSFLAGS
Read file system flags.
.It KAUTH_VNODE_WRITE_SYSFLAGS
Modify file system flags.
.It KAUTH_VNODE_RENAME
Rename a file.
.It KAUTH_VNODE_CHANGE_OWNERSHIP
Change ownership of a file.
.It KAUTH_VNODE_READ_SECURITY
Read the permissions of a file.
.It KAUTH_VNODE_WRITE_SECURITY
Change the permissions of a file, for example by using
.Xr chmod 2 .
.It KAUTH_VNODE_READ_ATTRIBUTES
Read attributes of a file.
.It KAUTH_VNODE_WRITE_ATTRIBUTES
Modify attributes of a file.
.It KAUTH_VNODE_READ_EXTATTRIBUTES
Read extended attributes of a file.
.It KAUTH_VNODE_WRITE_EXTATTRIBUTES
Modify extended attributes of a file.
.It KAUTH_VNODE_RETAIN_SUID
Check if retaining the set-user-id bit on files after
.Xr chown 2
is allowed.
.It KAUTH_VNODE_RETAIN_SGID
Check if retaining the set-group-id bit on files after
.Xr chown 2
is allowed.
.It KAUTH_VNODE_REVOKE
Revoke a file.
.El
.Pp
Flags include the following:
.Bl -tag -width compact -offset indent
.It KAUTH_VNODE_IS_EXEC
The vnode is executable.
.Pp
The macro
.Fn FS_OBJECT_CAN_EXEC
can be used to help determine if this flag should be set.
This macro determines a file system object to be executable if it is a
directory (in which case we say it is searchable) or if it has at least one
executable bit set in its mode.
.Pp
Setting this flag helps a listener know that a vnode is executable and is used
in implementing privileged access to files and directories while maintaining
semantics that prevent execution until a file is marked as an executable.
An example for using this in listener code is:
.Bd -literal -offset indent
if (privileged) {
	/* Always allow read/write; execute only if executable. */
	if ((action & KAUTH_VNODE_EXECUTE) == 0 ||
	    (action & KAUTH_VNODE_IS_EXEC))
		result = KAUTH_RESULT_ALLOW;
}
.Ed
.Pp
Finally, the vnode scope authorization wrapper returns
.Er EACCES
in case of an error, to maintain file system semantics.
File systems can override this value if needed.
.It KAUTH_VNODE_HAS_SYSFLAGS
The file system object represented by the vnode has system flags set.
.It KAUTH_VNODE_ACCESS
The authorization is advisory only and no actual operation is to be
performed.
This is not implemented.
.El
.Ss Credentials Scope
The credentials scope,
.Dq org.netbsd.kauth.cred ,
is a special scope used internally by the
.Nm
framework to provide hooking to credential-related operations.
.Pp
It is a
.Dq notify-only
scope, allowing hooking operations such as initialization of new credentials,
credential inheritance during a fork, and copying and freeing of credentials.
The main purpose for this scope is to give a security model a way to control
the aforementioned operations, especially in cases where the credentials
hold security model-private data.
.Pp
Notifications are made using the following function, which is internal to
.Nm :
.Pp
.Ft int Fn kauth_cred_hook "kauth_cred_t cred" "kauth_action_t action" \
"void *arg0" "void *arg1"
.Pp
With the following actions:
.Bl -tag -width compact
.It Dv KAUTH_CRED_COPY
.Ar cred
are the credentials that are being copied.
.Ar arg0
is a
.Ft kauth_cred_t
representing the destination
credentials.
That is the credentials are copied from
.Ar cred
to
.Ar arg0 .
.It Dv KAUTH_CRED_FORK
The credentials are being inherited from a parent to a child process during a
fork.
.Pp
.Ar cred
are the credentials of the lwp context doing the fork, and
.Ar arg0
and
.Ar arg1
are both
.Ft struct proc *
of the parent and child processes, respectively.
.It Dv KAUTH_CRED_CHROOT
The credentials in cred belong to a process whose root directory is
changed through
.Fn change_root
(see
.Xr vfs 9 ).
.Pp
.Ar Arg0
is the new
.Ft struct cwdinfo *
of the process.
.It Dv KAUTH_CRED_FREE
The credentials in
.Ar cred
are being freed.
.It Dv KAUTH_CRED_INIT
The credentials in
.Ar cred
are being initialized.
.El
.Pp
Since this is a notify-only scope, all listeners are required to return
.Dv KAUTH_RESULT_ALLOW .
.Ss Credentials Accessors and Mutators
.Nm
has a variety of accessor and mutator routines to handle
.Ft kauth_cred_t
objects.
.Pp
The following routines can be used to access and modify the user- and
group-ids in a
.Ft kauth_cred_t :
.Bl -tag -width compact
.It Ft uid_t Fn kauth_cred_getuid "kauth_cred_t cred"
Returns the real user-id from
.Ar cred .
.It Ft uid_t Fn kauth_cred_geteuid "kauth_cred_t cred"
Returns the effective user-id from
.Ar cred .
.It Ft uid_t Fn kauth_cred_getsvuid "kauth_cred_t cred"
Returns the saved user-id from
.Ar cred .
.It Ft void Fn kauth_cred_setuid "kauth_cred_t cred" "uid_t uid"
Sets the real user-id in
.Ar cred
to
.Ar uid .
.It Ft void Fn kauth_cred_seteuid "kauth_cred_t cred" "uid_t uid"
Sets the effective user-id in
.Ar cred
to
.Ar uid .
.It Ft void Fn kauth_cred_setsvuid "kauth_cred_t cred" "uid_t uid"
Sets the saved user-id in
.Ar cred
to
.Ar uid .
.It Ft gid_t Fn kauth_cred_getgid "kauth_cred_t cred"
Returns the real group-id from
.Ar cred .
.It Ft gid_t Fn kauth_cred_getegid "kauth_cred_t cred"
Returns the effective group-id from
.Ar cred .
.It Ft gid_t Fn kauth_cred_getsvgid "kauth_cred_t cred"
Returns the saved group-id from
.Ar cred .
.It Ft void Fn kauth_cred_setgid "kauth_cred_t cred" "gid_t gid"
Sets the real group-id in
.Ar cred
to
.Ar gid .
.It Ft void Fn kauth_cred_setegid "kauth_cred_t cred" "gid_t gid"
Sets the effective group-id in
.Ar cred
to
.Ar gid .
.It Ft void Fn kauth_cred_setsvgid "kauth_cred_t cred" "gid_t gid"
Sets the saved group-id in
.Ar cred
to
.Ar gid .
.It Ft u_int Fn kauth_cred_getrefcnt "kauth_cred_t cred"
Return the reference count for
.Ar cred .
.El
.Pp
The following routines can be used to access and modify the group
list in a
.Ft kauth_cred_t :
.Bl -tag -width compact
.It Ft int Fn kauth_cred_ismember_gid "kauth_cred_t cred" "gid_t gid" \
"int *resultp"
Checks if the group-id
.Ar gid
is a member in the group list of
.Ar cred .
.Pp
If it is,
.Ar resultp
will be set to one, otherwise, to zero.
.Pp
The return value is an error code, or zero for success.
.It Ft u_int Fn kauth_cred_ngroups "kauth_cred_t cred"
Return the number of groups in the group list of
.Ar cred .
.It Ft gid_t Fn kauth_cred_group "kauth_cred_t cred" "u_int idx"
Return the group-id of the group at index
.Ar idx
in the group list of
.Ar cred .
.It Ft int Fn kauth_cred_setgroups "kauth_cred_t cred" "const gid_t *groups" \
"size_t ngroups" "uid_t gmuid" "enum uio_seg seg"
Copy
.Ar ngroups
groups from array pointed to by
.Ar groups
to the group list in
.Ar cred ,
adjusting the number of groups in
.Ar cred
appropriately.
.Ar seg
should be either
.Dv UIO_USERSPACE
or
.Dv UIO_SYSSPACE
indicating whether
.Ar groups
is a user or kernel space address.
.Pp
Any groups remaining will be set to an invalid value.
.Pp
.Ar gmuid
is unused for now, and to maintain interface compatibility with the Darwin
KPI.
.Pp
The return value is an error code, or zero for success.
.It Ft int Fn kauth_cred_getgroups "kauth_cred_t cred" "gid_t *groups" \
"size_t ngroups" "enum uio_seg seg"
Copy
.Ar ngroups
groups from the group list in
.Ar cred
to the buffer pointed to by
.Ar groups .
.Ar seg
should be either
.Dv UIO_USERSPACE
or
.Dv UIO_SYSSPACE
indicating whether
.Ar groups
is a user or kernel space address.
.Pp
The return value is an error code, or zero for success.
.El
.Ss Credential Private Data
.Nm
provides an interface to allow attaching security-model private data to
credentials.
.Pp
The use of this interface has two parts that can be divided to direct and
indirect control of the private-data.
Directly controlling the private data is done by using the below routines,
while the indirect control is often dictated by events such as process
fork, and is handled by listening on the credentials scope (see above).
.Pp
Attaching private data to credentials works by registering a key to serve
as a unique identifier, distinguishing various sets of private data that
may be associated with the credentials.
Registering, and deregistering, a key is done by using these routines:
.Bl -tag -width compact
.It Ft int Fn kauth_register_key "secmodel_t sm" "kauth_key_t *keyp"
Register new key for private data for security model
.Ar sm .
.Ar keyp
will be used to return the key to be used in further calls.
.Pp
The function returns 0 on success and an error code (see
.Xr errno 2 )
on failure.
.It Ft int Fn kauth_deregister_key "kauth_key_t key"
Deregister private data key
.Ar key .
.El
.Pp
Once registered, private data may be manipulated by the following routines:
.Bl -tag -width compact
.It Ft void Fn kauth_cred_setdata "kauth_cred_t cred" "kauth_key_t key" \
"void *data"
Set private data for
.Ar key
in
.Ar cred
to be
.Ar data .
.It Ft void * Fn kauth_cred_getdata "kauth_cred_t cred" "kauth_key_t key"
Retrieve private data for
.Ar key
in
.Ar cred .
.El
.Pp
Note that it is required to use the above routines every time the private
data is changed, i.e., using
.Fn kauth_cred_getdata
and later modifying the private data should be accompanied by a call to
.Fn kauth_cred_setdata
with the
.Dq new
private data.
.Ss Credential Inheritance and Reference Counting
.Nm
provides an interface for handling shared credentials.
.Pp
When a
.Ft kauth_cred_t
is first allocated, its reference count is set to 1.
However, with time, its reference count can grow as more objects (processes,
LWPs, files, etc.) reference it.
.Pp
The following routines are available for managing credentials reference
counting:
.Bl -tag -width compact
.It Ft kauth_cred_t Fn kauth_cred_hold "kauth_cred_t cred"
Increases reference count to
.Ar cred
by one and returns
.Ar cred
verbatim.
.It Ft void Fn kauth_cred_free "kauth_cred_t cred"
Decreases the reference count to
.Ar cred
by one.
.Pp
If the reference count dropped to zero, the memory used by
.Ar cred
will be freed.
.El
.Pp
Credential inheritance happens during a
.Xr fork 2 ,
and is handled by the following function:
.Pp
.Ft void Fn kauth_proc_fork "struct proc *parent" "struct proc *child"
.Pp
When called, it references the parent's credentials from the child,
and calls the credentials scope's hook with the
.Dv KAUTH_CRED_FORK
action to allow security model-specific handling of the inheritance
to take place.
.Ss Credentials Memory Management
Data-structures for credentials, listeners, and scopes are allocated from
memory pools managed by the
.Xr pool 9
subsystem.
.Pp
The
.Ft kauth_cred_t
objects have their own memory management routines:
.Bl -tag -width compact
.It Ft kauth_cred_t Fn kauth_cred_alloc "void"
Allocates a new
.Ft kauth_cred_t ,
initializes its lock, and sets its reference count to one.
.El
.Ss Conversion Routines
Sometimes it might be necessary to convert a
.Ft kauth_cred_t
to userland's view of credentials, a
.Ft struct uucred ,
or vice versa.
.Pp
The following routines are available for these cases:
.Bl -tag -width compact
.It Ft void Fn kauth_uucred_to_cred "kauth_cred_t cred" "const struct uucred *uucred"
Convert userland's view of credentials to a
.Ft kauth_cred_t .
.Pp
This includes effective user- and group-ids, a number of groups, and a group
list.
The reference count is set to one.
.Pp
Note that
.Nm
will try to copy as many groups as can be held inside a
.Ft kauth_cred_t .
.It Ft void Fn kauth_cred_to_uucred "struct uucred *uucred" "const kauth_cred_t cred"
Convert
.Ft kauth_cred_t
to userland's view of credentials.
.Pp
This includes effective user- and group-ids, a number of groups, and a group
list.
.Pp
Note that
.Nm
will try to copy as many groups as can be held inside a
.Ft struct uucred .
.It Ft int Fn kauth_cred_uucmp "kauth_cred_t cred" "struct uucred *uucred"
Compares
.Ar cred
with the userland credentials in
.Ar uucred .
.Pp
Common values that will be compared are effective user- and group-ids, and
the group list.
.El
.Ss Miscellaneous Routines
Other routines provided by
.Nm
are:
.Bl -tag -width compact
.It Ft void Fn kauth_cred_clone "kauth_cred_t cred1" "kauth_cred_t cred2"
Clone credentials from
.Ar cred1
to
.Ar cred2 ,
except for the lock and reference count.
.It Ft kauth_cred_t Fn kauth_cred_dup "kauth_cred_t cred"
Duplicate
.Ar cred .
.Pp
What this routine does is call
.Fn kauth_cred_alloc
followed by a call to
.Fn kauth_cred_clone .
.It Ft kauth_cred_t Fn kauth_cred_copy "kauth_cred_t cred"
Works like
.Fn kauth_cred_dup ,
except for a few differences.
.Pp
If
.Ar cred
already has a reference count of one, it will be returned.
Otherwise, a new
.Ft kauth_cred_t
will be allocated and the credentials from
.Ar cred
will be cloned to it.
Last, a call to
.Fn kauth_cred_free
for
.Ar cred
will be done.
.It Ft kauth_cred_t Fn kauth_cred_get "void"
Return the credentials associated with the current LWP.
This does not change the reference count of the resulting
.Ft kauth_cred_t
object.
.El
.Ss Scope Management
.Nm
provides routines to manage the creation and deletion of scopes on the
system.
.Pp
Note that the built-in scopes, the
.Dq generic
scope and the
.Dq process
scope, can't be deleted.
.Bl -tag -width compact
.It Ft kauth_scope_t Fn kauth_register_scope "const char *id" \
"kauth_scope_callback_t cb" "void *cookie"
Register a new scope on the system.
.Ar id
is the name of the scope, usually in reverse DNS-like notation.
For example,
.Dq org.netbsd.kauth.myscope .
.Ar cb
is the default listener, to which authorization requests for this scope
will be dispatched to.
.Ar cookie
is optional user-data that will be passed to all listeners
during authorization on the scope.
.It Ft void Fn kauth_deregister_scope "kauth_scope_t scope"
Deregister
.Ar scope
from the scopes available on the system, and free the
.Ft kauth_scope_t
object
.Ar scope .
.El
.Ss Listener Management
Listeners in
.Nm
are authorization callbacks that are called during an authorization
request in the scope which they belong to.
.Pp
When an authorization request is made, all listeners associated with
a scope are called to allow, deny, or defer the request.
.Pp
It is enough for one listener to deny the request in order for the
request to be denied; but all listeners are called during an authorization
process none-the-less.
All listeners are required to allow the request for it to be granted,
and in a case where all listeners defer the request \(em leaving the
decision for other listeners \(em the request is denied.
.Pp
The following KPI is provided for the management of listeners:
.Bl -tag -width compact
.It Ft kauth_listener_t Fn kauth_listen_scope "const char *id" \
"kauth_scope_callback_t cb" "void *cookie"
Create a new listener on the scope with the id
.Ar id ,
setting the default listener to
.Ar cb .
.Ar cookie
is optional user-data that will be passed to the listener when called
during an authorization request.
.It Ft void Fn kauth_unlisten_scope "kauth_listener_t listener"
Removes
.Ar listener
from the scope which it belongs to, ensuring it won't be called again,
and frees the
.Ft kauth_listener_t
object
.Ar listener .
.El
.Pp
.Nm
provides no means for synchronization within listeners.
It is the programmer's responsibility to make sure data used by the
listener is properly locked during its use, as it can be accessed
simultaneously from the same listener called multiple times.
It is also the programmer's responsibility to do garbage collection after
the listener, possibly freeing any allocated data it used.
.Pp
The common method to do the above is by having a reference count to
each listener.
On entry to the listener, this reference count should be raised; on
exit, lowered.
.Pp
During the removal of a listener, first
.Fn kauth_scope_unlisten
should be called to make sure the listener code will not be entered in
the future.
Then, the code should wait (possibly sleeping) until the reference count
drops to zero.
When that happens, it is safe to do the final cleanup.
.Pp
Listeners might sleep, so no locks can be held when calling an authorization
wrapper.
.Sh EXAMPLES
Older code had no abstraction of the security model, so most privilege
checks looked like this:
.Bd -literal -offset indent
if (suser(cred, &acflag) == 0)
	/* allow privileged operation */
.Ed
.Pp
Using the new interface, you must ask for a specific privilege explicitly.
For example, checking whether it is possible to open a socket would look
something like this:
.Bd -literal -offset indent
if (kauth_authorize_network(cred, KAUTH_NETWORK_SOCKET,
    KAUTH_REQ_NETWORK_SOCKET_OPEN, PF_INET, SOCK_STREAM,
    IPPROTO_TCP) == 0)
	/* allow opening the socket */
.Ed
.Pp
Note that the
.Em securelevel
implications were also integrated into the
.Nm
framework so you don't have to note anything special in the call to the
authorization wrapper, but rather just have to make sure the security
model handles the request as you expect it to.
.Pp
To do that you can just
.Xr grep 1
in the relevant security model directory and have a look at the code.
.Sh EXTENDING KAUTH
Although
.Nm
provides a large set of both detailed and more or less generic requests,
it might be needed eventually to introduce more scopes, actions, or
requests.
.Pp
Adding a new scope should happen only when an entire subsystem is
introduced and it is assumed other parts of the kernel may want to
interfere with its inner-workings.
When a subsystem that has the potential of impacting the security
of the system is introduced, existing security modules must be updated
to also handle actions on the newly added scope.
.Pp
New actions should be added when sets of operations not covered at all
belong in an already existing scope.
.Pp
Requests (or sub-actions) can be added as subsets of existing actions
when an operation that belongs in an already covered area is introduced.
.Pp
Note that all additions should include updates to this manual, the
security models shipped with
.Nx ,
and the example skeleton security model.
.Sh SEE ALSO
.Xr secmodel 9
.Sh HISTORY
The kernel authorization framework first appeared in Mac OS X 10.4.
.Pp
The kernel authorization framework in
.Nx
first appeared in
.Nx 4.0 ,
and is a clean-room implementation based on Apple TN2127, available at
.Lk http://developer.apple.com/technotes/tn2005/tn2127.html
.Sh NOTES
As
.Nm
in
.Nx
is still under active development, it is likely that the ABI, and possibly the
API, will differ between
.Nx
versions.
Developers are to take notice of this fact in order to avoid building code
that expects one version of the ABI and running it in a system with a different
one.
.Sh AUTHORS
.An Elad Efrat Aq Mt elad@NetBSD.org
implemented the kernel authorization framework in
.Nx .
.Pp
.An Jason R. Thorpe Aq Mt thorpej@NetBSD.org
provided guidance and answered questions about the Darwin implementation.