|
| 1 | +<!-- |
| 2 | + SPDX-License-Identifier: CC-BY-SA-4.0 |
| 3 | + Copyright 2022 Kry10 |
| 4 | +--> |
| 5 | + |
| 6 | +# MCS: Improve constraints on grant via reply |
| 7 | + |
| 8 | +- Author: Matthew Brecknell |
| 9 | +- Proposed: 2022-11-04 |
| 10 | + |
| 11 | +## Summary |
| 12 | + |
| 13 | +In MCS configurations, the ability to grant capabilities when replying to a call |
| 14 | +is determined entirely by the grant right on the reply capability. If a server |
| 15 | +can create reply objects by retyping untyped memory, then it can also grant |
| 16 | +capabilities to its clients. Consequently, many realistic systems would not have |
| 17 | +the authority confinement property that we would expect. |
| 18 | + |
| 19 | +This RFC proposes two alternatives: |
| 20 | + |
| 21 | +- Both alternatives restrict the server's ability to grant via reply according |
| 22 | + to whether or not the grant right is present on the receive endpoint |
| 23 | + capability at the time the server called seL4_Recv. |
| 24 | + |
| 25 | +- The [first alternative] keeps the grant bit on reply object capabilities. |
| 26 | + Servers that want to grant via reply must have grant rights on both the |
| 27 | + receive endpoint capability and the reply object capability. |
| 28 | + |
| 29 | +- The [second alternative] removes the grant bit from reply object capabilities. |
| 30 | + Servers that want to grant via reply only need a grant right on the receive |
| 31 | + endpoint, but can't make reply object capabilities that mask those grant |
| 32 | + rights. |
| 33 | + |
| 34 | +[first alternative]: https://github.com/seL4/seL4/pull/874 |
| 35 | +[second alternative]: https://github.com/seL4/seL4/pull/945 |
| 36 | + |
| 37 | +## Motivation |
| 38 | + |
| 39 | +The [seL4 integrity theorems] show that seL4, in non-MCS configurations, can |
| 40 | +enforce access control policies. For example, one can construct a system in |
| 41 | +which untrusted client and server components can communicate through an |
| 42 | +endpoint, but cannot write to each other's private memory. |
| 43 | + |
| 44 | +The theorems are conditional: They require system setups that constrain the |
| 45 | +propagation of authority. In particular, grant rights are too powerful for the |
| 46 | +access control model, so one of the conditions is that untrusted components |
| 47 | +cannot grant or be granted capabilities. |
| 48 | + |
| 49 | +We would like to prove similar integrity theorems for MCS configurations, and |
| 50 | +therefore need appropriate mechanisms to limit capability grant rights between |
| 51 | +untrusted components. Currently, the only way to prevent an MCS server granting |
| 52 | +to its clients is to prevent it from retyping untyped memory. That's too severe |
| 53 | +a limitation. It's also an indirect mechanism, which would be difficult to |
| 54 | +express in an access control model. |
| 55 | + |
| 56 | +This RFC proposes a more direct mechanism for limiting an MCS server's ability |
| 57 | +to grant to its clients, and should provide a clearer path to useful integrity |
| 58 | +theorems for MCS configurations. |
| 59 | + |
| 60 | +[seL4 integrity theorems]: https://trustworthy.systems/publications/nictaabstracts/Sewell_WGMAK_11.abstract |
| 61 | + |
| 62 | +## Guide-level explanation |
| 63 | + |
| 64 | +We give a brief account of the history that led to the current situation. |
| 65 | + |
| 66 | +In the non-MCS kernel, there are no reply objects. Reply capabilities are |
| 67 | +generated by the kernel when a call is received through an endpoint, and |
| 68 | +inserted into a slot in the receiver's TCB. The kernel sets the grant right on |
| 69 | +the reply capability iff the grant right was set on the endpoint cap the |
| 70 | +receiver used when it called `seL4_Recv`. |
| 71 | + |
| 72 | +The intention of the design is that the receiver's endpoint capability controls |
| 73 | +the receiver's ability to grant capabilities when it replies. The implementation |
| 74 | +is the grant right on the reply capability, but the kernel ensures that the |
| 75 | +grant right on the generated reply capability is determined by the grant right |
| 76 | +on the receiver's endpoint capability. The intention is important, because |
| 77 | +endpoint rights are crucial to the ability to construct systems with useful |
| 78 | +access control properties. |
| 79 | + |
| 80 | +MCS changed the object-capability model, introducing reply objects and |
| 81 | +scheduling contexts. Reply objects make protected procedure call stacks more |
| 82 | +explicit, allowing scheduling contexts to be passed from caller to receiver and |
| 83 | +back again, potentially recursively. Reply object capabilities are supplied by |
| 84 | +the receiver, and the kernel internally links the reply object with the calling |
| 85 | +thread when a call is received. |
| 86 | + |
| 87 | +With respect to grant rights for replies, MCS reused parts of the implementation |
| 88 | +from the non-MCS kernel, but did not capture its intention. In both MCS and |
| 89 | +non-MCS, the ability to grant when replying is controlled by the grant bit on |
| 90 | +the reply capability. However, the way that bit is set is very different. In |
| 91 | +MCS, the grant right on a reply object capability is typically controlled by the |
| 92 | +receiver, if it can create reply objects. The grant right on the receiver's |
| 93 | +endpoint capability has no effect. Consequently, it is harder to construct MCS |
| 94 | +systems with useful access control properties. |
| 95 | + |
| 96 | +In this RFC, we propose changes that limit an MCS receiver's ability to grant |
| 97 | +when replying, according to the rights on the receiver's endpoint capability. |
| 98 | +The kernel propagates the endpoint grant right via the reply object. |
| 99 | + |
| 100 | +## Reference-level explanation |
| 101 | + |
| 102 | +We propose to add a boolean `canGrant` field to the MCS reply object. It is |
| 103 | +controlled by the kernel, and is only meaningful when the reply object is |
| 104 | +associated with either a receiver waiting for a caller, or a caller waiting for |
| 105 | +a reply. In those cases, the `canGrant` field indicates whether the |
| 106 | +`capcanGrant` bit was set on the receiver's endpoint capability when it called |
| 107 | +`seL4_Recv` or `seL4_ReplyRecv`. |
| 108 | + |
| 109 | +Regardless of whether a caller is waiting on the endpoint, the `canGrant` field |
| 110 | +of the reply object is set in receiveIPC, which is part of either `seL4_Recv` or |
| 111 | +`seL4_ReplyRecv`. In `receiveIPC`, the kernel has access to both the receiver's |
| 112 | +endpoint capability and its reply object capability, so it can directly copy the |
| 113 | +`capCanGrant` flag from the receive endpoint capability to the `canGrant` field |
| 114 | +of the reply object. |
| 115 | + |
| 116 | +If there is already a caller waiting, then the send phase of the call completes |
| 117 | +immediately, and the caller becomes blocked on the reply object. |
| 118 | + |
| 119 | +If the receiver has to block waiting for a caller, then either: |
| 120 | + |
| 121 | +- The receiver's IPC is cancelled before a caller arrives, and the reply object |
| 122 | + becomes dissociated from the receiver. In this case, the `canGrant` value that |
| 123 | + was set on the reply object is never used. |
| 124 | + |
| 125 | +- The receiver remains blocked until a caller arrives, and the `canGrant` field |
| 126 | + of the reply object still reflects the capCanGrant bit that was set on the |
| 127 | + receiver's endpoint capability. The send phase completes, and the caller |
| 128 | + becomes blocked on the reply object. |
| 129 | + |
| 130 | +Therefore, regardless of how the caller becomes blocked on the reply object, the |
| 131 | +`canGrant` field of the reply object reflects the capCanGrant bit on the endpoint |
| 132 | +capability used to receive that call. This is the property we'll need to prove a |
| 133 | +useful integrity theorem. |
| 134 | + |
| 135 | +This RFC includes two alternatives: |
| 136 | + |
| 137 | +- The [first alternative] only makes the change just described. The grant bit on |
| 138 | + the reply object capability (which is separate from the canGrant field of the |
| 139 | + reply object) is retained, and acts as a mask against the grant right on the |
| 140 | + receiver's endpoint capability. Therefore, to grant via a reply, a receiver |
| 141 | + would need grant rights on both the receive endpoint capability and the reply |
| 142 | + object capability. |
| 143 | + |
| 144 | +- The [second alternative] makes the change just described, and additionally |
| 145 | + removes the grant bit on reply object capabilities. To grant via a reply, a |
| 146 | + receiver only needs a grant right on the receive endpoint, but can't make a |
| 147 | + reply object capability that masks a grant right conferred by the receive |
| 148 | + endpoint. |
| 149 | + |
| 150 | +## Drawbacks |
| 151 | + |
| 152 | +The two alternatives are compared in the next section. |
| 153 | + |
| 154 | +Both alternatives have the potential to break existing MCS systems that include |
| 155 | +threads that: |
| 156 | + |
| 157 | +- receive calls on endpoint capabilities without grant rights, yet |
| 158 | + |
| 159 | +- expect to be able to grant capabilities when replying. |
| 160 | + |
| 161 | +Any such systems would need to be updated to add grant rights to the receive |
| 162 | +endpoint capabilities. |
| 163 | + |
| 164 | +Unfortunately, the breakage will only become evident when the caller tries to |
| 165 | +the use the capabilities it should have been granted. |
| 166 | + |
| 167 | +A mitigating factor is that non-MCS systems already require the grant bit to be |
| 168 | +set appropriately on receive endpoint capabilities, so systems ported from |
| 169 | +non-MCS to MCS should not be affected. |
| 170 | + |
| 171 | +## Rationale and alternatives |
| 172 | + |
| 173 | +We've already covered the rationale, so it only remains to compare the two |
| 174 | +alternatives. |
| 175 | + |
| 176 | +### Retaining the grant bit in reply object capabilities |
| 177 | + |
| 178 | +The [first alternative] retains the grant bit in the reply object capability. |
| 179 | +The code change is minimal. Any existing MCS systems that make use of the |
| 180 | +ability to mask grant rights via the reply object capability will continue to |
| 181 | +enjoy that ability, so the change does not give any thread permissions it did |
| 182 | +not already have. |
| 183 | + |
| 184 | +### Removing the grant bit in reply object capabilities |
| 185 | + |
| 186 | +The [second alternative] removes the grant bit in the reply object capability. |
| 187 | +This results in a simpler implementation and API semantics, but removes a |
| 188 | +feature that might be used in some MCS systems. There is [no corresponding |
| 189 | +feature in the non-MCS kernel][1], so the feature removal is only potentially |
| 190 | +relevant to MCS systems. |
| 191 | + |
| 192 | +Unfortunately, the only reasonable way to remove the feature is silently. This |
| 193 | +means that an existing MCS system that currently uses the feature to mask the |
| 194 | +grant rights of reply object capabilities will continue to work (assuming the |
| 195 | +corresponding receive endpoint capabilities have grant rights), but might |
| 196 | +include threads which gain permissions that the system designer did not intend. |
| 197 | +That is, there might be threads that did not previously have the right to grant |
| 198 | +capabilities when replying, that could gain that right when this alternative is |
| 199 | +implemented. |
| 200 | + |
| 201 | +The rationale for this alternative is that we think it is unlikely that there |
| 202 | +are any such systems. We are not aware of any real use cases, and have not been |
| 203 | +able to construct a hypothetical use case that is not [more easily implemented |
| 204 | +without this feature][2]. |
| 205 | + |
| 206 | +If there are any use cases, we would like to hear about them. |
| 207 | + |
| 208 | +[1]: https://github.com/seL4/seL4/pull/945#issuecomment-1302684909 |
| 209 | +[2]: https://github.com/seL4/seL4/pull/945#issuecomment-1301609528 |
| 210 | + |
| 211 | + |
| 212 | +## Prior art |
| 213 | + |
| 214 | +The main inspiration for this change is the non-MCS version of seL4, which: |
| 215 | + |
| 216 | +- already uses the grant bit on a receiver's endpoint capability to govern the |
| 217 | + receiver's ability to grant capabilities when replying. |
| 218 | + |
| 219 | +- [does not provide any facility to remove the grant right from a reply |
| 220 | + capability][1]. |
| 221 | + |
| 222 | +## Unresolved questions |
| 223 | + |
| 224 | +Is there a realistic use case for a grant bit on the reply object capability, |
| 225 | +that can be used to mask a grant right conferred by the receive endpoint |
| 226 | +capability? |
| 227 | + |
| 228 | +This is the main factor in choosing between the two alternatives. So far, the |
| 229 | +discussion on this issue has only shown a [hypothetical use case][3], which [did |
| 230 | +not survive scrutiny][2], and which for non-MCS systems, was based on a [mistaken |
| 231 | +understanding of the API semantics][1]. |
| 232 | + |
| 233 | +If you do use `seL4_CNode_Mint` to mask the grant rights of MCS reply object |
| 234 | +capabilities, we would like to hear from you. |
| 235 | + |
| 236 | +[3]: https://github.com/seL4/seL4/pull/874#issuecomment-1174670248 |
| 237 | + |
| 238 | +## Disposition |
| 239 | + |
| 240 | +The TSC as approved the option of the RFC that removes the grant right on the |
| 241 | +reply cap (the [second alternative]). Should there be appear a particular use |
| 242 | +case for it after all, it should be easy enough to consider another RFC to add |
| 243 | +it. |
0 commit comments