1; Copyright (C) 2014 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(import "system.sb") 29 30;; Utility functions for home directory relative path filters 31(define (home-regex home-relative-regex) 32 (regex (string-append "^" (regex-quote (param "HOME_DIR")) home-relative-regex))) 33 34(define (home-subpath home-relative-subpath) 35 (subpath (string-append (param "HOME_DIR") home-relative-subpath))) 36 37(define (home-literal home-relative-literal) 38 (literal (string-append (param "HOME_DIR") home-relative-literal))) 39 40;; Read-only preferences and data 41(allow file-read* 42 ;; Basic system paths 43 (subpath "/Library/Frameworks") 44 (subpath "/Library/Managed Preferences") 45 46 ;; System and user preferences 47 (literal "/Library/Preferences/.GlobalPreferences.plist") 48 (home-literal "/Library/Preferences/.GlobalPreferences.plist") 49 (home-regex #"/Library/Preferences/ByHost/\.GlobalPreferences\.") 50 51 ;; On-disk WebKit2 framework location, to account for debug installations 52 ;; outside of /System/Library/Frameworks 53 (subpath (param "WEBKIT2_FRAMEWORK_DIR"))) 54 55;; Sandbox extensions 56(define (apply-read-and-issue-extension op path-filter) 57 (op file-read* path-filter) 58 (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter))) 59(define (apply-write-and-issue-extension op path-filter) 60 (op file-write* path-filter) 61 (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter))) 62(define (read-only-and-issue-extensions path-filter) 63 (apply-read-and-issue-extension allow path-filter)) 64(define (read-write-and-issue-extensions path-filter) 65 (apply-read-and-issue-extension allow path-filter) 66 (apply-write-and-issue-extension allow path-filter)) 67(read-only-and-issue-extensions (extension "com.apple.app-sandbox.read")) 68(read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write")) 69 70(if (defined? 'vnode-type) 71 (deny file-write-create (vnode-type SYMLINK))) 72 73;; FIXME: Should be removed once <rdar://problem/16329087> is fixed. 74(deny file-write-xattr (xattr "com.apple.quarantine") (with no-log)) 75 76;; Reserve a namespace for additional protected extended attributes. 77#if __MAC_OS_X_VERSION_MIN_REQUIRED > 1090 78(deny file-read-xattr file-write-xattr (xattr-regex #"^com\.apple\.security\.private\.")) 79#else 80(deny file-read-xattr file-write-xattr (xattr #"^com\.apple\.security\.private\.")) 81#endif 82