eab254edc018f33170cf92307762e3ce9b4e48b6
[WebKit-https.git] / Source / WebKit / WebProcess / com.apple.WebProcess.sb.in
1 ; Copyright (C) 2010-2018 Apple Inc. All rights reserved.
2 ;
3 ; Redistribution and use in source and binary forms, with or without
4 ; modification, are permitted provided that the following conditions
5 ; are met:
6 ; 1. Redistributions of source code must retain the above copyright
7 ;    notice, this list of conditions and the following disclaimer.
8 ; 2. Redistributions in binary form must reproduce the above copyright
9 ;    notice, this list of conditions and the following disclaimer in the
10 ;    documentation and/or other materials provided with the distribution.
11 ;
12 ; THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
13 ; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
14 ; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
15 ; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
16 ; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
17 ; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
18 ; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
19 ; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
20 ; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
21 ; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
22 ; THE POSSIBILITY OF SUCH DAMAGE.
23
24 (version 1)
25 (deny default (with partial-symbolication))
26 (allow system-audit file-read-metadata)
27
28 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
29 (import "system.sb")
30 #else
31 ;;;
32 ;;; The following rules were originally contained in 'system.sb'. We are duplicating them here so we can
33 ;;; remove unneeded sandbox extensions.
34 ;;;
35
36 ;;; Allow registration of per-pid services.
37 (allow mach-register (local-name-prefix ""))
38
39 ;;; Allow read access to standard system paths.
40 (allow file-read*
41     (require-all (file-mode #o0004)
42     (require-any (subpath "/Library/Filesystems/NetFSPlugins")
43     (subpath "/Library/Apple/System")
44     (subpath "/Library/Preferences/Logging")      ; Logging Rethink
45     (subpath "/System")
46     (subpath "/private/var/db/dyld")
47     (subpath "/private/var/db/timezone")
48     (subpath "/usr/lib")
49     (subpath "/usr/share"))))
50
51 ;;; Allow reading internal profiles on development builds
52 (allow file-read*
53     (require-all (file-mode #o0004)
54     (subpath "/AppleInternal/Library/Preferences/Logging")
55     (system-attribute apple-internal)))
56
57 ;;; Allow mapping of system frameworks + dylibs
58 (allow file-map-executable
59     (subpath "/Library/Apple/System/Library/Frameworks")
60     (subpath "/Library/Apple/System/Library/PrivateFrameworks")
61     (subpath "/System/Library/Frameworks")
62     (subpath "/System/Library/PrivateFrameworks")
63     (subpath "/usr/lib")
64     (literal "/usr/local/lib/sanitizers"))
65
66 (allow file-read-metadata
67     (literal "/etc")
68     (literal "/tmp")
69     (literal "/var")
70     (literal "/private/etc/localtime"))
71
72
73 ;;; Allow access to standard special files.
74 (allow file-read*
75     (literal "/dev/autofs_nowait")
76     (literal "/dev/random")
77     (literal "/dev/urandom")
78     (literal "/private/etc/master.passwd")
79     (literal "/private/etc/passwd"))
80
81 (allow file-read*
82        file-write-data
83     (literal "/dev/null")
84     (literal "/dev/zero"))
85
86 (allow file-read*
87        file-write-data
88        file-ioctl
89     (literal "/dev/dtracehelper"))
90
91 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
92 (allow network-outbound
93     (literal "/private/var/run/asl_input")
94     (literal "/private/var/run/syslog"))
95 #endif
96
97 ;;; Allow creation of core dumps.
98 (allow file-write-create
99     (require-all (prefix "/cores/")
100         (vnode-type REGULAR-FILE)))
101
102
103 ;;; Allow IPC to standard system agents.
104 (allow ipc-posix-shm-read*
105     (ipc-posix-name "apple.shm.notification_center")
106     (ipc-posix-name-prefix "apple.cfprefs."))
107
108 ;;; (system-graphics) - Allow access to graphics hardware.
109 (define (system-graphics)
110     ;; Preferences
111     (allow user-preference-read
112         (preference-domain "com.apple.opengl")
113         (preference-domain "com.nvidia.OpenGL"))
114     ;; CVMS
115     (allow mach-lookup
116         (global-name "com.apple.cvmsServ"))
117 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
118     (allow file-read*
119         (prefix "/private/var/db/CVMS/cvmsCodeSignObj"))
120 #endif
121     ;; OpenCL
122     (allow iokit-open
123         (iokit-connection "IOAccelerator")
124         (iokit-registry-entry-class "IOAccelerationUserClient")
125         (iokit-registry-entry-class "IOSurfaceRootUserClient")
126         (iokit-registry-entry-class "IOSurfaceSendRight"))
127     ;; CoreVideo CVCGDisplayLink
128     (allow iokit-open
129         (iokit-registry-entry-class "IOFramebufferSharedUserClient"))
130     ;; H.264 Acceleration
131     (allow iokit-open
132         (iokit-registry-entry-class "AppleIntelMEUserClient")
133         (iokit-registry-entry-class "AppleSNBFBUserClient"))
134     ;; QuartzCore
135     (allow iokit-open
136         (iokit-registry-entry-class "AGPMClient")
137         (iokit-registry-entry-class "AppleGraphicsControlClient")
138         (iokit-registry-entry-class "AppleGraphicsPolicyClient"))
139     ;; OpenGL
140     (allow iokit-open
141         (iokit-registry-entry-class "AppleMGPUPowerControlClient"))
142     ;; GPU bundles
143     (allow file-read*
144         (subpath "/Library/GPUBundles"))
145     ;; DisplayServices
146     (allow iokit-set-properties
147         (require-all (iokit-connection "IODisplay")
148         (require-any (iokit-property "brightness")
149         (iokit-property "linear-brightness")
150         (iokit-property "commit")
151         (iokit-property "rgcs")
152         (iokit-property "ggcs")
153         (iokit-property "bgcs")))))
154
155 ;;;
156 ;;; End rules originally copied from 'system.sb'
157 ;;;
158 #endif
159
160 ;;; process-info* defaults to allow; deny it and then allow operations we actually need.
161 (deny process-info*)
162 (allow process-info-pidinfo)
163 (allow process-info-setcontrol (target self))
164 (allow process-codesigning-status*)
165
166 (deny sysctl*)
167 (allow sysctl-read
168     (sysctl-name
169         "hw.byteorder"
170         "hw.busfrequency_max"
171         "hw.cputype"
172         "hw.machine"
173         "hw.memsize"
174         "hw.model"
175         "hw.ncpu"
176         "hw.vectorunit"
177         "kern.bootargs" ;; <rdar://problem/47738015>
178         "kern.hostname"
179         "kern.maxfilesperproc"
180         "kern.memorystatus_level"
181         "kern.safeboot"
182         "kern.version"
183         "machdep.cpu.brand_string"
184         "security.mac.sandbox.sentinel"
185         "kern.tcsm_enable"
186         "kern.tcsm_available"
187         "vm.footprint_suspend")
188     (sysctl-name-regex #"^hw.(active|avail)cpu")
189     (sysctl-name-regex #"^hw.(busfrequency|cachelinesize|cpufrequency(|_max)|pagesize|tbfrequency)(|_compat)")
190     (sysctl-name-regex #"^hw.l.+cachesize")
191     (sysctl-name-regex #"^hw.(logical|physical)cpu_max")
192     (sysctl-name-regex #"^hw.optional\.")
193     (sysctl-name-regex #"^kern.os(release|type|variant_status|version)")
194     (sysctl-name-regex #"^net.routetable")
195 )
196
197 (allow sysctl-write
198     (sysctl-name
199         "kern.tcsm_enable"))
200
201 (deny iokit-get-properties)
202 (allow iokit-get-properties
203     (iokit-property "AAPL,LCD-PowerState-ON") ;; <rdar://problem/47738015>
204     (iokit-property "AGCInfo")
205     (iokit-property-regex #"^Accel(Caps|NativeDMARowByteAlignment)")
206     (iokit-property-regex #"^(Accurate|Extended)MaxDigitizerPressureValue")
207     (iokit-property-regex #"^(Activation|Animation)Thresholds")
208     (iokit-property "ActuationSupported")
209     (iokit-property "AllowDisplaySleep")
210     (iokit-property "AlwaysNeedsVelocityCalculated")
211     (iokit-property-regex #"Apple(GVAKeyDoesNotExist|IntelMEVABundleName)")
212     (iokit-property-regex #"^AAPL,(DisplayPipe|OpenCLdisabled|IOGraphics_LER(|_RegTag_1|_RegTag_0|_Busy_2)|alias-policy|boot-display|display-alias|mux-switch-state|ndrv-dev|primary-display|slot-name)")
213     (iokit-property-regex #"^ATY,(cbits|fb_(linebytes|offset|size)|intrev)")
214     (iokit-property "AVCSupported")
215     (iokit-property "BacklightHandle")
216     (iokit-property "BlockSize")
217     (iokit-property-regex #"^CEA(ModeID|PixelRepetition)")
218     (iokit-property "CFBundleIdentifier")
219     (iokit-property "CFBundleIdentifierKernel") ;; <rdar://problem/47738015>
220     (iokit-property "CapsLockDelay")
221     (iokit-property "CaseSensitive")
222     (iokit-property "ConfigState")
223     (iokit-property "Description")
224     (iokit-property "Development")
225     (iokit-property-regex #"^Device( Characteristics|EqID)")
226     (iokit-property "DisplayRouting")
227     (iokit-property "Driver is Ready")
228     (iokit-property "Ejectable")
229     (iokit-property "EnableLPVP")
230     (iokit-property "Encrypted")
231     (iokit-property "Endianness")
232     (iokit-property "Family ID")
233     (iokit-property "ForceSupported")
234     (iokit-property "Formats")
235     (iokit-property "GPUConfigurationVariable")
236     (iokit-property "GpuDebugPolicy")
237     (iokit-property "HEVCSupported")
238     (iokit-property "HIDPointerAccelerationType")
239     (iokit-property-regex #"^IOAccel(DisplayPipeCapabilities|Index|Types|Revision)")
240     (iokit-property-regex #"^IO(Class|MatchCategory|NameMatch)")
241     (iokit-property-regex #"^IOAudioControl(ChannelID|ID|SubType|Usage|Value)")
242     (iokit-property-regex #"^IOAudioDevice(CanBeDefaults|TransportType)")
243     (iokit-property-regex #"^IOAudioEngine(ChannelNames|ClientDescription|CoreAudioPlugIn|(|Device)Description|Flavor|GlobalUniqueID|IsHidden|OutputChannelLayout|SampleOffset|State)")
244     (iokit-property-regex #"^IOAudioEngineClock(Domain|IsStable)")
245     (iokit-property "IOAudioEngineDisableClockBoundsCheck")
246     (iokit-property-regex #"^IOAudioEngine(Input|Output)Sample(Latency|Offset)")
247     (iokit-property-regex #"^IOAudioEngineNum(ActiveUserClients|SampleFramesPerBuffer)")
248     (iokit-property "IOAudioSampleRate")
249     (iokit-property "IOAudioStreamSampleFormatByteOrder")
250     (iokit-property-regex #"^IOAV(.*)(De|En)code$")
251     (iokit-property "IOBacklightHandlerID")
252     (iokit-property "IOBusyInterest")
253     (iokit-property "IOCFPlugInTypes")
254     (iokit-property "IOChildIndex")
255     (iokit-property-regex #"^IOClass(|NameOverride)")
256     (iokit-property "IOConsoleUsers")
257     (iokit-property "IODVDBundleName")
258     (iokit-property "IODeviceMemory")
259     (iokit-property "IODisplayParameters")
260     (iokit-property-regex #"^IOFB(CLUTDefer|Config|CursorInfo|Dependent(ID|Index))")
261     (iokit-property "IOFBCurrentPixelClock")
262     (iokit-property-regex #"^IOFBCurrentPixelCount(|Real)")
263     (iokit-property-regex #"^IOFB(DetailedTimings|Gamma(Count|HeaderSize|Width))")
264     (iokit-property-regex #"^IOFB(Blue|Green|Red)GammaScale")
265     (iokit-property-regex #"^IOFBI2CInterface(IDs|Info)")
266     (iokit-property-regex #"^IOFB(HDMIDongleROM|Integrated|MemorySize|NeedsRefresh|ProbeOptions|ScalerInfo|TimingRange|Transform|UIScale|WaitCursor(Frames|Period))")
267     (iokit-property "IOFramebufferOpenGLIndex")
268     (iokit-property "IOGeneralInterest")
269     (iokit-property "IOGLBundleName")
270     (iokit-property-regex #"^IOGVA(BGRAEnc|Codec|EncoderRestricted|Scaler|VTCapabilities|HEVCDecodeCapabilities|HEVCEncodeCapabilities)")
271     (iokit-property-regex #"^IOGVA(.*)(De|En)code$")
272     (iokit-property "IOHibernateState")
273     (iokit-property "IOI2CTransactionTypes")
274     (iokit-property-regex #"^IOInterrupt(Controllers|Specifiers)")
275     (iokit-property "IOKitDebug")
276     (iokit-property "IOMatchCategory")
277     (iokit-property "IOMediaIcon")
278     (iokit-property "IONDRVFramebufferGeneration")
279     (iokit-property "IONVRAMProperty")
280     (iokit-property-regex #"^IOName(|Match(|ed))")
281     (iokit-property "IOOCDBundleName")
282     (iokit-property "IOPCITunnelled")
283     (iokit-property "IOPCITunnelCompatible")
284     (iokit-property "IOPMStrictTreeOrder")
285     (iokit-property "IOParentMatch")
286     (iokit-property-regex #"^IOPCI((Class|Primary|Property|)Match|Express(Capabilities|Link(Status|Capabilities))|MSIMode|Resourced|Tunnelled)")
287     (iokit-property "IOPMIsPowerManaged")
288     (iokit-property-regex #"^IOPlatform(SerialNumber|UUID)")
289     (iokit-property "IOPowerManagement")
290     (iokit-property "IOProbeScore")
291     (iokit-property "IOPropertyMatch")
292     (iokit-property "IOProviderClass")
293     (iokit-property-regex #"^IOReport(Lures|Legend(|Public))")
294     (iokit-property "IOScreenRestoreState")
295     (iokit-property "IOSourceVersion")
296     (iokit-property-regex #"^IOVA(BundleName|Renderer(|Sub)ID)")
297     (iokit-property-regex #"^InternalStatistics(|Accm)")
298     (iokit-property-regex #"^MetalPlugin(Name|ClassName)")
299     (iokit-property "MetalStatisticsName")
300     (iokit-property "MTHIDDevice")
301     (iokit-property "MT Built-In")
302     (iokit-property "MaintainPowerInUILock")
303     (iokit-property "Max Packet Size")
304     (iokit-property "MinDigitizerPressureValue")
305     (iokit-property "Multitouch Serial Number")
306     (iokit-property-regex #"^Multitouch (Subdevice |)ID")
307     (iokit-property "NVArch")
308     (iokit-property-regex #"^NVC(AP|LASS)")
309     (iokit-property-regex #"^NVDA,(Features|NVPresentment-version|accel-loaded|invalid-config|mm-version)")
310     (iokit-property "NVDA,Enable-A2R10G10B10Format")
311     (iokit-property-regex #"^NVDA(Type|initgl_created)")
312     (iokit-property "NVRAMProperty")
313     (iokit-property "NXSystemInfo")
314     (iokit-property-regex #"^VRAM,(memvendorID|total(MB|size))")
315     (iokit-property "NoAutoRoute")
316     (iokit-property-regex #"^Num(Blocks|Streams)")
317     (iokit-property-regex #"^PerformanceStatistics(|Accum)")
318     (iokit-property "Protocol Characteristics")
319     (iokit-property "Removable")
320     (iokit-property-regex #"^ResetOn(Lock|Unlock)Ms")
321     (iokit-property "SafeEjectRequested")
322     (iokit-property "SampleRates")
323     (iokit-property "Serial Number")
324     (iokit-property "StartupDisplay")
325     (iokit-property "SurfaceList")
326     (iokit-property-regex #"^Support(AudioAUUC|sSilentClick|TapToWake)")
327     (iokit-property-regex #"^Sensor (Columns|Rows)")
328     (iokit-property-regex #"^Sensor Region (Descriptor|Param|Rows)")
329     (iokit-property-regex #"^Sensor Surface (Descriptor|Height|Width)")
330     (iokit-property "SurfaceList")
331     (iokit-property "TimeStampFiltering")
332     (iokit-property "Transport")
333     (iokit-property "USBADC") ;; Needed for Audio support on older hardware
334     (iokit-property "UserClientEnabled")
335     (iokit-property "VRAM,totalMB")
336     (iokit-property "WANTS_FRAMES_IGNORED")
337     (iokit-property-regex #"^acpi-(device|path)")
338     (iokit-property "assigned-addresses")
339     (iokit-property "attached-gpu-control-path")
340     (iokit-property-regex #"^audio-(codec-info|device-mvalue|device-nvalue|selector)")
341     (iokit-property "av-signal-type")
342     (iokit-property "bcdVersion")
343     (iokit-property-regex #"^(board|device|revision|subsystem|vendor)-id")
344     (iokit-property "boot-gamma-restored")
345     (iokit-property "built-in")
346     (iokit-property "cail_properties")
347     (iokit-property-regex #"^canvas-(height|width)")
348     (iokit-property "class-code")
349     (iokit-property "color-accuracy-index")
350     (iokit-property "compatible")
351     (iokit-property "connector-type")
352     (iokit-property-regex #"^(device|revision|subsystem-vendor|touch-size)-id")
353     (iokit-property "device_type")
354     (iokit-property "dpm")
355     (iokit-property "errordb") ;; Needed for OpenGL on older hardware
356     (iokit-property "graphic-options")
357     (iokit-property "hda-gfx")
358     (iokit-property-regex #"^id(Product|Vendor)")
359     (iokit-property "iofb_version")
360     (iokit-property "image-encrypted")
361     (iokit-property "locationID") ;; Needed for Audio support on older hardware
362     (iokit-property "model")
363     (iokit-property "mt-device-id")
364     (iokit-property "name")
365     (iokit-property "nv-stats")
366     (iokit-property-regex #"^parser-(options|type)")
367     (iokit-property-regex #"^pci(-aspm-default|debug)")
368     (iokit-property "port-number")
369     (iokit-property "reg")
370     (iokit-property "rm_board_number")
371     (iokit-property-regex #"^(rom|vbios)-revision")
372     (iokit-property "saved-config")
373     (iokit-property "startup-timing")
374     (iokit-property "touch-size-id")
375 #if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
376     (iokit-property "ATY,cbits")
377     (iokit-property "ATY,intrev")
378     (iokit-property "AccelNativeDMARowByteAlignment")
379     (iokit-property "CompactVRAM")
380     (iokit-property "EnableBlitLib")
381     (iokit-property "ForceDisableEDRAM")
382     (iokit-property "GPUConfigurationVariable")
383     (iokit-property "GpuDebugPolicy")
384     (iokit-property "IOKitDebug")
385     (iokit-property "IOPCIMatch")
386     (iokit-property "IOOCDBundleName")
387     (iokit-property "MetalStatisticsScriptName")
388     (iokit-property "MetalCoalesce")
389     (iokit-property "PanicOnGPUHang")
390     (iokit-property "TelemetryDisable")
391     (iokit-property "cail_properties")
392     (iokit-property "dpm")
393 #endif
394     (iokit-property "IOGVAH264EncodeCapabilities") ;; <rdar://problem/49498040>
395 )
396
397 #if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
398 (deny mach-lookup (xpc-service-name-prefix ""))
399 (allow mach-lookup
400     (xpc-service-name "com.apple.PerformanceAnalysis.animationperfd")
401     (xpc-service-name "com.apple.accessibility.mediaaccessibilityd")
402     (xpc-service-name "com.apple.audio.SandboxHelper")
403     (xpc-service-name "com.apple.coremedia.videodecoder")
404     (xpc-service-name "com.apple.coremedia.videoencoder")
405     (xpc-service-name-regex #"\.apple-extension-service$")
406     (xpc-service-name "com.apple.hiservices-xpcservice")
407     (xpc-service-name "com.apple.print.normalizerd")
408 )
409 #endif
410
411 ;; Utility functions for home directory relative path filters
412 (define (home-regex home-relative-regex)
413   (regex (string-append "^" (regex-quote (param "HOME_DIR")) home-relative-regex)))
414
415 (define (home-subpath home-relative-subpath)
416   (subpath (string-append (param "HOME_DIR") home-relative-subpath)))
417
418 (define (home-literal home-relative-literal)
419   (literal (string-append (param "HOME_DIR") home-relative-literal)))
420
421 (define (allow-read-directory-and-issue-read-extensions path)
422     (if path
423         (begin
424             (allow file-read* (subpath path))
425             (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path))))))
426
427 (define (allow-read-write-directory-and-issue-read-write-extensions path)
428     (if path
429         (begin
430             (allow file-read* file-write* (subpath path))
431             (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path)))
432             (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") (subpath path))))))
433
434 ;; Remove when <rdar://problem/29646094> is fixed.
435 (define (HEX-pattern-match-generator pattern-descriptor)
436     (letrec ((pattern-string ""))
437         (for-each  (lambda (repeat-count)
438             (if (zero? repeat-count)
439                 (set! pattern-string (string-append  pattern-string "-"))
440                 (let appender ((count repeat-count))
441                     (if (> count 0)
442                         (begin
443                             (set! pattern-string (string-append  pattern-string "[0-9A-F]"))
444                             (appender (- count 1)))))))
445             pattern-descriptor)
446     pattern-string))
447
448 ;; return a regex pattern matching string for 8-4-4-4-12 UUIDs:
449 (define (uuid-HEX-pattern-match-string)
450     (HEX-pattern-match-generator '(8 0 4 0 4 0 4 0 12)))
451
452 ;; global to hold the computed UUID matching pattern.
453 (define *uuid-pattern* "")
454
455 (define (uuid-regex-string)
456     (if (zero? (string-length *uuid-pattern*))
457         (set! *uuid-pattern* (uuid-HEX-pattern-match-string)))
458     *uuid-pattern*)
459
460 ;; Read-only preferences and data
461 (allow file-read*
462     ;; Basic system paths
463     (subpath "/Library/Dictionaries")
464     (subpath "/Library/Fonts")
465     (subpath "/Library/Frameworks")
466     (subpath "/Library/Managed Preferences")
467     (subpath "/Library/Speech/Synthesizers")
468     (regex #"^/private/etc/(hosts|group|passwd)$")
469
470     (literal "/Library/Application Support/CrashReporter/SubmitDiagInfo.domains")
471
472     ;; System and user preferences
473     (home-literal "/.CFUserTextEncoding")
474
475     ;; FIXME: This should be removed when <rdar://problem/8957845> is fixed.
476     (home-subpath "/Library/Fonts")
477
478     (subpath "/Library/Audio/Plug-Ins/HAL")
479
480     (home-subpath "/Library/Dictionaries"))
481
482 (allow file-read-data
483     (literal "/usr/local/lib/log") ; <rdar://problem/36629495>
484     ;; Needed for AES3 support
485     (subpath "/Library/Audio/Plug-Ins/Components"))
486
487 ;; Preferences support
488 (allow user-preference-read
489     (preference-domain
490         "kCFPreferencesAnyApplication"
491         "com.apple.ATS"
492         "com.apple.CoreGraphics"
493         "com.apple.DownloadAssessment"
494         "com.apple.HIToolbox"
495         "com.apple.LaunchServices"
496         "com.apple.MultitouchSupport" ;; FIXME: Remove when <rdar://problem/13011633> is fixed.
497         "com.apple.ServicesMenu.Services" ;; Needed for NSAttributedString <rdar://problem/10844321>
498         "com.apple.ViewBridge" ;; Needed for Input elements.
499         "com.apple.WebFoundation"
500         "com.apple.avfoundation"
501         "com.apple.avfoundation.frecents" ;; <rdar://problem/33137029>
502         "com.apple.avfoundation.videoperformancehud" ;; <rdar://problem/31594568>
503         "com.apple.coremedia"
504         "com.apple.crypto"
505         "com.apple.driver.AppleBluetoothMultitouch.mouse"
506         "com.apple.driver.AppleBluetoothMultitouch.trackpad"
507         "com.apple.driver.AppleHIDMouse"
508         "com.apple.lookup.shared"
509         "com.apple.mediaaccessibility" ;; Needed for custom caption styles
510         "com.apple.networkConnect"
511         "com.apple.speech.voice.prefs"
512         "com.apple.systemsound"
513         "com.apple.universalaccess"
514         "edu.mit.Kerberos"
515         "pbs" ;; Needed for NSAttributedString <rdar://problem/10844321>
516 ))
517
518 ; (Temporary) backward compatibility with non-CFPreferences readers.
519 (allow file-read*
520     (literal "/Library/Preferences/com.apple.ViewBridge.plist"))
521
522 ; FIXME: This is needed for some security framework calls (that use non-CFPreferences readers)
523 (allow file-read-data
524     (literal "/Library/Preferences/com.apple.security.plist")
525     (home-subpath "/Library/Preferences/com.apple.security.plist"))
526
527 ;; On-disk WebKit2 framework location, to account for debug installations outside of /System/Library/Frameworks,
528 ;; and to allow issuing extensions.
529 (allow-read-directory-and-issue-read-extensions (param "WEBKIT2_FRAMEWORK_DIR"))
530
531 ;; Allow issuing extensions to system libraries that the Network process can already read.
532 ;; This is to avoid warnings attempting to create extensions for these resources.
533 (allow-read-directory-and-issue-read-extensions "/System/Library/PrivateFrameworks/WebInspectorUI.framework")
534
535 ;; Sandbox extensions
536 (define (apply-read-and-issue-extension op path-filter)
537     (op file-read* path-filter)
538     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
539 (define (apply-write-and-issue-extension op path-filter)
540     (op file-write* path-filter)
541     (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
542 (define (read-only-and-issue-extensions path-filter)
543     (apply-read-and-issue-extension allow path-filter))
544 (define (read-write-and-issue-extensions path-filter)
545     (apply-read-and-issue-extension allow path-filter)
546     (apply-write-and-issue-extension allow path-filter))
547 (read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
548 (read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
549 (allow mach-lookup (extension "com.apple.app-sandbox.mach")) ;; FIXME: Should be removed when <rdar://problem/13066206> is fixed.
550
551 ;; Allow the OpenGL Profiler to attach.
552 (if (defined? 'mach-register)
553     (allow mach-register (global-name-regex #"^_oglprof_attach_<[0-9]+>$")))
554
555 (if (positive? (string-length (param "DARWIN_USER_CACHE_DIR")))
556     (allow-read-write-directory-and-issue-read-write-extensions (param "DARWIN_USER_CACHE_DIR")))
557
558 (if (positive? (string-length (param "DARWIN_USER_TEMP_DIR")))
559     (allow-read-write-directory-and-issue-read-write-extensions (param "DARWIN_USER_TEMP_DIR")))
560
561 ;; IOKit user clients
562 (allow iokit-open
563     (iokit-user-client-class "AppleMultitouchDeviceUserClient")
564     (iokit-user-client-class "AppleUpstreamUserClient")
565     (iokit-user-client-class "IOHIDParamUserClient")
566     (iokit-user-client-class "RootDomainUserClient")
567     (iokit-user-client-class "IOAudioControlUserClient")
568     (iokit-user-client-class "IOAudioEngineUserClient")
569     ;; Following is needed due to <rdar://problem/10427451> && <rdar://problem/10808817>
570     (iokit-user-client-class "AudioAUUC"))
571
572 ;; cookied.
573 ;; FIXME: Update for <rdar://problem/13642852>.
574 (allow ipc-posix-shm-read-data
575     (ipc-posix-name "FNetwork.defaultStorageSession")
576     (ipc-posix-name-regex #"\.PrivateBrowsing-")
577     (ipc-posix-name-regex #"^WebKit Test-"))
578
579 ;; ColorSync
580 (allow ipc-posix-shm*
581     (ipc-posix-name "com.apple.ColorSync.Gen.lock")
582     (ipc-posix-name "com.apple.ColorSync.Disp.lock")
583     (ipc-posix-name "com.apple.ColorSync.Gray2.2")
584     (ipc-posix-name "com.apple.ColorSync.sRGB")
585     (ipc-posix-name "com.apple.ColorSync.GenGray")
586     (ipc-posix-name "com.apple.ColorSync.GenRGB"))
587
588 ;; Audio
589 (allow ipc-posix-shm-read* ipc-posix-shm-write-data
590     (ipc-posix-name-regex #"^AudioIO"))
591
592 ;; Remote Web Inspector
593 (allow mach-lookup
594        (global-name "com.apple.webinspector"))
595
596 ;; Various services required by AppKit and other frameworks
597 (allow mach-lookup
598 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101400
599        (global-name "com.apple.FontObjectsServer")
600 #endif
601        (global-name "com.apple.PowerManagement.control")
602        (global-name "com.apple.SystemConfiguration.configd")
603 #if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
604        (global-name "com.apple.analyticsd")
605        (global-name "com.apple.audio.AudioComponentRegistrar")
606 #endif
607        (global-name "com.apple.assertiond.processassertionconnection")
608        (global-name "com.apple.audio.SystemSoundServer-OSX")
609        (global-name "com.apple.audio.audiohald")
610        (global-name "com.apple.awdd")
611        (global-name "com.apple.cfprefsd.agent")
612        (global-name "com.apple.cfprefsd.daemon")
613        (global-name "com.apple.cmio.registerassistantservice") ;; Needed by CoreMedia for plugin drivers
614        (global-name "com.apple.cookied")
615        (global-name "com.apple.coreservices.launchservicesd")
616        (global-name "com.apple.diagnosticd")
617        (global-name "com.apple.fonts")
618        (global-name "com.apple.iconservices")
619        (global-name "com.apple.iconservices.store")
620        (global-name "com.apple.mediaremoted.xpc")
621        (global-name "com.apple.logd")
622        (global-name "com.apple.logd.events")
623        (global-name "com.apple.lsd.mapdb")
624        (global-name "com.apple.lskdd") ;; <rdar://problem/49123855>
625        (global-name "com.apple.mobileassetd")
626        (global-name "com.apple.powerlog.plxpclogger.xpc")
627        (global-name "com.apple.system.logger")
628        (global-name "com.apple.tccd")
629        (global-name "com.apple.tccd.system")
630        (global-name "com.apple.trustd.agent")
631 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
632        (global-name "com.apple.CARenderServer") ; Needed for [CAContext remoteContextWithOptions]
633 #else
634        (global-name "com.apple.windowserver.active")
635 #endif
636 )
637
638 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400 || PLATFORM(IOSMAC)
639 ;; <rdar://problem/47268166>
640 (allow mach-lookup (xpc-service-name "com.apple.MTLCompilerService"))
641 #endif
642
643 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400
644 (deny mach-lookup (with no-log)
645     (global-name "com.apple.ViewBridgeAuxiliary")
646     (global-name "com.apple.windowserver.active"))
647 #endif
648
649
650 ;; Needed to support encrypted media playback <rdar://problem/40038478>
651 (allow mach-lookup
652     (global-name "com.apple.SecurityServer")
653     (global-name "com.apple.ocspd"))
654
655 (allow file-read* file-write* (subpath "/private/var/db/mds/system")) ;; FIXME: This should be removed when <rdar://problem/9538414> is fixed.
656
657 (allow file-read*
658        (subpath "/private/var/db/mds")
659        (literal "/private/var/db/DetachedSignatures"))
660
661 (allow ipc-posix-shm-read* ipc-posix-shm-write-data ipc-posix-shm-write-create
662        (ipc-posix-name "com.apple.AppleDatabaseChanged"))
663
664 ;; CoreFoundation. We don't import com.apple.corefoundation.sb, because it allows unnecessary access to pasteboard.
665 (allow mach-lookup
666     (global-name-regex #"^com.apple.distributed_notifications")
667 #if !HAVE(CSCHECKFIXDISABLE)
668     (global-name "com.apple.CoreServices.coreservicesd")
669 #endif
670 )
671
672 (allow file-read-data
673     (literal "/dev/autofs_nowait")) ; Used by CF to circumvent automount triggers
674 (allow ipc-posix-shm
675     (ipc-posix-name-regex #"^CFPBS:")) ; <rdar://problem/13757475>
676 (allow system-fsctl (fsctl-command (_IO "h" 47)))
677
678 ;; Graphics
679 (system-graphics)
680
681 ;; Networking
682 #if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
683 (system-network)
684 #endif
685 (allow network-outbound
686        ;; Local mDNSResponder for DNS, arbitrary outbound TCP
687        ;; Note: This is needed for some media playback features. <rdar://problem/38191574>
688        ;; Remove this permission when <rdar://problem/38240572> is fixed.
689        (literal "/private/var/run/mDNSResponder")
690        ;; ObjC map_images needs to send logging data to syslog. <rdar://problem/39778918>
691        (literal "/private/var/run/syslog")
692        (remote tcp))
693
694 #if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
695 ;; CFNetwork
696 (allow file-read-data (path "/private/var/db/nsurlstoraged/dafsaData.bin"))
697 #endif
698
699 ;; Network Extensions / VPN helper.
700 (allow mach-lookup
701     (global-name "com.apple.nehelper")
702     (global-name "com.apple.nesessionmanager.content-filter")) ;; <rdar://problem/48442387>
703
704 #if PLATFORM(MAC)
705 ;; FIXME should be removed when <rdar://problem/9347205> + related radar in Safari is fixed
706 (allow mach-lookup
707        (global-name "com.apple.system.logger")
708        (global-name "com.apple.system.notification_center"))
709 #if __MAC_OS_X_VERSION_MIN_REQUIRED < 101300
710 (allow network-outbound
711        (remote udp))
712 #endif
713 #endif
714
715 (if (defined? 'vnode-type)
716         (deny file-write-create (vnode-type SYMLINK)))
717
718 ;; Reserve a namespace for additional protected extended attributes.
719 (deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\."))
720
721 (deny file-read* file-write* (with no-log)
722        ;; FIXME: Should be removed after <rdar://problem/10463881> is fixed.
723        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
724        (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
725
726 ;; Deny access needed for unnecessary NSApplication initialization.
727 ;; FIXME: This can be removed once <rdar://problem/13011633> is fixed.
728 (deny file-read* (with no-log)
729        (subpath "/Library/InputManagers")
730        (home-subpath "/Library/InputManagers"))
731 (deny user-preference-read (with no-log)
732     (preference-domain "com.apple.speech.recognition.AppleSpeechRecognition.prefs"))
733 (deny mach-lookup (with no-log)
734        (global-name "com.apple.coreservices.appleevents")
735        (global-name "com.apple.pasteboard.1")
736        (global-name "com.apple.speech.recognitionserver"))
737 #if PLATFORM(MAC)
738 ;; Also part of unnecessary NSApplication initialization, but we can't block access to these yet, see <rdar://problem/13869765>.
739 (allow file-read*
740        (subpath "/Library/Components")
741        (subpath "/Library/Keyboard Layouts")
742        (subpath "/Library/Input Methods")
743        (home-subpath "/Library/Components")
744        (home-subpath "/Library/Keyboard Layouts")
745        (home-subpath "/Library/Input Methods"))
746 #endif
747
748 ;; AirPlay
749 (allow mach-lookup
750     (global-name "com.apple.coremedia.endpoint.xpc")
751     (global-name "com.apple.coremedia.endpointstream.xpc")
752     (global-name "com.apple.coremedia.endpointplaybacksession.xpc")
753     ; <rdar://problem/35509194>
754     (global-name "com.apple.coremedia.endpointremotecontrolsession.xpc")
755 #if !PLATFORM(MAC) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
756     (global-name "com.apple.coremedia.routediscoverer.xpc")
757     (global-name "com.apple.coremedia.routingcontext.xpc")
758     (global-name "com.apple.coremedia.volumecontroller.xpc")
759 #endif
760 )
761
762 ;; Data Detectors
763 (allow file-read* (subpath "/private/var/db/datadetectors/sys"))
764
765 #if PLATFORM(MAC)
766 ;; Media capture, utilities
767 (if (not (defined? 'sbpl-filter?))
768   (define (sbpl-filter? x)
769       (and (list? x)
770            (eq? (car x) 'filter))))
771
772 (macro (with-filter form)
773    (let* ((ps (cdr form))
774           (extra-filter (car ps))
775           (rules (cdr ps)))
776     `(letrec
777         ((collect
778              (lambda (l filters non-filters)
779                  (if (null? l)
780                      (list filters non-filters)
781                      (let* 
782                          ((x (car l))
783                           (rest (cdr l)))
784                          (if (sbpl-filter? x)
785                              (collect rest (cons x filters) non-filters)
786                              (collect rest filters (cons x non-filters)))))))
787          (inject-filter
788              (lambda args
789                  (let* ((collected (collect args '() '()))
790                         (filters (car collected))
791                         (non-filters (cadr collected)))
792                  (if (null? filters)
793                      (cons ,extra-filter non-filters)
794                      (cons (require-all (apply require-any filters) ,extra-filter) non-filters)))))
795          (orig-allow allow)
796          (orig-deny deny)
797          (wrapper
798              (lambda (action)
799                  (lambda args (apply action (apply inject-filter args))))))
800         (set! allow (wrapper orig-allow))
801         (set! deny (wrapper orig-deny))
802         ,@rules
803         (set! deny orig-deny)
804         (set! allow orig-allow))))
805
806 (define (home-library-preferences-regex home-library-preferences-relative-regex)
807     (regex (string-append "^" (regex-quote (param "HOME_LIBRARY_PREFERENCES_DIR")) home-library-preferences-relative-regex)))
808
809 (define (home-library-preferences-literal home-library-preferences-relative-literal)
810     (literal (string-append (param "HOME_LIBRARY_PREFERENCES_DIR") home-library-preferences-relative-literal)))
811
812 (define (shared-preferences-read . domains)
813   (for-each (lambda (domain)
814               (begin
815                 (if (defined? `user-preference-read)
816                     (allow user-preference-read (preference-domain domain)))
817                 ; (Temporary) backward compatibility with non-CFPreferences readers.
818                 (allow file-read*
819                        (literal (string-append "/Library/Preferences/" domain ".plist"))
820                        (home-library-preferences-literal (string-append "/" domain ".plist"))
821                        (home-library-preferences-regex (string-append #"/ByHost/" (regex-quote domain) #"\..*\.plist$")))))
822             domains))
823
824 ;; Media capture, microphone access
825 (with-filter (extension "com.apple.webkit.microphone")
826     (allow device-microphone))
827
828 ;; Media capture, camera access
829 (with-filter (extension "com.apple.webkit.camera")
830     (shared-preferences-read "com.apple.coremedia")
831     (allow file-read* (subpath "/Library/CoreMediaIO/Plug-Ins/DAL"))
832     (allow mach-lookup (extension "com.apple.app-sandbox.mach"))
833     (allow mach-lookup
834         (global-name "com.apple.cmio.AppleCameraAssistant")
835         ;; Apple DAL assistants
836         (global-name "com.apple.cmio.VDCAssistant")
837         (global-name "com.apple.cmio.AVCAssistant")
838         (global-name "com.apple.cmio.IIDCVideoAssistant")
839         ;; QuickTimeIIDCDigitizer assistant
840         (global-name "com.apple.IIDCAssistant"))
841     (allow iokit-open
842         ;; QuickTimeUSBVDCDigitizer
843         (iokit-user-client-class "IOUSBDeviceUserClientV2")
844         (iokit-user-client-class "IOUSBInterfaceUserClientV2"))
845     (allow device-camera))
846 #endif // PLATFORM(MAC)
847
848 (when (defined? 'syscall-unix)
849     (deny syscall-unix (with send-signal SIGKILL))
850     (allow syscall-unix
851         (syscall-number SYS_exit)
852         (syscall-number SYS_read)
853         (syscall-number SYS_write)
854         (syscall-number SYS_open)
855         (syscall-number SYS_close)
856         (syscall-number SYS_unlink)
857         (syscall-number SYS_chmod)
858         (syscall-number SYS_getuid)
859         (syscall-number SYS_geteuid)
860         (syscall-number SYS_recvfrom)
861         (syscall-number SYS_getpeername)
862         (syscall-number SYS_access)
863         (syscall-number SYS_dup)
864         (syscall-number SYS_pipe)
865         (syscall-number SYS_getegid)
866         (syscall-number SYS_getgid)
867         (syscall-number SYS_sigprocmask)
868         (syscall-number SYS_sigaltstack)
869         (syscall-number SYS_ioctl)
870         (syscall-number SYS_readlink)
871         (syscall-number SYS_umask)
872         (syscall-number SYS_msync)
873         (syscall-number SYS_munmap)
874         (syscall-number SYS_mprotect)
875         (syscall-number SYS_madvise)
876         (syscall-number SYS_fcntl)
877         (syscall-number SYS_select)
878         (syscall-number SYS_fsync)
879         (syscall-number SYS_setpriority)
880         (syscall-number SYS_socket)
881         (syscall-number SYS_connect)
882         (syscall-number SYS_setsockopt)
883         (syscall-number SYS_gettimeofday)
884         (syscall-number SYS_getrusage)
885         (syscall-number SYS_getsockopt)
886         (syscall-number SYS_writev)
887         (syscall-number SYS_fchmod)
888         (syscall-number SYS_rename)
889         (syscall-number SYS_flock)
890         (syscall-number SYS_sendto)
891         (syscall-number SYS_shutdown)
892         (syscall-number SYS_socketpair)
893         (syscall-number SYS_mkdir)
894         (syscall-number SYS_rmdir)
895         (syscall-number SYS_pread)
896         (syscall-number SYS_pwrite)
897         (syscall-number SYS_csops)
898         (syscall-number SYS_csops_audittoken)
899         (syscall-number SYS_kdebug_trace64)
900         (syscall-number SYS_kdebug_trace)
901         (syscall-number SYS_sigreturn)
902         (syscall-number SYS_pathconf)
903         (syscall-number SYS_getrlimit)
904         (syscall-number SYS_setrlimit)
905         (syscall-number SYS_mmap)
906         (syscall-number SYS_lseek)
907         (syscall-number SYS_ftruncate)
908         (syscall-number SYS_sysctl)
909         (syscall-number SYS_mlock)
910         (syscall-number SYS_munlock)
911         (syscall-number SYS_getattrlist)
912         (syscall-number SYS_getxattr)
913         (syscall-number SYS_fgetxattr)
914         (syscall-number SYS_listxattr)
915         (syscall-number SYS_shm_open)
916         (syscall-number SYS_sem_wait)
917         (syscall-number SYS_sem_post)
918         (syscall-number SYS_sysctlbyname)
919         (syscall-number SYS_psynch_mutexwait)
920         (syscall-number SYS_psynch_mutexdrop)
921         (syscall-number SYS_psynch_cvbroad)
922         (syscall-number SYS_psynch_cvsignal)
923         (syscall-number SYS_psynch_cvwait)
924         (syscall-number SYS_psynch_rw_wrlock)
925         (syscall-number SYS_psynch_rw_unlock)
926         (syscall-number SYS_psynch_cvclrprepost)
927         (syscall-number SYS_process_policy)
928         (syscall-number SYS_issetugid)
929         (syscall-number SYS___pthread_kill)
930         (syscall-number SYS___pthread_sigmask)
931         (syscall-number SYS___disable_threadsignal)
932         (syscall-number SYS___semwait_signal)
933         (syscall-number SYS_proc_info)
934         (syscall-number SYS_stat64)
935         (syscall-number SYS_fstat64)
936         (syscall-number SYS_lstat64)
937         (syscall-number SYS_getdirentries64)
938         (syscall-number SYS_statfs64)
939         (syscall-number SYS_fstatfs64)
940         (syscall-number SYS_getfsstat64)
941         (syscall-number SYS_getaudit_addr)
942         (syscall-number SYS_bsdthread_create)
943         (syscall-number SYS_bsdthread_terminate)
944         (syscall-number SYS_workq_kernreturn)
945         (syscall-number SYS_thread_selfid)
946         (syscall-number SYS_kevent_qos)
947         (syscall-number SYS_kevent_id)
948         (syscall-number SYS___mac_syscall)
949         (syscall-number SYS_read_nocancel)
950         (syscall-number SYS_write_nocancel)
951         (syscall-number SYS_open_nocancel)
952         (syscall-number SYS_close_nocancel)
953         (syscall-number SYS_sendmsg_nocancel)
954         (syscall-number SYS_recvfrom_nocancel)
955         (syscall-number SYS_fcntl_nocancel)
956         (syscall-number SYS_select_nocancel)
957         (syscall-number SYS_connect_nocancel)
958         (syscall-number SYS_sendto_nocancel)
959         (syscall-number SYS_fsgetpath)
960         (syscall-number SYS_fileport_makeport)
961         (syscall-number SYS_guarded_open_np)
962         (syscall-number SYS_guarded_close_np)
963         (syscall-number SYS_change_fdguard_np)
964         (syscall-number SYS_proc_rlimit_control)
965         (syscall-number SYS_connectx)
966         (syscall-number SYS_getattrlistbulk)
967         (syscall-number SYS_openat)
968         (syscall-number SYS_openat_nocancel)
969         (syscall-number SYS_fstatat64)
970         (syscall-number SYS_mkdirat)
971         (syscall-number SYS_bsdthread_ctl)
972         (syscall-number SYS_csrctl)
973         (syscall-number SYS_guarded_pwrite_np)
974         (syscall-number SYS_getentropy)
975         (syscall-number SYS_necp_open)
976         (syscall-number SYS_necp_client_action)
977         (syscall-number SYS_ulock_wait)
978         (syscall-number SYS_ulock_wake)
979         (syscall-number SYS_work_interval_ctl)
980         (syscall-number SYS_kdebug_typefilter)
981         (syscall-number SYS_gettid) ;; Needed for base system, see <rdar://problem/48651255>
982         (syscall-number SYS_memorystatus_control) ;; Needed for memory measurement infrastructure, see <rdar://problem/48647263>
983         (syscall-number SYS_kdebug_trace_string) ;; Needed for performance sampling, see <rdar://problem/48829655>.
984         (syscall-number SYS_psynch_rw_rdlock) ;; <rdar://problem/49060359>
985         (syscall-number SYS_terminate_with_payload) ;; <rdar://problem/50026580>
986         (syscall-number SYS_quotactl) ;; <rdar://problem/49945031>
987         (syscall-number SYS_stat64_extended) ;; <rdar://problem/50473330>
988         (syscall-number SYS_lstat64_extended)
989     )
990 )
991