]>
git.saurik.com Git - apple/xnu.git/blob - san/tools/kasan_install
4 # kasan_install: set up a system to run the KASan kernel. Run with "--uninstall"
5 # to reverse the setup.
7 # Installs a symlink to the kernel kasan in /System/Library/Kernels/kernel.kasan
8 # and adds kcsuffix=kasan to boot-args.
12 kernel_name
=kernel.kasan
13 kernel_src
=/AppleInternal
/CoreOS
/xnu_kasan
/${kernel_name}
14 SLK
=/System
/Library
/Kernels
/
15 kernel_dst
=${SLK}${kernel_name}
17 if [[ `whoami` != root
]] ; then
18 echo "Re-running with sudo"
24 csrutil status
|grep -q enabled
41 if [[ ! -f $kernel_src ]] ; then
42 echo "No KASan kernel found at $kernel_src"
46 echo -n "Installing KASan kernel... "
48 if [[ -L $kernel_dst && $kernel_dst -ef $kernel_src ]] ; then
49 echo "already installed."
50 elif [[ -f $kernel_dst ]] ; then
51 prompt
"file exists. Overwrite?" && {
52 echo -n "Overwriting KASan kernel... "
59 # Use a temporary directory with a symlink to kernel.kasan. We can ditto
60 # from there into /S/L/K, even with SIP enabled.
61 [[ $dosymlink -eq 1 ]] && {
62 tmp
=$(mktemp -d) || exit $?
63 ln -s "$kernel_src" "$tmp" || exit $?
64 ditto
"$tmp" "$SLK" || exit $?
70 echo -n "Checking KASan boot args... "
72 bootargs
=$(nvram boot-args | cut -f2)
73 cursuffix
=$(echo $bootargs | sed -n 's/.*kcsuffix=\([^ ]\)/\
1/p
')
75 if [[ "$cursuffix" == kasan ]] ; then
77 elif [[ -n "$cursuffix" ]] ; then
78 prompt "custom kcsuffix ($cursuffix) is set. Overwrite?" && {
79 bootargs=$(echo "$bootargs" | sed 's/[ ]*kcsuffix=[^ ]*//')
83 prompt "not set. Modify?" && {
88 [[ $dobootargs -eq 1 ]] && {
89 echo -n "Adding boot arg kcsuffix=kasan... "
90 newlen=$(echo -n "$bootargs kcsuffix=kasan" |wc -c)
91 if [[ $newlen -ge 512 ]] ; then
92 echo "boot-args too long. Bailing."
96 nvram boot-args="$bootargs kcsuffix=kasan" || exit $?
100 [[ $dosymlink -eq 1 ]] && {
101 echo -n "Triggering kernel cache rebuild... "
102 touch /System/Library/Extensions || exit $?
111 echo -n "Removing kasan kernel... "
115 if [[ -L $kernel_dst && $kernel_dst -ef $kernel_src ]] ; then
117 elif [[ -f $kernel_dst ]] ; then
118 prompt "unexpected file. Remove anyway?" && {
122 echo "not installed."
125 [[ $dorm -eq 1 ]] && {
126 if rm "$kernel_dst" ; then
129 if sip_enabled ; then
130 echo "failed due to SIP - this is normal."
136 echo -n "Removing boot args... "
138 bootargs=$(nvram boot-args | cut -f2)
139 cursuffix=$(echo $bootargs | sed -n 's/.*kcsuffix=\([^ ]\)/\1/p')
141 if [[ $cursuffix == "kasan" ]] ; then
142 prompt
"remove kcsuffix=kasan?" && {
143 echo -n "Removing kcsuffix... "
144 bootargs
=$(echo "$bootargs" | sed 's/[ ]*kcsuffix=[^ ]*//')
145 nvram boot
-args="$bootargs"
155 *uninstall
|*del
*|*remove
|*rm)