Deleted Added
full compact
kern_descrip.c (90392) kern_descrip.c (91140)
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
1/*
2 * Copyright (c) 1982, 1986, 1989, 1991, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.

--- 22 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)kern_descrip.c 8.6 (Berkeley) 4/19/94
39 * $FreeBSD: head/sys/kern/kern_descrip.c 90392 2002-02-08 09:16:57Z peter $
39 * $FreeBSD: head/sys/kern/kern_descrip.c 91140 2002-02-23 11:12:57Z tanimura $
40 */
41
42#include "opt_compat.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/lock.h>
47#include <sys/malloc.h>

--- 482 unchanged lines hidden (view full) ---

530void
531funsetown(sigio)
532 struct sigio *sigio;
533{
534 int s;
535
536 if (sigio == NULL)
537 return;
40 */
41
42#include "opt_compat.h"
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/lock.h>
47#include <sys/malloc.h>

--- 482 unchanged lines hidden (view full) ---

530void
531funsetown(sigio)
532 struct sigio *sigio;
533{
534 int s;
535
536 if (sigio == NULL)
537 return;
538
538 s = splhigh();
539 *(sigio->sio_myref) = NULL;
540 splx(s);
539 s = splhigh();
540 *(sigio->sio_myref) = NULL;
541 splx(s);
541 if (sigio->sio_pgid < 0) {
542 if ((sigio)->sio_pgid < 0) {
543 struct pgrp *pg = (sigio)->sio_pgrp;
544 PGRP_LOCK(pg);
542 SLIST_REMOVE(&sigio->sio_pgrp->pg_sigiolst, sigio,
543 sigio, sio_pgsigio);
545 SLIST_REMOVE(&sigio->sio_pgrp->pg_sigiolst, sigio,
546 sigio, sio_pgsigio);
544 } else /* if ((*sigiop)->sio_pgid > 0) */ {
547 PGRP_UNLOCK(pg);
548 } else {
549 struct proc *p = (sigio)->sio_proc;
550 PROC_LOCK(p);
545 SLIST_REMOVE(&sigio->sio_proc->p_sigiolst, sigio,
546 sigio, sio_pgsigio);
551 SLIST_REMOVE(&sigio->sio_proc->p_sigiolst, sigio,
552 sigio, sio_pgsigio);
553 PROC_UNLOCK(p);
547 }
548 crfree(sigio->sio_ucred);
549 FREE(sigio, M_SIGIO);
550}
551
552/* Free a list of sigio structures. */
553void
554funsetownlst(sigiolst)
555 struct sigiolst *sigiolst;
556{
554 }
555 crfree(sigio->sio_ucred);
556 FREE(sigio, M_SIGIO);
557}
558
559/* Free a list of sigio structures. */
560void
561funsetownlst(sigiolst)
562 struct sigiolst *sigiolst;
563{
564 int s;
557 struct sigio *sigio;
565 struct sigio *sigio;
566 struct proc *p;
567 struct pgrp *pg;
558
568
559 while ((sigio = SLIST_FIRST(sigiolst)) != NULL)
560 funsetown(sigio);
569 sigio = SLIST_FIRST(sigiolst);
570 if (sigio == NULL)
571 return;
572
573 p = NULL;
574 pg = NULL;
575
576 /*
577 * Every entry of the list should belong
578 * to a single proc or pgrp.
579 */
580 if (sigio->sio_pgid < 0) {
581 pg = sigio->sio_pgrp;
582 PGRP_LOCK_ASSERT(pg, MA_OWNED);
583 } else /* if (sigio->sio_pgid > 0) */ {
584 p = sigio->sio_proc;
585 PROC_LOCK_ASSERT(p, MA_OWNED);
586 }
587
588 while ((sigio = SLIST_FIRST(sigiolst)) != NULL) {
589 s = splhigh();
590 *(sigio->sio_myref) = NULL;
591 splx(s);
592 if (pg != NULL) {
593 KASSERT(sigio->sio_pgid < 0, ("Proc sigio in pgrp sigio list"));
594 KASSERT(sigio->sio_pgrp == pg, ("Bogus pgrp in sigio list"));
595 SLIST_REMOVE(&pg->pg_sigiolst, sigio, sigio, sio_pgsigio);
596 PGRP_UNLOCK(pg);
597 crfree(sigio->sio_ucred);
598 FREE(sigio, M_SIGIO);
599 PGRP_LOCK(pg);
600 } else /* if (p != NULL) */ {
601 KASSERT(sigio->sio_pgid > 0, ("Pgrp sigio in proc sigio list"));
602 KASSERT(sigio->sio_proc == p, ("Bogus proc in sigio list"));
603 SLIST_REMOVE(&p->p_sigiolst, sigio, sigio, sio_pgsigio);
604 PROC_UNLOCK(p);
605 crfree(sigio->sio_ucred);
606 FREE(sigio, M_SIGIO);
607 PROC_LOCK(p);
608 }
609 }
561}
562
563/*
564 * This is common code for FIOSETOWN ioctl called by fcntl(fd, F_SETOWN, arg).
565 *
566 * After permission checking, add a sigio structure to the sigio list for
567 * the process or process group.
568 */
569int
570fsetown(pgid, sigiop)
571 pid_t pgid;
572 struct sigio **sigiop;
573{
574 struct proc *proc;
575 struct pgrp *pgrp;
576 struct sigio *sigio;
610}
611
612/*
613 * This is common code for FIOSETOWN ioctl called by fcntl(fd, F_SETOWN, arg).
614 *
615 * After permission checking, add a sigio structure to the sigio list for
616 * the process or process group.
617 */
618int
619fsetown(pgid, sigiop)
620 pid_t pgid;
621 struct sigio **sigiop;
622{
623 struct proc *proc;
624 struct pgrp *pgrp;
625 struct sigio *sigio;
577 int s;
626 int s, ret;
578
579 if (pgid == 0) {
580 funsetown(*sigiop);
581 return (0);
582 }
627
628 if (pgid == 0) {
629 funsetown(*sigiop);
630 return (0);
631 }
632
633 ret = 0;
634
635 /* Allocate and fill in the new sigio out of locks. */
636 MALLOC(sigio, struct sigio *, sizeof(struct sigio), M_SIGIO, M_WAITOK);
637 sigio->sio_pgid = pgid;
638 sigio->sio_ucred = crhold(curthread->td_proc->p_ucred);
639 sigio->sio_myref = sigiop;
640
641 PGRPSESS_SLOCK();
583 if (pgid > 0) {
584 proc = pfind(pgid);
642 if (pgid > 0) {
643 proc = pfind(pgid);
585 if (proc == NULL)
586 return (ESRCH);
644 if (proc == NULL) {
645 ret = ESRCH;
646 goto fail;
647 }
587
588 /*
589 * Policy - Don't allow a process to FSETOWN a process
590 * in another session.
591 *
592 * Remove this test to allow maximum flexibility or
593 * restrict FSETOWN to the current process or process
594 * group for maximum safety.
595 */
648
649 /*
650 * Policy - Don't allow a process to FSETOWN a process
651 * in another session.
652 *
653 * Remove this test to allow maximum flexibility or
654 * restrict FSETOWN to the current process or process
655 * group for maximum safety.
656 */
657 PROC_UNLOCK(proc);
596 if (proc->p_session != curthread->td_proc->p_session) {
658 if (proc->p_session != curthread->td_proc->p_session) {
597 PROC_UNLOCK(proc);
598 return (EPERM);
659 ret = EPERM;
660 goto fail;
599 }
661 }
600 PROC_UNLOCK(proc);
601
602 pgrp = NULL;
603 } else /* if (pgid < 0) */ {
604 pgrp = pgfind(-pgid);
662
663 pgrp = NULL;
664 } else /* if (pgid < 0) */ {
665 pgrp = pgfind(-pgid);
605 if (pgrp == NULL)
606 return (ESRCH);
666 if (pgrp == NULL) {
667 ret = ESRCH;
668 goto fail;
669 }
670 PGRP_UNLOCK(pgrp);
607
608 /*
609 * Policy - Don't allow a process to FSETOWN a process
610 * in another session.
611 *
612 * Remove this test to allow maximum flexibility or
613 * restrict FSETOWN to the current process or process
614 * group for maximum safety.
615 */
671
672 /*
673 * Policy - Don't allow a process to FSETOWN a process
674 * in another session.
675 *
676 * Remove this test to allow maximum flexibility or
677 * restrict FSETOWN to the current process or process
678 * group for maximum safety.
679 */
616 if (pgrp->pg_session != curthread->td_proc->p_session)
617 return (EPERM);
680 if (pgrp->pg_session != curthread->td_proc->p_session) {
681 ret = EPERM;
682 goto fail;
683 }
618
619 proc = NULL;
620 }
621 funsetown(*sigiop);
684
685 proc = NULL;
686 }
687 funsetown(*sigiop);
622 MALLOC(sigio, struct sigio *, sizeof(struct sigio), M_SIGIO, M_WAITOK);
623 if (pgid > 0) {
688 if (pgid > 0) {
689 PROC_LOCK(proc);
624 SLIST_INSERT_HEAD(&proc->p_sigiolst, sigio, sio_pgsigio);
625 sigio->sio_proc = proc;
690 SLIST_INSERT_HEAD(&proc->p_sigiolst, sigio, sio_pgsigio);
691 sigio->sio_proc = proc;
692 PROC_UNLOCK(proc);
626 } else {
693 } else {
694 PGRP_LOCK(pgrp);
627 SLIST_INSERT_HEAD(&pgrp->pg_sigiolst, sigio, sio_pgsigio);
628 sigio->sio_pgrp = pgrp;
695 SLIST_INSERT_HEAD(&pgrp->pg_sigiolst, sigio, sio_pgsigio);
696 sigio->sio_pgrp = pgrp;
697 PGRP_UNLOCK(pgrp);
629 }
698 }
630 sigio->sio_pgid = pgid;
631 sigio->sio_ucred = crhold(curthread->td_proc->p_ucred);
632 sigio->sio_myref = sigiop;
699 PGRPSESS_SUNLOCK();
633 s = splhigh();
634 *sigiop = sigio;
635 splx(s);
636 return (0);
700 s = splhigh();
701 *sigiop = sigio;
702 splx(s);
703 return (0);
704
705fail:
706 PGRPSESS_SUNLOCK();
707 crfree(sigio->sio_ucred);
708 FREE(sigio, M_SIGIO);
709 return (ret);
637}
638
639/*
640 * This is common code for FIOGETOWN ioctl called by fcntl(fd, F_GETOWN, arg).
641 */
642pid_t
643fgetown(sigio)
644 struct sigio *sigio;

--- 1390 unchanged lines hidden ---
710}
711
712/*
713 * This is common code for FIOGETOWN ioctl called by fcntl(fd, F_GETOWN, arg).
714 */
715pid_t
716fgetown(sigio)
717 struct sigio *sigio;

--- 1390 unchanged lines hidden ---