MCPcopy Create free account
hub / github.com/F-Stack/f-stack / sys___mac_set_fd

Function sys___mac_set_fd

freebsd/security/mac/mac_syscalls.c:386–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

384}
385
386int
387sys___mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap)
388{
389 struct label *intlabel;
390 struct pipe *pipe;
391 struct socket *so;
392 struct file *fp;
393 struct mount *mp;
394 struct vnode *vp;
395 struct mac mac;
396 cap_rights_t rights;
397 char *buffer;
398 int error;
399
400 error = copyin(uap->mac_p, &mac, sizeof(mac));
401 if (error)
402 return (error);
403
404 error = mac_check_structmac_consistent(&mac);
405 if (error)
406 return (error);
407
408 buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK);
409 error = copyinstr(mac.m_string, buffer, mac.m_buflen, NULL);
410 if (error) {
411 free(buffer, M_MACTEMP);
412 return (error);
413 }
414
415 error = fget(td, uap->fd, cap_rights_init_one(&rights, CAP_MAC_SET),
416 &fp);
417 if (error)
418 goto out;
419
420 switch (fp->f_type) {
421 case DTYPE_FIFO:
422 case DTYPE_VNODE:
423 if (!(mac_labeled & MPC_OBJECT_VNODE)) {
424 error = EINVAL;
425 goto out_fdrop;
426 }
427 intlabel = mac_vnode_label_alloc();
428 error = mac_vnode_internalize_label(intlabel, buffer);
429 if (error) {
430 mac_vnode_label_free(intlabel);
431 break;
432 }
433 vp = fp->f_vnode;
434 error = vn_start_write(vp, &mp, V_WAIT | PCATCH);
435 if (error != 0) {
436 mac_vnode_label_free(intlabel);
437 break;
438 }
439 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
440 error = vn_setlabel(vp, intlabel, td->td_ucred);
441 VOP_UNLOCK(vp);
442 vn_finished_write(mp);
443 mac_vnode_label_free(intlabel);

Callers

nothing calls this directly

Calls 15

mallocFunction · 0.85
fgetFunction · 0.85
mac_vnode_label_allocFunction · 0.85
mac_vnode_label_freeFunction · 0.85
vn_start_writeFunction · 0.85
vn_lockFunction · 0.85
vn_setlabelFunction · 0.85
vn_finished_writeFunction · 0.85
mac_pipe_label_allocFunction · 0.85

Tested by

no test coverage detected