]> code.delx.au - refind/commitdiff
Further refinements to SIP/CSR/rootless support, including
authorsrs5694 <srs5694@users.sourceforge.net>
Thu, 5 Nov 2015 02:11:36 +0000 (21:11 -0500)
committersrs5694 <srs5694@users.sourceforge.net>
Thu, 5 Nov 2015 02:11:36 +0000 (21:11 -0500)
documentation.

14 files changed:
docs/refind/about.png [new file with mode: 0644]
docs/refind/configfile.html
docs/refind/func_csr_rotate.png [new file with mode: 0644]
docs/refind/recovery-mode.png [deleted file]
docs/refind/sip.html
docs/refind/using.html
refind.spec
refind/apple.c
refind/apple.h
refind/config.c
refind/global.h
refind/lib.c
refind/lib.h
refind/main.c

diff --git a/docs/refind/about.png b/docs/refind/about.png
new file mode 100644 (file)
index 0000000..e28fc11
Binary files /dev/null and b/docs/refind/about.png differ
index 5e8fc004b8b87ab7c7862e03dbcf2abad5493f29..c62fcd5fec6095f95c06b1a92fc4df5e42938bd9 100644 (file)
@@ -292,8 +292,8 @@ timeout 20
 </tr>
 <tr>
    <td><tt>showtools</tt></td>
-   <td><tt>shell</tt>, <tt>memtest</tt>, <tt>gdisk</tt>, <tt>gptsync</tt>, <tt>apple_recovery</tt>, <tt>mok_tool</tt>, <tt>netboot</tt>, <tt>about</tt>, <tt>exit</tt>, <tt>shutdown</tt>, <tt>reboot</tt>, and <tt>firmware</tt></td>
-   <td>Specifies which tool tags to display on the second row. <tt>shell</tt> launches an EFI shell, <tt>memtest</tt> (or <tt>memtest86</tt>) launches the <a href="http://www.memtest86.com/download.htm">Memtest86</a> program, <tt>gdisk</tt> launches the partitioning tool of the same name, <tt>gptsync</tt> launches a tool that creates a hybrid MBR, <tt>apple_recovery</tt> boots the OS X Recovery HD, <tt>windows_recovery</tt> boots a Windows recovery tool, <tt>mok_tool</tt> launches a tool to manage Machine Owner Keys (MOKs) on systems with Secure Boot active, <tt>netboot</tt> launches the network boot tool (iPXE), <tt>about</tt> displays information about rEFInd, <tt>exit</tt> terminates rEFInd, <tt>shutdown</tt> shuts down the computer (or reboots it, on some UEFI PCs), <tt>reboot</tt> reboots the computer, and <tt>firmware</tt> reboots the computer into the computer's own setup utility. The tags appear in the order in which you specify them. The default is <tt>shell, memtest, gdisk, apple_recovery, mok_tool, about, shutdown, reboot, firmware</tt>. Note that the <tt>shell</tt>, <tt>memtest</tt>, <tt>apple_recovery</tt>, and <tt>mok_tool</tt> options all require the presence of programs not included with rEFInd. The <tt>gptsync</tt> option requires use of a like-named program which, although it ships with rEFInd 0.6.9 and later, is not installed by default except under OS X. See the <a href="installing.html#addons">"Installing Additional Components"</a> section of the <a href="installing.html">Installing rEFInd</a> page for pointers to the shell, Memtest86, and <tt>gptsync</tt> programs. The <tt>apple_recovery</tt> option will appear only if you've got an Apple Recovery HD partition (which has a boot loader called <tt>com.apple.recovery.boot/boot.efi</tt>). The <tt>firmware</tt> option works only on computers that support this option; on other computers, the option is quietly ignored. See the <a href="secureboot.html">Secure Boot</a> page for information on Secure Boot and MOK management.</td>
+   <td><tt>shell</tt>, <tt>memtest</tt>, <tt>gdisk</tt>, <tt>gptsync</tt>, <tt>apple_recovery</tt>, <tt>csr_rotate</tt>, <tt>mok_tool</tt>, <tt>netboot</tt>, <tt>about</tt>, <tt>exit</tt>, <tt>shutdown</tt>, <tt>reboot</tt>, and <tt>firmware</tt></td>
+   <td>Specifies which tool tags to display on the second row. <tt>shell</tt> launches an EFI shell, <tt>memtest</tt> (or <tt>memtest86</tt>) launches the <a href="http://www.memtest86.com/download.htm">Memtest86</a> program, <tt>gdisk</tt> launches the partitioning tool of the same name, <tt>gptsync</tt> launches a tool that creates a hybrid MBR, <tt>apple_recovery</tt> boots the OS X Recovery HD, <tt>csr_rotate</tt> rotates through System Integrity Protection (SIP) values specified by <tt>csr_values</tt>, <tt>windows_recovery</tt> boots a Windows recovery tool, <tt>mok_tool</tt> launches a tool to manage Machine Owner Keys (MOKs) on systems with Secure Boot active, <tt>netboot</tt> launches the network boot tool (iPXE), <tt>about</tt> displays information about rEFInd, <tt>exit</tt> terminates rEFInd, <tt>shutdown</tt> shuts down the computer (or reboots it, on some UEFI PCs), <tt>reboot</tt> reboots the computer, and <tt>firmware</tt> reboots the computer into the computer's own setup utility. The tags appear in the order in which you specify them. The default is <tt>shell, memtest, gdisk, apple_recovery, mok_tool, about, shutdown, reboot, firmware</tt>. Note that the <tt>shell</tt>, <tt>memtest</tt>, <tt>apple_recovery</tt>, and <tt>mok_tool</tt> options all require the presence of programs not included with rEFInd. The <tt>gptsync</tt> option requires use of a like-named program which, although it ships with rEFInd 0.6.9 and later, is not installed by default except under OS X. See the <a href="installing.html#addons">"Installing Additional Components"</a> section of the <a href="installing.html">Installing rEFInd</a> page for pointers to the shell, Memtest86, and <tt>gptsync</tt> programs. The <tt>apple_recovery</tt> option will appear only if you've got an Apple Recovery HD partition (which has a boot loader called <tt>com.apple.recovery.boot/boot.efi</tt>). The <tt>firmware</tt> option works only on computers that support this option; on other computers, the option is quietly ignored. See the <a href="secureboot.html">Secure Boot</a> page for information on Secure Boot and MOK management.</td>
 </tr>
 <tr>
    <td><tt>font</tt></td>
@@ -395,6 +395,11 @@ timeout 20
    <td>string (<tt>10.9</tt> suggested)</td>
    <td>On some Macs, this option causes rEFInd to tell the firmware that the specified version of OS X is being launched, even when another OS is selected. The effect is that the firmware may initialize hardware differently, which may have beneficial (or detrimental) results. If your Mac's video output isn't working normally, this option may help. On the other hand, keyboards and mice are known to sometimes stop functioning if this option is used, so you shouldn't use it unnecessarily. This option has no effect on non-Apple hardware. The default is to not use this feature.</td>
 </tr>
+<tr>
+   <td><tt>csr_rotate</tt></td>
+   <td>List of hexadecimal values</td>
+   <td>Specifies values that may be set via the <tt>csr_rotate</tt> tool for Apple's System Integrity Protection (SIP). SIP stores values in NVRAM to set restrictions on what users (even <tt>root</tt>) may do in recent versions of OS X. If you want to be able to control these restrictions in rEFInd, you must set the values you want to use here <i>and</i> set <tt>csr_rotate</tt> on the <tt>showtools</tt> line (which must also be uncommented). Note that values are specified in hexadecimal, with no leading <tt>0x</tt> or other hexadecimal indicator. SIP is described in more detail on many Web sites, such as <a href="http://osxarena.com/2015/10/guide-details-apples-system-integrity-protection-sip-for-hackintosh/">here</a> and <a href="http://www.idelta.info/archives/sip-rootless-internal-in-el-capitan/">here.</a></td>
+</tr>
 <tr>
    <td><tt>include</tt></td>
    <td>filename</td>
diff --git a/docs/refind/func_csr_rotate.png b/docs/refind/func_csr_rotate.png
new file mode 100644 (file)
index 0000000..75fa419
Binary files /dev/null and b/docs/refind/func_csr_rotate.png differ
diff --git a/docs/refind/recovery-mode.png b/docs/refind/recovery-mode.png
deleted file mode 100644 (file)
index 8e6a54e..0000000
Binary files a/docs/refind/recovery-mode.png and /dev/null differ
index fa589b723ee044de72dc5267a24ae6241467e1de..905e4a0b2c399003cfe3100dc7a124d311a55601 100644 (file)
@@ -129,17 +129,61 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <hr />
 
-<p>Apple's OS X 10.11 (aka <i>El Capitan</i>) includes a new feature, known as System Integrity Protection (SIP), aka "rootless" mode. To understand SIP, you should first know that Unix-like systems, including OS X, have traditionally provided a model of security in which ordinary users can read and write their own files (word processor documents, their own digital photos, etc.), but not system files (programs, system configuration files, etc.). This system security model has worked well for decades on traditional Unix systems, which have been administered by computer professionals and used by individuals with less experience. For administrative tasks, the <tt>root</tt> account is used; on Macs, this access is generally granted by the <tt>sudo</tt> command or by various GUI tools. Most Macs are single-user computers that are administered by their users. Such people often lack the knowledge of the professional system administrators who have traditionally managed Unix systems; but they must still perform system administration tasks such as installing new software and configuring network settings. OS X has always provided some measure of security by requiring users to enter their passwords before performing these dangerous tasks, and by providing GUI tools to help guide users through these tasks in a way that minimizes the risk of damage.</p>
+<div style="float:right; width:55%">
+
+<p>Apple's OS X 10.11 (aka <i>El Capitan</i>) includes a new feature, known as System Integrity Protection (SIP), aka "rootless" mode. This feature is causing some consternation for advanced users, because it restricts what you can do with your computer, even as <tt>root</tt>. This page is dedicated to this new feature, including basic information on why SIP exists, how to install rEFInd on a computer with SIP enabled, and how to use rEFInd to manage SIP.</p>
+
+</div>
+
+<div class="navbar">
+
+<h4 class="tight">Contents</h4>
+
+<ul>
+
+<li class="tight"><a href="#what_is">What Is SIP?</li>
+
+<li class="tight"><a href="#sip_enabled">Installing rEFInd with SIP Enabled</a>
+
+  <ul>
+
+  <li class="tight"><a href="#recovery">Using Recovery Mode</a>
+
+  <li class="tight"><a href="#disable">Disabling SIP</a>
+
+  <li class="tight"><a href="#another">Using Another OS</a>
+
+  </ul>
+
+</li>
+
+<li class="tight"><a href="#refind_manage">Using rEFInd to Manage SIP</a></li>
+
+<li class="tight"><a href="#conclusion">Conclusion</a></li>
+
+</ul>
+
+</div>
+
+<a name="what_is">
+<h2>What Is SIP?</h2>
+</a>
+
+<p>To understand SIP, you should first know that Unix-like systems, including OS X, have traditionally provided a model of security in which ordinary users can read and write their own files (word processor documents, their own digital photos, etc.), but cannot write to system files (programs, system configuration files, etc.)&mdash;and users cannot even read some system files. This system security model has worked well for decades on traditional Unix systems, which have been administered by computer professionals and used by individuals with less experience. For administrative tasks, the <tt>root</tt> account is used. On Macs, this access is generally granted by the <tt>sudo</tt> command or by various GUI tools. Most Macs are single-user computers that are administered by their users. Such people often lack the knowledge of the professional system administrators who have traditionally managed Unix systems; but they must still perform system administration tasks such as installing new software and configuring network settings. OS X has always provided some measure of security by requiring users to enter their passwords before performing these dangerous tasks, and by providing GUI tools to help guide users through these tasks in a way that minimizes the risk of damage.</p>
 
 <p>Apple has apparently decided that these safeguards are no longer sufficient. I won't try to speak for Apple or explain their motivations, but the result of Apple's decisions is SIP. With SIP active, as is the default, OS X limits your ability to perform some of these administrative tasks. You can still install and remove most third-party programs, configure your network, and so on; but some critical directories can no longer be written, even as <tt>root</tt>, and some utilities cannot be used in certain ways, even as <tt>root</tt>. These restrictions impact rEFInd because one of the affected tools, a command called <tt>bless</tt>, is required to tell the Mac to boot rEFInd rather than to boot OS X directly.</p>
 
-<p>The end result of SIP is that rEFInd cannot be installed under OS X 10.11 in the way described on the <a href="installing.html">Installing rEFInd</a> page&mdash;at least, not without first booting into <a href="#recovery">Recovery mode,</a> in which SIP restrictions are ignored or <a href="#disable">disabling SIP.</a> This page covers these two options in more detail, as well as a third: <a href="#another">Using another OS</a> to install rEFInd.</p>
+<a name="sip_enabled">
+<h2>Installing rEFInd with SIP Enabled</h2>
+</a>
+
+<p>The end result of SIP is that rEFInd cannot be installed under OS X 10.11 in the way described on the <a href="installing.html">Installing rEFInd</a> page&mdash;at least, not without first booting into <a href="#recovery">Recovery mode,</a> in which SIP restrictions are ignored; or <a href="#disable">disabling SIP</a> (either temporarily or permanently). This page covers these two options in more detail, as well as a third: <a href="#another">Using another OS</a> to install rEFInd.</p>
 
 <a name="recovery">
-<h2>Using Recovery Mode</h2>
+<h3>Using Recovery Mode</h3>
 </a>
 
-<p>Unless you've deleted its partition, the Recovery HD partition should be present on your Mac as a way to perform emergency recovery operations. The nature of this tool means that SIP cannot be enabled, so you can install rEFInd from a boot to this partition. The trouble is that this installation is not a full-fledged OS X system, so you may have trouble using it if you're not comfortable with such a bare-bones environment. Nontheless, it is arguably the best way to install rEFInd on a Mac that runs OS X 10.11. To do so, follow these steps:</p>
+<p>Unless you've deleted it, the Recovery HD partition should be present on your Mac as a way to perform emergency recovery operations. The nature of this tool means that SIP cannot be enabled when using it, so you can install rEFInd from a boot to this partition. The trouble is that this installation is not a full-fledged OS X system, so you may have trouble using it if you're not comfortable with such a bare-bones environment. Nontheless, it is arguably the best way to install rEFInd on a Mac that runs OS X 10.11. To do so, follow these steps:</p>
 
 <ol>
 
@@ -147,11 +191,7 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <li>Reboot the computer.</li>
 
-<li>At the startup chime, hold down the Option+R key combination. The computer should launch into the Recovery system. This is a very bare system, with only a window providing a way to launch a handful of utilities and a menu bar, as shown here:</li>
-
-    <br /><center><img src="recovery-mode.png" align="center" width="814"
-    height="514" alt="To install rEFInd, you must launch the Terminal from
-    the menu bar." border=2> </center><br />
+<li>At the startup chime, hold down the Option+R key combination. The computer should launch into the Recovery system. This is a very bare system, with only a window providing a way to launch a handful of utilities and a menu bar. You must use the latter.</li>
 
 <li>Select Utilities -&gt; Terminal from the menu bar. A Terminal window should open.</li>
 
@@ -159,13 +199,13 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <li>Increase the size of the Terminal a bit. (This just makes its output more legible, since the next step produces long lines.)</li>
 
-<li>Type <tt class="userinput">df -h</tt> in the Terminal. This produces a list of partitions that are mounted. Locate the one on which you unpacked the rEFInd files. It will normally be <tt>/Volumes/<tt class="variable">Somename</tt></tt>, where <tt class="variable">Somename"</tt> is the volume's name.</li>
+<li>Type <tt class="userinput">df -h</tt> in the Terminal. This produces a list of partitions that are mounted. Locate the one on which you unpacked the rEFInd files. It will normally be <tt>/Volumes/<tt class="variable">Somename</tt></tt>, where <tt class="variable">Somename</tt> is the volume's name.</li>
 
-<li>In the Terminal, use <tt>cd</tt> to change to the directory where the rEFInd files you unpacked earlier are stored. For instance, on my MacBook, I would type <tt class="userinput">cd /Volumes/Macintosh\ HD/Users/rodsmith/Destkop/refind-0.9.3</tt>. Note that if any element of this path includes a space, you must either enclose the <i>entire path</i> in quotes or precede the space with a backslash (<tt>\</tt>), as in this example's <tt>Macintish\ HD</tt> volume name.</li>
+<li>In the Terminal, use <tt>cd</tt> to change to the directory where the rEFInd files you unpacked earlier are stored. For instance, on my MacBook, I would type <tt class="userinput">cd /Volumes/Macintosh\ HD/Users/rodsmith/Destkop/refind-0.10.1</tt>. Note that if any element of this path includes a space, you must either enclose the <i>entire path</i> in quotes or precede the space with a backslash (<tt>\</tt>), as in this example's <tt>Macintish\ HD</tt> volume name.</li>
 
 <li>Type <tt class="userinput">ls</tt> to verify that <tt>refind-install</tt> is present in this directory.</li>
 
-<li>Type <tt>./refind-install</tt> to run the installation script.</li> It should run normally, as described on the <a href="installing.html">Installing rEFInd</a> page. You can add options, if you like, as described on the Installing rEFInd page. Alternatively, you can perform a manual installation, also as described on that page.</li>
+<li>Type <tt class="userinput">./refind-install</tt> to run the installation script. It should run normally, as described on the <a href="installing.html">Installing rEFInd</a> page. You can add options, if you like, as described on that page. Alternatively, you can perform a manual installation, also as described on that page.</li>
 
 <li>Reboot.</li>
 
@@ -174,7 +214,7 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 <p>At this point, rEFInd should come up and enable you to boot into OS X and any other OS(es) that are already installed. You should not need to perform these steps again unless OS X re-installs its own boot loader or a subsequent OS installation overrides the default boot option. You can install an updated rEFInd and it should install correctly, provided you're installing it to the EFI System Partition (ESP). The <tt>refind-install</tt> script may complain about a failure, but because you're overwriting one rEFInd binary with another one, it should continue to boot.</p>
 
 <a name="disable">
-<h2>Disabling SIP</h2>
+<h3>Disabling SIP</h3>
 </a>
 
 <p>Another option is to disable SIP for your regular boot. This is a viable option if you're an expert who needs regular access to tools with which SIP interferes, such as low-level disk utilities. Regular users should probably avoid this option unless the preceding procedure does not work&mdash;and in that case, you should disable SIP temporarily and then re-enable it when you've finished installing rEFInd.</p>
@@ -190,7 +230,7 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 <p>If you want to re-enable SIP, you can do so in exactly the way you disabled it, except that you should type <tt class="userinput">csrutil enable</tt> rather than <tt class="userinput">csrutil disable</tt> in the Recovery environment.</p>
 
 <a name="another">
-<h2>Using Another OS</h2>
+<h3>Using Another OS</h3>
 </a>
 
 <p>A final option for installing rEFInd on a Mac that runs with SIP enabled is to do the installation using another OS. This other OS could be an OS that's already installed or an emergency boot disk, such as an <a href="http://www.ubuntu.com">Ubuntu</a> installation/recovery system.</p>
@@ -209,15 +249,50 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <p>I've tested this method of installing rEFInd on my MacBook Air, but I can't promise it will work on all Macs&mdash;or even on an identical Mac with a configuration that's different from mine. My preference is to install rEFInd under OS X on Macs, because Apple likes to do things differently from everybody else, and so a Mac's firmware might not react in the usual way to tools like <tt>efibootmgr</tt> in Linux or <tt>bcdedit</tt> in Windows.</p>
 
-<a name="conclusion">
-<h2>Conclusion</h2>
+<a name="refind_manage">
+<h2>Using rEFInd to Manage SIP</h2>
 </a>
 
-<p>Although the goal of increased security is a good one, SIP is causing problems for intermediate and advanced users. The good news is that the process to install rEFInd on a system that runs OS X 10.11, although more complex than it used to be, is not an impossible one. Furthermore, once you've done it, you shouldn't have to do it again for a while. (An update to OS X's boot loader is entirely possible, though. If nothing else, the next major OS X update may require re-installing rEFInd.)</p>
+<p>Once rEFInd is installed, you can use it to manage SIP features; however, the rEFInd features needed to do this are disabled by default. You must uncomment or add two lines to your <tt>refind.conf</tt> file:</p>
+
+<p class="sidebar"><b>Note:</b> Apple code samples and technical discussions are filled with the acronym "CSR." I don't know for what this acronym stands, but as it appears to be used in preference to "SIP" or "rootless" when referring to specific values, I used it in the <tt>refind.conf</tt> files token names.</p>
+
+<ul>
+
+<li><tt class="userinput">showtools</tt>&mdash;This line specifies tools that appear on the second row of icons in rEFInd. The new tool for managing SIP is called <tt>csr_rotate</tt>, so you must uncomment <tt>showtools</tt> and add this option, or create a new <tt>showtools</tt> line.</li>
+
+<li><tt class="userinput">csr_values</tt>&mdash;This line lists the hexadecimal values through which you can rotate once <tt>csr_rotate</tt> is active on the <tt>showtools</tt> line. The trick to this token is selecting appropriate options. Several sites, such as <a href="http://www.idelta.info/archives/sip-rootless-internal-in-el-capitan/">this one</a> and <a href="http://osxarena.com/2015/10/guide-details-apples-system-integrity-protection-sip-for-hackintosh/">this one,</a> describe the meanings of the various options, but often not in much detail. Apple's own <tt>csrutil</tt> command sets values of 77 (disabled) or 10 (enabled). Note also that you specify hexadecimal values on this line, but without a leading <tt>0x</tt> or other hexadecimal-notation indicator. If you put gibberish values, or hexadecimal values higher than those used by SIP, rEFInd ignores the bad entries. Thus, if some of your values are being ignored, you should check your <tt>csr_values</tt> line for typos.</li>
+
+</ul>
+
+<p>Note that <i><b>both</b></i> of these options must be set appropriately. If either of them is missing or misconfigured, rEFInd will not display the new SIP tool. A typical configuration using these features might look like this:</p>
 
-<p></p>
+<pre class="listing">showtools shell,memtest,gdisk,csr_rotate,apple_recovery,windows_recovery,mok_tool,about,shutdown,reboot,firmware
+csr_values 10,77</pre>
+
+    <img src="func_csr_rotate.png" align="right" width="48" height="48"
+    alt="The SIP rotation tool rotates through all the CSR values you set"
+    border=2 background="gray"/>
+
+<p>Once these options are set and you reboot into rEFInd, you should see a new shield icon, as shown at the right. When you select this tool, rEFInd identifies the next available CSR value from the list you specified and switches to that mode, rotating back to the start of the list once the end is reached. To confirm that the SIP mode has changed, rEFInd displays, for three seconds, a message identifying the new mode.</p>
+
+<p>Whether or not you've enabled these SIP features in <tt>refind.conf</tt>, rEFInd displays the current SIP status on its "About" page:</p>
+
+    <br /><center><img src="about.png" align="center" width="525"
+    height="559" alt="rEFInd presents a graphical menu for selecting your
+    boot OS." border=2> </center><br />
+
+<p>Note the line that reads "System Integrity Protection is disabled (0x77)." This line will be updated whenever you use the CSR rotation tool, so if you've specified a large number of values and have forgotten where you are in your rotation, you can use the About screen to figure it out.</p>
+
+<p>Both the summary on the About page and the CSR rotation tool depend on the presence of the <tt>csr-active-config</tt> NVRAM variable, which is where this information is stored. Thus, these features will not be present on older Macs that have not seen the presence of an OS X version that sets this variable. Likewise, you probably won't see the SIP summary in About or be able to set these values via <tt>csr_rotate</tt> and <tt>csr_values</tt> on a UEFI-based PC. (You could always create the variable on such a system in some other way, in which case rEFInd would let you adjust it, but it would have no effect on any OS except OS X.)</p>
+
+<p>I provide these features in rEFInd as a convenience for developers and other advanced users who have a legitimate need to adjust their SIP settings. Using rEFInd for this purpose is much faster than booting into the OS X Recovery system to make these adjustments. I discourage others from playing with these settings, since changing them inappropriately could cause problems; that's why they're not enabled by default.</p>
+
+<a name="conclusion">
+<h2>Conclusion</h2>
+</a>
 
-<p></p>
+<p>Although the goal of increased security is a good one, SIP is causing problems for intermediate and advanced users. The good news is that the process to install rEFInd on a system that runs OS X 10.11, although more complex than it used to be, is not an impossible one. Furthermore, once you've done it, you shouldn't have to do it again for a while. (An update to OS X's boot loader is entirely possible, though. If nothing else, the next major OS X update may require re-installing rEFInd.) For advanced users, rEFInd can adjust SIP settings, which can be helpful if you occasionally want to do something that require greater-than-typical privileges.</p>
 
 <hr />
 
index 8a79513a7b6f4943549287340e7c0887e1c00929..4d5f3e7820543a585fa2768bf3543a77d1bbfac9 100644 (file)
@@ -350,7 +350,7 @@ href="mailto:rodsmith@rodsbooks.com">rodsmith@rodsbooks.com</a></p>
 
 <p>The <tt>scanfor</tt> option, described on the <a href="configfile.html">Configuring the Boot Manager</a> page, controls rEFInd's detection of legacy OSes. On Macs, the default is to scan for such OSes, since a common boot scenario on Macs is dual-booting OS X and Windows, and of course BIOS support is required for this. On UEFI PCs, rEFInd defaults to <i>not</i> scanning for legacy OSes; thus, you must edit the <tt>scanfor</tt> item in the configuration file if you want to boot a legacy OS on a UEFI PC.</p>
 
-    <img src="os_legacy.png" align="right" width="139" height="141"
+    <img src="os_legacy.png" align="right" width="128" height="128"
     alt="The legacy OS icon is identical for all OSes on UEFI-based PCs."
     border=2 background="gray"/>
 
index 267e2be495e8c6c2f9790f412b335e60cd718ae2..7744be5709c5a09c9bb981f0460824350b0b194a 100644 (file)
@@ -1,6 +1,6 @@
 Summary: EFI boot manager software
 Name: refind
-Version: 0.9.2.4
+Version: 0.9.2.7
 Release: 1%{?dist}
 Summary: EFI boot manager software
 License: GPLv3
index d9ce9757112f9bd2745b0f110f333993c1b55f4b..bc72cbb9e5156a8454415e29259341b076d4d62c 100644 (file)
 CHAR16 *gCsrStatus = NULL;
 
 // Get CSR (Apple's System Integrity Protection [SIP], or "rootless") status
-// byte. Return values:
-// -2      = Call succeeded but returned value of unexpected length, so result
-//           is suspect
-// -1      = Call failed; likely not an Apple, or an Apple running OS X version
-//           that doesn't support CSR/SIP
-// 0-127   = Valid values (as of 11/2015)
-// 128-255 = High bit set unexpectedly, but value still returned
-INTN GetCsrStatus(VOID) {
-    CHAR8 *CsrValues;
-    UINTN CsrLength;
-    EFI_GUID CsrGuid = CSR_GUID;
-    EFI_STATUS Status;
-
-    Status = EfivarGetRaw(&CsrGuid, L"csr-active-config", &CsrValues, &CsrLength);
-    if (Status == EFI_SUCCESS) {
-        if (CsrLength == 4) {
-            return CsrValues[0];
-        } else {
-            return -2;
+// information.
+EFI_STATUS GetCsrStatus(UINT32 *CsrStatus) {
+    UINT32     *ReturnValue;
+    UINTN      CsrLength;
+    EFI_GUID   CsrGuid = CSR_GUID;
+    EFI_STATUS Status = EFI_INVALID_PARAMETER;
+
+    if (CsrStatus) {
+        Status = EfivarGetRaw(&CsrGuid, L"csr-active-config", (CHAR8**) &ReturnValue, &CsrLength);
+        if (Status == EFI_SUCCESS) {
+            if (CsrLength == 4) {
+                *CsrStatus = *ReturnValue;
+            } else {
+                Status = EFI_BAD_BUFFER_SIZE;
+            }
         }
-    } else {
-        return -1;
+        MyFreePool(ReturnValue);
     }
+    return Status;
 } // INTN GetCsrStatus()
 
 // Store string describing CSR status byte in gCsrStatus variable, which appears
-// on the Info page.
-VOID RecordgCsrStatus(INTN CsrStatus) {
+// on the Info page. If DisplayMessage is TRUE, displays the new value of
+// gCsrStatus on the screen for three seconds.
+VOID RecordgCsrStatus(UINT32 CsrStatus, BOOLEAN DisplayMessage) {
+    EG_PIXEL    BGColor;
+
+    BGColor.b = 255;
+    BGColor.g = 175;
+    BGColor.r = 100;
+    BGColor.a = 0;
+
     if (gCsrStatus == NULL)
         gCsrStatus = AllocateZeroPool(256 * sizeof(CHAR16));
 
     switch (CsrStatus) {
-        case -2:
-            SPrint(gCsrStatus, 255, L" System Integrity Protection status is unrecognized");
-            break;
-        case -1:
-            SPrint(gCsrStatus, 255, L"System Integrity Protection status is unrecorded");
-            break;
         case SIP_ENABLED:
             SPrint(gCsrStatus, 255, L" System Integrity Protection is enabled (0x%02x)", CsrStatus);
             break;
@@ -76,63 +74,37 @@ VOID RecordgCsrStatus(INTN CsrStatus) {
         default:
             SPrint(gCsrStatus, 255, L" System Integrity Protection status: 0x%02x", CsrStatus);
     } // switch
+    if (DisplayMessage) {
+        egDisplayMessage(gCsrStatus, &BGColor);
+        PauseSeconds(3);
+    } // if
 } // VOID RecordgCsrStatus
 
 // Find the current CSR status and reset it to the next one in the
 // GlobalConfig.CsrValues list, or to the first value if the current
 // value is not on the list.
 // Returns the value to which the CSR is being set.
-INTN RotateCsrValue(VOID) {
-    INTN        CurrentValue;
-    UINTN       Index = 0;
-    CHAR16      *CurrentValueAsString = NULL;
-    CHAR16      *TargetValueAsString = NULL;
-    CHAR16      *ListItem;
-    CHAR8       TargetCsr[4];
-    EFI_GUID    CsrGuid = CSR_GUID;
-    EFI_STATUS  Status;
-    EG_PIXEL    BGColor;
-
-    BGColor.b = 255;
-    BGColor.g = 175;
-    BGColor.r = 100;
-    BGColor.a = 0;
-    CurrentValue = GetCsrStatus();
-    if ((CurrentValue >= 0) && GlobalConfig.CsrValues) {
-        CurrentValueAsString = PoolPrint(L"%02x", CurrentValue);
-        while (TargetValueAsString == NULL) {
-            ListItem = FindCommaDelimited(GlobalConfig.CsrValues, Index++);
-            if (ListItem) {
-                if (MyStriCmp(ListItem, CurrentValueAsString)) {
-                    TargetValueAsString = FindCommaDelimited(GlobalConfig.CsrValues, Index);
-                    if (TargetValueAsString == NULL)
-                        TargetValueAsString = FindCommaDelimited(GlobalConfig.CsrValues, 0);
-                }
-            } else {
-                TargetValueAsString = FindCommaDelimited(GlobalConfig.CsrValues, 0);
-            } // if/else
-            MyFreePool(ListItem);
-        } // while
-        TargetCsr[0] = (CHAR8) StrToHex(TargetValueAsString, 0, 2);
-        Status = EfivarSetRaw(&CsrGuid, L"csr-active-config", TargetCsr, 4, TRUE);
-        if (Status == EFI_SUCCESS) {
-            switch (TargetCsr[0]) {
-                case SIP_ENABLED:
-                    egDisplayMessage(PoolPrint(L"Set System Integrity Protection to enabled (0x%x)", (UINTN) TargetCsr[0]), &BGColor);
-                    break;
-                case SIP_DISABLED:
-                    egDisplayMessage(PoolPrint(L"Set System Integrity Protection status to disabled (0x%x)", (UINTN) TargetCsr[0]), &BGColor);
-                    break;
-                default:
-                    egDisplayMessage(PoolPrint(L"Set System Integrity Protection status to 0x%x", (UINTN) TargetCsr[0]), &BGColor);
-            }
-            RecordgCsrStatus((INTN) TargetCsr[0]);
+VOID RotateCsrValue(VOID) {
+    UINT32       CurrentValue;
+    UINT32_LIST  *ListItem;
+    UINT32       TargetCsr;
+    EFI_GUID     CsrGuid = CSR_GUID;
+    EFI_STATUS   Status;
+
+    Status = GetCsrStatus(&CurrentValue);
+    if ((Status == EFI_SUCCESS) && GlobalConfig.CsrValues) {
+        ListItem = GlobalConfig.CsrValues;
+        while ((ListItem != NULL) && (ListItem->Value != CurrentValue))
+            ListItem = ListItem->Next;
+        if (ListItem == NULL || ListItem->Next == NULL) {
+            TargetCsr = GlobalConfig.CsrValues->Value;
         } else {
-            egDisplayMessage(L"Error setting System Integrity Protection status", &BGColor);
+            TargetCsr = ListItem->Next->Value;
         }
-        PauseSeconds(3);
+        Status = EfivarSetRaw(&CsrGuid, L"csr-active-config", (CHAR8 *) &TargetCsr, 4, TRUE);
+        if (Status == EFI_SUCCESS)
+            RecordgCsrStatus(TargetCsr, TRUE);
     } // if
-    return (INTN) TargetCsr[0];
 } // INTN RotateCsrValue()
 
 
@@ -166,7 +138,7 @@ EFI_STATUS SetAppleOSInfo() {
 
     Status = refit_call3_wrapper(BS->LocateProtocol, &apple_set_os_guid, NULL, (VOID**) &SetOs);
 
-    // Not a Mac, so ignore the call....
+    // If not a Mac, ignore the call....
     if ((Status != EFI_SUCCESS) || (!SetOs))
         return EFI_SUCCESS;
 
index 33fd5b2ad25abe9d03476833e7c5c0935deab9ec..17ed15506f0f7057af8406a90e3d7440af4f7ad1 100644 (file)
  *
  */
 
+#ifndef __APPLE_H_
+#define __APPLE_H_
+
+// The constants related to Apple's System Integrity Protection (SIP)....
+#define CSR_GUID { 0x7c436110, 0xab2a, 0x4bbb, { 0xa8, 0x80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82 } };
+// These codes are returned in the first byte of the csr-active-config variable
+#define CSR_ALLOW_UNTRUSTED_KEXTS       0x01
+#define CSR_ALLOW_UNRESTRICTED_FS       0x02
+#define CSR_ALLOW_TASK_FOR_PID          0x04
+#define CSR_ALLOW_KERNEL_DEBUGGER       0x08
+#define CSR_ALLOW_APPLE_INTERNAL        0x10
+#define CSR_ALLOW_UNRESTRICTED_DTRACE   0x20
+#define CSR_ALLOW_UNRESTRICTED_NVRAM    0x40
+#define CSR_END_OF_LIST                 0xFFFFFFFF
+// Some summaries....
+#define SIP_ENABLED  CSR_ALLOW_APPLE_INTERNAL
+#define SIP_DISABLED (CSR_ALLOW_UNRESTRICTED_NVRAM | \
+                      CSR_ALLOW_UNRESTRICTED_DTRACE | \
+                      CSR_ALLOW_APPLE_INTERNAL | \
+                      CSR_ALLOW_TASK_FOR_PID | \
+                      CSR_ALLOW_UNRESTRICTED_FS | \
+                      CSR_ALLOW_UNTRUSTED_KEXTS)
+#define CSR_MAX_LEGAL_VALUE (CSR_ALLOW_UNTRUSTED_KEXTS | \
+                             CSR_ALLOW_UNRESTRICTED_FS | \
+                             CSR_ALLOW_TASK_FOR_PID | \
+                             CSR_ALLOW_KERNEL_DEBUGGER | \
+                             CSR_ALLOW_APPLE_INTERNAL | \
+                             CSR_ALLOW_UNRESTRICTED_DTRACE | \
+                             CSR_ALLOW_UNRESTRICTED_NVRAM)
+
 extern CHAR16 *gCsrStatus;
 
-INTN GetCsrStatus(VOID);
-VOID RecordgCsrStatus(INTN CsrStatus);
-INTN RotateCsrValue(VOID);
+EFI_STATUS GetCsrStatus(UINT32 *CsrValue);
+VOID RecordgCsrStatus(UINT32 CsrStatus, BOOLEAN DisplayMessage);
+VOID RotateCsrValue(VOID);
 EFI_STATUS SetAppleOSInfo();
+
+#endif
\ No newline at end of file
index e54e56bc0cf8a0516a96fb9a8e65b4bf873f2a14..f592eb9a046c1b8384ceba1a373f7d82986a6663 100644 (file)
@@ -62,6 +62,7 @@
 #include "menu.h"
 #include "config.h"
 #include "screen.h"
+#include "apple.h"
 #include "../include/refit_call_wrapper.h"
 #include "../mok/mok.h"
 
@@ -377,6 +378,48 @@ static VOID HandleStrings(IN CHAR16 **TokenList, IN UINTN TokenCount, OUT CHAR16
    } // for
 } // static VOID HandleStrings()
 
+// Handle a parameter with a series of hexadecimal arguments, to replace or be added to a
+// linked list of UINT32 values. Any item with a non-hexadecimal value is discarded, as is
+// any value that exceeds MaxValue. If the first non-keyword token is "+", the new list is
+// added to the existing Target; otherwise, the interpreted tokens replace the current
+// Target.
+static VOID HandleHexes(IN CHAR16 **TokenList, IN UINTN TokenCount, IN UINTN MaxValue, OUT UINT32_LIST **Target) {
+    UINTN       InputIndex = 1, i;
+    UINT32      Value;
+    UINT32_LIST *EndOfList = NULL;
+    UINT32_LIST *NewEntry;
+
+    if ((TokenCount > 2) && (StrCmp(TokenList[1], L"+") == 0)) {
+        InputIndex = 2;
+        EndOfList = *Target;
+        while (EndOfList && (EndOfList->Next != NULL)) {
+            EndOfList = EndOfList->Next;
+        }
+    } else {
+        EraseUint32List(Target);
+    }
+
+    for (i = InputIndex; i < TokenCount; i++) {
+        if (IsValidHex(TokenList[i])) {
+            Value = (UINT32) StrToHex(TokenList[i], 0, 8);
+            if (Value <= MaxValue) {
+                NewEntry = AllocatePool(sizeof(UINT32_LIST));
+                if (NewEntry) {
+                    NewEntry->Value = Value;
+                    NewEntry->Next = NULL;
+                    if (EndOfList == NULL) {
+                        EndOfList = NewEntry;
+                        *Target = NewEntry;
+                    } else {
+                        EndOfList->Next = NewEntry;
+                        EndOfList = NewEntry;
+                    } // if/else
+                } // if allocated memory for NewEntry
+            } // if (Value < MaxValue)
+        } // if is valid hex value
+    } // for
+} // static VOID HandleHexes()
+
 // Convert TimeString (in "HH:MM" format) to a pure-minute format. Values should be
 // in the range from 0 (for 00:00, or midnight) to 1439 (for 23:59; aka LAST_MINUTE).
 // Any value outside that range denotes an error in the specification. Note that if
@@ -707,7 +750,7 @@ VOID ReadConfig(CHAR16 *FileName)
             HandleString(TokenList, TokenCount, &(GlobalConfig.SpoofOSXVersion));
 
         } else if (MyStriCmp(TokenList[0], L"csr_values")) {
-            HandleStrings(TokenList, TokenCount, &(GlobalConfig.CsrValues));
+            HandleHexes(TokenList, TokenCount, CSR_MAX_LEGAL_VALUE, &(GlobalConfig.CsrValues));
 
         } else if (MyStriCmp(TokenList[0], L"include") && (TokenCount == 2) && MyStriCmp(FileName, GlobalConfig.ConfigFilename)) {
            if (!MyStriCmp(TokenList[1], FileName)) {
index a07e0c90d74f4815e00dcecf942f8fdb77f49de7..8acbf7dc603457f26fb857624010f33c24fcf5af 100644 (file)
 #define ICON_SIZE_SMALL 1
 #define ICON_SIZE_BIG   2
 
-// The constants related to Apple's System Integrity Protection (SIP)....
-#define CSR_GUID { 0x7c436110, 0xab2a, 0x4bbb, { 0xa8, 0x80, 0xfe, 0x41, 0x99, 0x5c, 0x9f, 0x82 } };
-// These codes are returned in the first byte of the csr-active-config variable
-#define CSR_ALLOW_UNTRUSTED_KEXTS       0x01
-#define CSR_ALLOW_UNRESTRICTED_FS       0x02
-#define CSR_ALLOW_TASK_FOR_PID          0x04
-#define CSR_ALLOW_KERNEL_DEBUGGER       0x08
-#define CSR_ALLOW_APPLE_INTERNAL        0x10
-#define CSR_ALLOW_UNRESTRICTED_DTRACE   0x20
-#define CSR_ALLOW_UNRESTRICTED_NVRAM    0x40
-// Some summaries....
-#define SIP_ENABLED  CSR_ALLOW_APPLE_INTERNAL
-#define SIP_DISABLED (CSR_ALLOW_UNRESTRICTED_NVRAM | \
-                      CSR_ALLOW_UNRESTRICTED_DTRACE | \
-                      CSR_ALLOW_APPLE_INTERNAL | \
-                      CSR_ALLOW_TASK_FOR_PID | \
-                      CSR_ALLOW_UNRESTRICTED_FS | \
-                      CSR_ALLOW_UNTRUSTED_KEXTS)
-
 // Names of binaries that can manage MOKs....
 #define MOK_NAMES               L"MokManager.efi,HashTool.efi,HashTool-signed.efi,KeyTool.efi,KeyTool-signed.efi"
 // Directories to search for these MOK-managing programs. Note that SelfDir is
 
 // global types
 
+typedef struct _uint32_list {
+    UINT32               Value;
+    struct _uint32_list  *Next;
+} UINT32_LIST;
+
 typedef struct {
    UINT8 Flags;
    UINT8 StartCHS1;
@@ -326,7 +312,7 @@ typedef struct {
    CHAR16           *DriverDirs;
    CHAR16           *IconsDir;
    CHAR16           *SpoofOSXVersion;
-   CHAR16           *CsrValues;
+   UINT32_LIST      *CsrValues;
    UINTN            ShowTools[NUM_TOOLS];
    CHAR8            ScanFor[NUM_SCAN_OPTIONS]; // codes of types of loaders for which to scan
 } REFIT_CONFIG;
index 46e265095e68c9fb5ceab46747da1ded50ad751f..3a75cdfdcacb62cb8746ed225184c7c86e05c73c 100644 (file)
@@ -2031,6 +2031,23 @@ BOOLEAN EjectMedia(VOID) {
     return (Ejected > 0);
 } // VOID EjectMedia()
 
+// Returns TRUE if *Input contains nothing but valid hexadecimal characters,
+// FALSE otherwise. Note that a leading "0x" is NOT acceptable in the input!
+BOOLEAN IsValidHex(CHAR16 *Input) {
+    BOOLEAN IsHex = TRUE;
+    UINTN i = 0;
+
+    while ((Input[i] != L'\0') && IsHex) {
+        if (!(((Input[i] >= L'0') && (Input[i] <= L'9')) ||
+              ((Input[i] >= L'A') && (Input[i] <= L'F')) ||
+              ((Input[i] >= L'a') && (Input[i] <= L'f')))) {
+                IsHex = FALSE;
+        }
+        i++;
+    } // while
+    return IsHex;
+} // BOOLEAN IsValidHex()
+
 // Converts consecutive characters in the input string into a
 // number, interpreting the string as a hexadecimal number, starting
 // at the specified position and continuing for the specified number
@@ -2140,3 +2157,14 @@ EFI_GUID StringAsGuid(CHAR16 * InString) {
 BOOLEAN GuidsAreEqual(EFI_GUID *Guid1, EFI_GUID *Guid2) {
     return (CompareMem(Guid1, Guid2, 16) == 0);
 } // BOOLEAN GuidsAreEqual()
+
+// Erase linked-list of UINT32 values....
+VOID EraseUint32List(UINT32_LIST **TheList) {
+    UINT32_LIST *NextItem;
+
+    while (*TheList) {
+        NextItem = (*TheList)->Next;
+        FreePool(*TheList);
+        *TheList = NextItem;
+    } // while
+} // EraseUin32List()
index 376efd7604440e5409873098a2a59697f18f860c..037605c88da8d98f0ea6ae24e63883f76e255703 100644 (file)
@@ -141,10 +141,13 @@ VOID MyFreePool(IN OUT VOID *Pointer);
 
 BOOLEAN EjectMedia(VOID);
 
+BOOLEAN IsValidHex(CHAR16 *Input);
 UINT64 StrToHex(CHAR16 *Input, UINTN Position, UINTN NumChars);
 BOOLEAN IsGuid(CHAR16 *UnknownString);
 CHAR16 * GuidAsString(EFI_GUID *GuidData);
 EFI_GUID StringAsGuid(CHAR16 * InString);
 BOOLEAN GuidsAreEqual(EFI_GUID *Guid1, EFI_GUID *Guid2);
 
+VOID EraseUint32List(UINT32_LIST **TheList);
+
 #endif
\ No newline at end of file
index f16908609db6940cdf45da3be38f02acb056d117..6234a974f7d0f3020ee067e49afcff2d73f5f714 100644 (file)
@@ -187,12 +187,12 @@ struct LOADER_LIST {
 
 static VOID AboutrEFInd(VOID)
 {
-    CHAR16 *FirmwareVendor;
-    INTN   CsrStatus;
+    CHAR16     *FirmwareVendor;
+    UINT32     CsrStatus;
 
     if (AboutMenu.EntryCount == 0) {
         AboutMenu.TitleImage = BuiltinIcon(BUILTIN_ICON_FUNC_ABOUT);
-        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.9.2.6");
+        AddMenuInfoLine(&AboutMenu, L"rEFInd Version 0.9.2.7");
         AddMenuInfoLine(&AboutMenu, L"");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2006-2010 Christoph Pfisterer");
         AddMenuInfoLine(&AboutMenu, L"Copyright (c) 2012-2015 Roderick W. Smith");
@@ -210,10 +210,10 @@ static VOID AboutrEFInd(VOID)
 #else
         AddMenuInfoLine(&AboutMenu, L" Platform: unknown");
 #endif
-        CsrStatus = GetCsrStatus();
-        RecordgCsrStatus(CsrStatus);
-        if ((CsrStatus == -2) || (CsrStatus >= 0))
+        if (GetCsrStatus(&CsrStatus) == EFI_SUCCESS) {
+            RecordgCsrStatus(CsrStatus, FALSE);
             AddMenuInfoLine(&AboutMenu, gCsrStatus);
+        }
         FirmwareVendor = StrDuplicate(ST->FirmwareVendor);
         LimitStringLength(FirmwareVendor, MAX_LINE_LENGTH); // More than ~65 causes empty info page on 800x600 display
         AddMenuInfoLine(&AboutMenu, PoolPrint(L" Firmware: %s %d.%02d", FirmwareVendor, ST->FirmwareRevision >> 16,
@@ -1912,6 +1912,7 @@ static VOID ScanForTools(VOID) {
     UINTN i, j, VolumeIndex;
     UINT64 osind;
     CHAR8 *b = 0;
+    UINT32 CsrValue;
 
     MokLocations = StrDuplicate(MOK_LOCATIONS);
     if (MokLocations != NULL)
@@ -2043,7 +2044,7 @@ static VOID ScanForTools(VOID) {
                 break;
 
             case TAG_CSR_ROTATE:
-                if ((GetCsrStatus() >= 0) && (GlobalConfig.CsrValues)) {
+                if ((GetCsrStatus(&CsrValue) == EFI_SUCCESS) && (GlobalConfig.CsrValues)) {
                     TempMenuEntry = CopyMenuEntry(&MenuEntryRotateCsr);
                     TempMenuEntry->Image = BuiltinIcon(BUILTIN_ICON_FUNC_CSR_ROTATE);
                     AddMenuEntry(&MainMenu, TempMenuEntry);