kern_ktrace.c (a163d034fadcfb4a25ca34a2ba5f491c47b6ff69) | kern_ktrace.c (a5881ea55a2c554fd584cf985d99e92ad1db8737) |
---|---|
1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 212 unchanged lines hidden (view full) --- 221 mtx_unlock(&ktrace_mtx); 222 td->td_inktrace = 0; 223 return (NULL); 224 } 225 req = STAILQ_FIRST(&ktr_free); 226 if (req != NULL) { 227 STAILQ_REMOVE_HEAD(&ktr_free, ktr_list); 228 req->ktr_header.ktr_type = type; | 1/* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 212 unchanged lines hidden (view full) --- 221 mtx_unlock(&ktrace_mtx); 222 td->td_inktrace = 0; 223 return (NULL); 224 } 225 req = STAILQ_FIRST(&ktr_free); 226 if (req != NULL) { 227 STAILQ_REMOVE_HEAD(&ktr_free, ktr_list); 228 req->ktr_header.ktr_type = type; |
229 KASSERT(p->p_tracep != NULL, ("ktrace: no trace vnode")); 230 req->ktr_vp = p->p_tracep; 231 VREF(p->p_tracep); | 229 KASSERT(p->p_tracevp != NULL, ("ktrace: no trace vnode")); 230 KASSERT(p->p_tracecred != NULL, ("ktrace: no trace cred")); 231 req->ktr_vp = p->p_tracevp; 232 VREF(p->p_tracevp); 233 req->ktr_cred = crhold(p->p_tracecred); |
232 mtx_unlock(&ktrace_mtx); 233 microtime(&req->ktr_header.ktr_time); 234 req->ktr_header.ktr_pid = p->p_pid; 235 bcopy(p->p_comm, req->ktr_header.ktr_comm, MAXCOMLEN + 1); | 234 mtx_unlock(&ktrace_mtx); 235 microtime(&req->ktr_header.ktr_time); 236 req->ktr_header.ktr_pid = p->p_pid; 237 bcopy(p->p_comm, req->ktr_header.ktr_comm, MAXCOMLEN + 1); |
236 req->ktr_cred = crhold(td->td_ucred); | |
237 req->ktr_header.ktr_buffer = NULL; 238 req->ktr_header.ktr_len = 0; 239 } else { 240 pm = print_message; 241 print_message = 0; 242 mtx_unlock(&ktrace_mtx); 243 if (pm) 244 printf("Out of ktrace request objects.\n"); --- 248 unchanged lines hidden (view full) --- 493 register struct proc *p; 494 struct pgrp *pg; 495 int facs = uap->facs & ~KTRFAC_ROOT; 496 int ops = KTROP(uap->ops); 497 int descend = uap->ops & KTRFLAG_DESCEND; 498 int ret = 0; 499 int flags, error = 0; 500 struct nameidata nd; | 238 req->ktr_header.ktr_buffer = NULL; 239 req->ktr_header.ktr_len = 0; 240 } else { 241 pm = print_message; 242 print_message = 0; 243 mtx_unlock(&ktrace_mtx); 244 if (pm) 245 printf("Out of ktrace request objects.\n"); --- 248 unchanged lines hidden (view full) --- 494 register struct proc *p; 495 struct pgrp *pg; 496 int facs = uap->facs & ~KTRFAC_ROOT; 497 int ops = KTROP(uap->ops); 498 int descend = uap->ops & KTRFLAG_DESCEND; 499 int ret = 0; 500 int flags, error = 0; 501 struct nameidata nd; |
502 struct ucred *cred; |
|
501 502 td->td_inktrace = 1; 503 if (ops != KTROP_CLEAR) { 504 /* 505 * an operation which requires a file argument. 506 */ 507 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->fname, td); 508 flags = FREAD | FWRITE | O_NOFOLLOW; --- 13 unchanged lines hidden (view full) --- 522 } 523 /* 524 * Clear all uses of the tracefile. 525 */ 526 if (ops == KTROP_CLEARFILE) { 527 sx_slock(&allproc_lock); 528 LIST_FOREACH(p, &allproc, p_list) { 529 PROC_LOCK(p); | 503 504 td->td_inktrace = 1; 505 if (ops != KTROP_CLEAR) { 506 /* 507 * an operation which requires a file argument. 508 */ 509 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->fname, td); 510 flags = FREAD | FWRITE | O_NOFOLLOW; --- 13 unchanged lines hidden (view full) --- 524 } 525 /* 526 * Clear all uses of the tracefile. 527 */ 528 if (ops == KTROP_CLEARFILE) { 529 sx_slock(&allproc_lock); 530 LIST_FOREACH(p, &allproc, p_list) { 531 PROC_LOCK(p); |
530 if (p->p_tracep == vp) { | 532 if (p->p_tracevp == vp) { |
531 if (ktrcanset(td, p)) { 532 mtx_lock(&ktrace_mtx); | 533 if (ktrcanset(td, p)) { 534 mtx_lock(&ktrace_mtx); |
533 p->p_tracep = NULL; | 535 cred = p->p_tracecred; 536 p->p_tracecred = NULL; 537 p->p_tracevp = NULL; |
534 p->p_traceflag = 0; 535 mtx_unlock(&ktrace_mtx); 536 PROC_UNLOCK(p); 537 (void) vn_close(vp, FREAD|FWRITE, | 538 p->p_traceflag = 0; 539 mtx_unlock(&ktrace_mtx); 540 PROC_UNLOCK(p); 541 (void) vn_close(vp, FREAD|FWRITE, |
538 td->td_ucred, td); | 542 cred, td); 543 crfree(cred); |
539 } else { 540 PROC_UNLOCK(p); 541 error = EPERM; 542 } 543 } else 544 PROC_UNLOCK(p); 545 } 546 sx_sunlock(&allproc_lock); --- 102 unchanged lines hidden (view full) --- 649static int 650ktrops(td, p, ops, facs, vp) 651 struct thread *td; 652 struct proc *p; 653 int ops, facs; 654 struct vnode *vp; 655{ 656 struct vnode *tracevp = NULL; | 544 } else { 545 PROC_UNLOCK(p); 546 error = EPERM; 547 } 548 } else 549 PROC_UNLOCK(p); 550 } 551 sx_sunlock(&allproc_lock); --- 102 unchanged lines hidden (view full) --- 654static int 655ktrops(td, p, ops, facs, vp) 656 struct thread *td; 657 struct proc *p; 658 int ops, facs; 659 struct vnode *vp; 660{ 661 struct vnode *tracevp = NULL; |
662 struct ucred *tracecred = NULL; |
|
657 658 PROC_LOCK(p); 659 if (!ktrcanset(td, p)) { 660 PROC_UNLOCK(p); 661 return (0); 662 } 663 mtx_lock(&ktrace_mtx); 664 if (ops == KTROP_SET) { | 663 664 PROC_LOCK(p); 665 if (!ktrcanset(td, p)) { 666 PROC_UNLOCK(p); 667 return (0); 668 } 669 mtx_lock(&ktrace_mtx); 670 if (ops == KTROP_SET) { |
665 if (p->p_tracep != vp) { | 671 if (p->p_tracevp != vp) { |
666 /* 667 * if trace file already in use, relinquish below 668 */ | 672 /* 673 * if trace file already in use, relinquish below 674 */ |
669 tracevp = p->p_tracep; | 675 tracevp = p->p_tracevp; |
670 VREF(vp); | 676 VREF(vp); |
671 p->p_tracep = vp; | 677 p->p_tracevp = vp; |
672 } | 678 } |
679 if (p->p_tracecred != td->td_ucred) { 680 tracecred = p->p_tracecred; 681 p->p_tracecred = crhold(td->td_ucred); 682 } |
|
673 p->p_traceflag |= facs; 674 if (td->td_ucred->cr_uid == 0) 675 p->p_traceflag |= KTRFAC_ROOT; 676 } else { 677 /* KTROP_CLEAR */ 678 if (((p->p_traceflag &= ~facs) & KTRFAC_MASK) == 0) { 679 /* no more tracing */ 680 p->p_traceflag = 0; | 683 p->p_traceflag |= facs; 684 if (td->td_ucred->cr_uid == 0) 685 p->p_traceflag |= KTRFAC_ROOT; 686 } else { 687 /* KTROP_CLEAR */ 688 if (((p->p_traceflag &= ~facs) & KTRFAC_MASK) == 0) { 689 /* no more tracing */ 690 p->p_traceflag = 0; |
681 tracevp = p->p_tracep; 682 p->p_tracep = NULL; | 691 tracevp = p->p_tracevp; 692 p->p_tracevp = NULL; 693 tracecred = p->p_tracecred; 694 p->p_tracecred = NULL; |
683 } 684 } 685 mtx_unlock(&ktrace_mtx); 686 PROC_UNLOCK(p); 687 if (tracevp != NULL) 688 vrele(tracevp); | 695 } 696 } 697 mtx_unlock(&ktrace_mtx); 698 PROC_UNLOCK(p); 699 if (tracevp != NULL) 700 vrele(tracevp); |
701 if (tracecred != NULL) 702 crfree(tracecred); |
|
689 690 return (1); 691} 692 693static int 694ktrsetchildren(td, top, ops, facs, vp) 695 struct thread *td; 696 struct proc *top; --- 102 unchanged lines hidden (view full) --- 799 vrele_count = 0; 800 /* 801 * First, clear this vnode from being used by any processes in the 802 * system. 803 * XXX - If one process gets an EPERM writing to the vnode, should 804 * we really do this? Other processes might have suitable 805 * credentials for the operation. 806 */ | 703 704 return (1); 705} 706 707static int 708ktrsetchildren(td, top, ops, facs, vp) 709 struct thread *td; 710 struct proc *top; --- 102 unchanged lines hidden (view full) --- 813 vrele_count = 0; 814 /* 815 * First, clear this vnode from being used by any processes in the 816 * system. 817 * XXX - If one process gets an EPERM writing to the vnode, should 818 * we really do this? Other processes might have suitable 819 * credentials for the operation. 820 */ |
821 cred = NULL; |
|
807 sx_slock(&allproc_lock); 808 LIST_FOREACH(p, &allproc, p_list) { 809 PROC_LOCK(p); | 822 sx_slock(&allproc_lock); 823 LIST_FOREACH(p, &allproc, p_list) { 824 PROC_LOCK(p); |
810 if (p->p_tracep == vp) { | 825 if (p->p_tracevp == vp) { |
811 mtx_lock(&ktrace_mtx); | 826 mtx_lock(&ktrace_mtx); |
812 p->p_tracep = NULL; | 827 p->p_tracevp = NULL; |
813 p->p_traceflag = 0; | 828 p->p_traceflag = 0; |
829 cred = p->p_tracecred; 830 p->p_tracecred = NULL; |
|
814 mtx_unlock(&ktrace_mtx); 815 vrele_count++; 816 } 817 PROC_UNLOCK(p); | 831 mtx_unlock(&ktrace_mtx); 832 vrele_count++; 833 } 834 PROC_UNLOCK(p); |
835 if (cred != NULL) { 836 crfree(cred); 837 cred = NULL; 838 } |
|
818 } 819 sx_sunlock(&allproc_lock); 820 /* 821 * Second, clear this vnode from any pending requests. 822 */ 823 mtx_lock(&ktrace_mtx); 824 STAILQ_FOREACH(req, &ktr_todo, ktr_list) { 825 if (req->ktr_vp == vp) { --- 36 unchanged lines hidden --- | 839 } 840 sx_sunlock(&allproc_lock); 841 /* 842 * Second, clear this vnode from any pending requests. 843 */ 844 mtx_lock(&ktrace_mtx); 845 STAILQ_FOREACH(req, &ktr_todo, ktr_list) { 846 if (req->ktr_vp == vp) { --- 36 unchanged lines hidden --- |