uipc_usrreq.c (c08e016f000ce417a6fb413025ab81ad66cbdfff) | uipc_usrreq.c (bfd03046d18776ea70785ca1ef36dfc60822de3b) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1982, 1986, 1989, 1991, 1993 5 * The Regents of the University of California. All Rights Reserved. 6 * Copyright (c) 2004-2009 Robert N. M. Watson All Rights Reserved. 7 * Copyright (c) 2018 Matthew Macy 8 * Copyright (c) 2022 Gleb Smirnoff <glebius@FreeBSD.org> --- 470 unchanged lines hidden (view full) --- 479 unp = uma_zalloc(unp_zone, M_NOWAIT | M_ZERO); 480 if (unp == NULL) 481 return (ENOBUFS); 482 LIST_INIT(&unp->unp_refs); 483 UNP_PCB_LOCK_INIT(unp); 484 unp->unp_socket = so; 485 so->so_pcb = unp; 486 refcount_init(&unp->unp_refcount, 1); | 1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1982, 1986, 1989, 1991, 1993 5 * The Regents of the University of California. All Rights Reserved. 6 * Copyright (c) 2004-2009 Robert N. M. Watson All Rights Reserved. 7 * Copyright (c) 2018 Matthew Macy 8 * Copyright (c) 2022 Gleb Smirnoff <glebius@FreeBSD.org> --- 470 unchanged lines hidden (view full) --- 479 unp = uma_zalloc(unp_zone, M_NOWAIT | M_ZERO); 480 if (unp == NULL) 481 return (ENOBUFS); 482 LIST_INIT(&unp->unp_refs); 483 UNP_PCB_LOCK_INIT(unp); 484 unp->unp_socket = so; 485 so->so_pcb = unp; 486 refcount_init(&unp->unp_refcount, 1); |
487 unp->unp_mode = ACCESSPERMS; |
|
487 488 if ((locked = UNP_LINK_WOWNED()) == false) 489 UNP_LINK_WLOCK(); 490 491 unp->unp_gencnt = ++unp_gencnt; 492 unp->unp_ino = ++unp_ino; 493 unp_count++; 494 switch (so->so_type) { --- 26 unchanged lines hidden (view full) --- 521 struct vattr vattr; 522 int error, namelen; 523 struct nameidata nd; 524 struct unpcb *unp; 525 struct vnode *vp; 526 struct mount *mp; 527 cap_rights_t rights; 528 char *buf; | 488 489 if ((locked = UNP_LINK_WOWNED()) == false) 490 UNP_LINK_WLOCK(); 491 492 unp->unp_gencnt = ++unp_gencnt; 493 unp->unp_ino = ++unp_ino; 494 unp_count++; 495 switch (so->so_type) { --- 26 unchanged lines hidden (view full) --- 522 struct vattr vattr; 523 int error, namelen; 524 struct nameidata nd; 525 struct unpcb *unp; 526 struct vnode *vp; 527 struct mount *mp; 528 cap_rights_t rights; 529 char *buf; |
530 mode_t mode; |
|
529 530 if (nam->sa_family != AF_UNIX) 531 return (EAFNOSUPPORT); 532 533 unp = sotounpcb(so); 534 KASSERT(unp != NULL, ("uipc_bind: unp == NULL")); 535 536 if (soun->sun_len > sizeof(struct sockaddr_un)) --- 16 unchanged lines hidden (view full) --- 553 UNP_PCB_UNLOCK(unp); 554 return (EINVAL); 555 } 556 if (unp->unp_flags & UNP_BINDING) { 557 UNP_PCB_UNLOCK(unp); 558 return (EALREADY); 559 } 560 unp->unp_flags |= UNP_BINDING; | 531 532 if (nam->sa_family != AF_UNIX) 533 return (EAFNOSUPPORT); 534 535 unp = sotounpcb(so); 536 KASSERT(unp != NULL, ("uipc_bind: unp == NULL")); 537 538 if (soun->sun_len > sizeof(struct sockaddr_un)) --- 16 unchanged lines hidden (view full) --- 555 UNP_PCB_UNLOCK(unp); 556 return (EINVAL); 557 } 558 if (unp->unp_flags & UNP_BINDING) { 559 UNP_PCB_UNLOCK(unp); 560 return (EALREADY); 561 } 562 unp->unp_flags |= UNP_BINDING; |
563 mode = unp->unp_mode & ~td->td_proc->p_pd->pd_cmask; |
|
561 UNP_PCB_UNLOCK(unp); 562 563 buf = malloc(namelen + 1, M_TEMP, M_WAITOK); 564 bcopy(soun->sun_path, buf, namelen); 565 buf[namelen] = 0; 566 567restart: 568 NDINIT_ATRIGHTS(&nd, CREATE, NOFOLLOW | LOCKPARENT | NOCACHE, --- 16 unchanged lines hidden (view full) --- 585 } 586 error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH); 587 if (error) 588 goto error; 589 goto restart; 590 } 591 VATTR_NULL(&vattr); 592 vattr.va_type = VSOCK; | 564 UNP_PCB_UNLOCK(unp); 565 566 buf = malloc(namelen + 1, M_TEMP, M_WAITOK); 567 bcopy(soun->sun_path, buf, namelen); 568 buf[namelen] = 0; 569 570restart: 571 NDINIT_ATRIGHTS(&nd, CREATE, NOFOLLOW | LOCKPARENT | NOCACHE, --- 16 unchanged lines hidden (view full) --- 588 } 589 error = vn_start_write(NULL, &mp, V_XSLEEP | V_PCATCH); 590 if (error) 591 goto error; 592 goto restart; 593 } 594 VATTR_NULL(&vattr); 595 vattr.va_type = VSOCK; |
593 vattr.va_mode = (ACCESSPERMS & ~td->td_proc->p_pd->pd_cmask); | 596 vattr.va_mode = mode; |
594#ifdef MAC 595 error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, 596 &vattr); 597#endif 598 if (error == 0) { 599 /* 600 * The prior lookup may have left LK_SHARED in cn_lkflags, 601 * and VOP_CREATE technically only requires the new vnode to --- 96 unchanged lines hidden (view full) --- 698 UNP_PCB_UNLOCK(unp); 699 if (vp) { 700 mtx_unlock(vplock); 701 vrele(vp); 702 } 703} 704 705static int | 597#ifdef MAC 598 error = mac_vnode_check_create(td->td_ucred, nd.ni_dvp, &nd.ni_cnd, 599 &vattr); 600#endif 601 if (error == 0) { 602 /* 603 * The prior lookup may have left LK_SHARED in cn_lkflags, 604 * and VOP_CREATE technically only requires the new vnode to --- 96 unchanged lines hidden (view full) --- 701 UNP_PCB_UNLOCK(unp); 702 if (vp) { 703 mtx_unlock(vplock); 704 vrele(vp); 705 } 706} 707 708static int |
709uipc_chmod(struct socket *so, mode_t mode, struct ucred *cred __unused, 710 struct thread *td __unused) 711{ 712 struct unpcb *unp; 713 int error; 714 715 if ((mode & ~ACCESSPERMS) != 0) 716 return (EINVAL); 717 718 error = 0; 719 unp = sotounpcb(so); 720 UNP_PCB_LOCK(unp); 721 if (unp->unp_vnode != NULL || (unp->unp_flags & UNP_BINDING) != 0) 722 error = EINVAL; 723 else 724 unp->unp_mode = mode; 725 UNP_PCB_UNLOCK(unp); 726 return (error); 727} 728 729static int |
|
706uipc_connect2(struct socket *so1, struct socket *so2) 707{ 708 struct unpcb *unp, *unp2; 709 710 if (so1->so_type != so2->so_type) 711 return (EPROTOTYPE); 712 713 unp = so1->so_pcb; --- 2638 unchanged lines hidden (view full) --- 3352 .pr_rcvd = uipc_rcvd, 3353 .pr_send = uipc_send, 3354 .pr_ready = uipc_ready, 3355 .pr_sense = uipc_sense, 3356 .pr_shutdown = uipc_shutdown, 3357 .pr_sockaddr = uipc_sockaddr, 3358 .pr_soreceive = soreceive_generic, 3359 .pr_close = uipc_close, | 730uipc_connect2(struct socket *so1, struct socket *so2) 731{ 732 struct unpcb *unp, *unp2; 733 734 if (so1->so_type != so2->so_type) 735 return (EPROTOTYPE); 736 737 unp = so1->so_pcb; --- 2638 unchanged lines hidden (view full) --- 3376 .pr_rcvd = uipc_rcvd, 3377 .pr_send = uipc_send, 3378 .pr_ready = uipc_ready, 3379 .pr_sense = uipc_sense, 3380 .pr_shutdown = uipc_shutdown, 3381 .pr_sockaddr = uipc_sockaddr, 3382 .pr_soreceive = soreceive_generic, 3383 .pr_close = uipc_close, |
3384 .pr_chmod = uipc_chmod, |
|
3360}; 3361 3362static struct protosw dgramproto = { 3363 .pr_type = SOCK_DGRAM, 3364 .pr_flags = PR_ATOMIC | PR_ADDR | PR_CAPATTACH | PR_SOCKBUF, 3365 .pr_ctloutput = &uipc_ctloutput, 3366 .pr_abort = uipc_abort, 3367 .pr_accept = uipc_peeraddr, --- 7 unchanged lines hidden (view full) --- 3375 .pr_disconnect = uipc_disconnect, 3376 .pr_peeraddr = uipc_peeraddr, 3377 .pr_sosend = uipc_sosend_dgram, 3378 .pr_sense = uipc_sense, 3379 .pr_shutdown = uipc_shutdown, 3380 .pr_sockaddr = uipc_sockaddr, 3381 .pr_soreceive = uipc_soreceive_dgram, 3382 .pr_close = uipc_close, | 3385}; 3386 3387static struct protosw dgramproto = { 3388 .pr_type = SOCK_DGRAM, 3389 .pr_flags = PR_ATOMIC | PR_ADDR | PR_CAPATTACH | PR_SOCKBUF, 3390 .pr_ctloutput = &uipc_ctloutput, 3391 .pr_abort = uipc_abort, 3392 .pr_accept = uipc_peeraddr, --- 7 unchanged lines hidden (view full) --- 3400 .pr_disconnect = uipc_disconnect, 3401 .pr_peeraddr = uipc_peeraddr, 3402 .pr_sosend = uipc_sosend_dgram, 3403 .pr_sense = uipc_sense, 3404 .pr_shutdown = uipc_shutdown, 3405 .pr_sockaddr = uipc_sockaddr, 3406 .pr_soreceive = uipc_soreceive_dgram, 3407 .pr_close = uipc_close, |
3408 .pr_chmod = uipc_chmod, |
|
3383}; 3384 3385static struct protosw seqpacketproto = { 3386 .pr_type = SOCK_SEQPACKET, 3387 /* 3388 * XXXRW: For now, PR_ADDR because soreceive will bump into them 3389 * due to our use of sbappendaddr. A new sbappend variants is needed 3390 * that supports both atomic record writes and control data. --- 15 unchanged lines hidden (view full) --- 3406 .pr_peeraddr = uipc_peeraddr, 3407 .pr_rcvd = uipc_rcvd, 3408 .pr_send = uipc_send, 3409 .pr_sense = uipc_sense, 3410 .pr_shutdown = uipc_shutdown, 3411 .pr_sockaddr = uipc_sockaddr, 3412 .pr_soreceive = soreceive_generic, /* XXX: or...? */ 3413 .pr_close = uipc_close, | 3409}; 3410 3411static struct protosw seqpacketproto = { 3412 .pr_type = SOCK_SEQPACKET, 3413 /* 3414 * XXXRW: For now, PR_ADDR because soreceive will bump into them 3415 * due to our use of sbappendaddr. A new sbappend variants is needed 3416 * that supports both atomic record writes and control data. --- 15 unchanged lines hidden (view full) --- 3432 .pr_peeraddr = uipc_peeraddr, 3433 .pr_rcvd = uipc_rcvd, 3434 .pr_send = uipc_send, 3435 .pr_sense = uipc_sense, 3436 .pr_shutdown = uipc_shutdown, 3437 .pr_sockaddr = uipc_sockaddr, 3438 .pr_soreceive = soreceive_generic, /* XXX: or...? */ 3439 .pr_close = uipc_close, |
3440 .pr_chmod = uipc_chmod, |
|
3414}; 3415 3416static struct domain localdomain = { 3417 .dom_family = AF_LOCAL, 3418 .dom_name = "local", 3419 .dom_externalize = unp_externalize, 3420 .dom_nprotosw = 3, 3421 .dom_protosw = { --- 152 unchanged lines hidden --- | 3441}; 3442 3443static struct domain localdomain = { 3444 .dom_family = AF_LOCAL, 3445 .dom_name = "local", 3446 .dom_externalize = unp_externalize, 3447 .dom_nprotosw = 3, 3448 .dom_protosw = { --- 152 unchanged lines hidden --- |