| 164 | } |
| 165 | |
| 166 | int |
| 167 | sys___mac_set_proc(struct thread *td, struct __mac_set_proc_args *uap) |
| 168 | { |
| 169 | struct ucred *newcred, *oldcred; |
| 170 | struct label *intlabel; |
| 171 | struct proc *p; |
| 172 | struct mac mac; |
| 173 | char *buffer; |
| 174 | int error; |
| 175 | |
| 176 | if (!(mac_labeled & MPC_OBJECT_CRED)) |
| 177 | return (EINVAL); |
| 178 | |
| 179 | error = copyin(uap->mac_p, &mac, sizeof(mac)); |
| 180 | if (error) |
| 181 | return (error); |
| 182 | |
| 183 | error = mac_check_structmac_consistent(&mac); |
| 184 | if (error) |
| 185 | return (error); |
| 186 | |
| 187 | buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK); |
| 188 | error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL); |
| 189 | if (error) { |
| 190 | free(buffer, M_MACTEMP); |
| 191 | return (error); |
| 192 | } |
| 193 | |
| 194 | intlabel = mac_cred_label_alloc(); |
| 195 | error = mac_cred_internalize_label(intlabel, buffer); |
| 196 | free(buffer, M_MACTEMP); |
| 197 | if (error) |
| 198 | goto out; |
| 199 | |
| 200 | newcred = crget(); |
| 201 | |
| 202 | p = td->td_proc; |
| 203 | PROC_LOCK(p); |
| 204 | oldcred = p->p_ucred; |
| 205 | |
| 206 | error = mac_cred_check_relabel(oldcred, intlabel); |
| 207 | if (error) { |
| 208 | PROC_UNLOCK(p); |
| 209 | crfree(newcred); |
| 210 | goto out; |
| 211 | } |
| 212 | |
| 213 | setsugid(p); |
| 214 | crcopy(newcred, oldcred); |
| 215 | mac_cred_relabel(newcred, intlabel); |
| 216 | proc_set_cred(p, newcred); |
| 217 | |
| 218 | PROC_UNLOCK(p); |
| 219 | crfree(oldcred); |
| 220 | mac_proc_vm_revoke(td); |
| 221 | |
| 222 | out: |
| 223 | mac_cred_label_free(intlabel); |
nothing calls this directly
no test coverage detected