imgact_elf.c (50477) | imgact_elf.c (50717) |
---|---|
1/*- 2 * Copyright (c) 1995-1996 S�ren Schmidt 3 * Copyright (c) 1996 Peter Wemm 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 1995-1996 S�ren Schmidt 3 * Copyright (c) 1996 Peter Wemm 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/sys/kern/imgact_elf.c 50477 1999-08-28 01:08:13Z peter $ | 29 * $FreeBSD: head/sys/kern/imgact_elf.c 50717 1999-09-01 00:29:56Z julian $ |
30 */ 31 32#include "opt_rlimit.h" 33 34#include <sys/param.h> 35#include <sys/acct.h> 36#include <sys/exec.h> 37#include <sys/fcntl.h> --- 640 unchanged lines hidden (view full) --- 678static void elf_puthdr __P((struct proc *, void *, size_t *, 679 const prstatus_t *, const prfpregset_t *, const prpsinfo_t *, int)); 680static void elf_putnote __P((void *, size_t *, const char *, int, 681 const void *, size_t)); 682 683extern int osreldate; 684 685int | 30 */ 31 32#include "opt_rlimit.h" 33 34#include <sys/param.h> 35#include <sys/acct.h> 36#include <sys/exec.h> 37#include <sys/fcntl.h> --- 640 unchanged lines hidden (view full) --- 678static void elf_puthdr __P((struct proc *, void *, size_t *, 679 const prstatus_t *, const prfpregset_t *, const prpsinfo_t *, int)); 680static void elf_putnote __P((void *, size_t *, const char *, int, 681 const void *, size_t)); 682 683extern int osreldate; 684 685int |
686elf_coredump(p) | 686elf_coredump(p, vp, limit) |
687 register struct proc *p; | 687 register struct proc *p; |
688{ | |
689 register struct vnode *vp; | 688 register struct vnode *vp; |
689 off_t limit; 690{ |
|
690 register struct ucred *cred = p->p_cred->pc_ucred; | 691 register struct ucred *cred = p->p_cred->pc_ucred; |
691 struct nameidata nd; 692 struct vattr vattr; 693 int error, error1; 694 char *name; /* name of corefile */ | 692 int error = 0; |
695 struct sseg_closure seginfo; 696 void *hdr; 697 size_t hdrsize; 698 | 693 struct sseg_closure seginfo; 694 void *hdr; 695 size_t hdrsize; 696 |
699 STOPEVENT(p, S_CORE, 0); 700 701 if (sugid_coredump == 0 && p->p_flag & P_SUGID) 702 return (EFAULT); 703 | |
704 /* Size the program segments. */ 705 seginfo.count = 0; 706 seginfo.size = 0; 707 each_writable_segment(p, cb_size_segment, &seginfo); 708 709 /* 710 * Calculate the size of the core file header area by making 711 * a dry run of generating it. Nothing is written, but the 712 * size is calculated. 713 */ 714 hdrsize = 0; 715 elf_puthdr((struct proc *)NULL, (void *)NULL, &hdrsize, 716 (const prstatus_t *)NULL, (const prfpregset_t *)NULL, 717 (const prpsinfo_t *)NULL, seginfo.count); 718 | 697 /* Size the program segments. */ 698 seginfo.count = 0; 699 seginfo.size = 0; 700 each_writable_segment(p, cb_size_segment, &seginfo); 701 702 /* 703 * Calculate the size of the core file header area by making 704 * a dry run of generating it. Nothing is written, but the 705 * size is calculated. 706 */ 707 hdrsize = 0; 708 elf_puthdr((struct proc *)NULL, (void *)NULL, &hdrsize, 709 (const prstatus_t *)NULL, (const prfpregset_t *)NULL, 710 (const prpsinfo_t *)NULL, seginfo.count); 711 |
719 if (hdrsize + seginfo.size >= p->p_rlimit[RLIMIT_CORE].rlim_cur) | 712 if (hdrsize + seginfo.size >= limit) |
720 return (EFAULT); | 713 return (EFAULT); |
721 name = expand_name(p->p_comm, p->p_ucred->cr_uid, p->p_pid); 722 if (name == NULL) 723 return (EFAULT); /* XXX -- not the best error */ 724 725 NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, p); 726 error = vn_open(&nd, O_CREAT | FWRITE | O_NOFOLLOW, S_IRUSR | S_IWUSR); 727 free(name, M_TEMP); 728 if (error) 729 return (error); 730 vp = nd.ni_vp; | |
731 | 714 |
732 /* Don't dump to non-regular files or files with links. */ 733 if (vp->v_type != VREG || 734 VOP_GETATTR(vp, &vattr, cred, p) || vattr.va_nlink != 1) { 735 error = EFAULT; 736 goto out; 737 } 738 VATTR_NULL(&vattr); 739 vattr.va_size = 0; 740 VOP_LEASE(vp, p, cred, LEASE_WRITE); 741 VOP_SETATTR(vp, &vattr, cred, p); 742 p->p_acflag |= ACORE; 743 744 | |
745 /* 746 * Allocate memory for building the header, fill it up, 747 * and write it out. 748 */ 749 hdr = malloc(hdrsize, M_TEMP, M_WAITOK); 750 if (hdr == NULL) { | 715 /* 716 * Allocate memory for building the header, fill it up, 717 * and write it out. 718 */ 719 hdr = malloc(hdrsize, M_TEMP, M_WAITOK); 720 if (hdr == NULL) { |
751 error = EINVAL; 752 goto out; | 721 return EINVAL; |
753 } 754 error = elf_corehdr(p, vp, cred, seginfo.count, hdr, hdrsize); 755 756 /* Write the contents of all of the writable segments. */ 757 if (error == 0) { 758 Elf_Phdr *php; 759 off_t offset; 760 int i; --- 6 unchanged lines hidden (view full) --- 767 IO_NODELOCKED|IO_UNIT, cred, (int *)NULL, p); 768 if (error != 0) 769 break; 770 offset += php->p_filesz; 771 php++; 772 } 773 } 774 free(hdr, M_TEMP); | 722 } 723 error = elf_corehdr(p, vp, cred, seginfo.count, hdr, hdrsize); 724 725 /* Write the contents of all of the writable segments. */ 726 if (error == 0) { 727 Elf_Phdr *php; 728 off_t offset; 729 int i; --- 6 unchanged lines hidden (view full) --- 736 IO_NODELOCKED|IO_UNIT, cred, (int *)NULL, p); 737 if (error != 0) 738 break; 739 offset += php->p_filesz; 740 php++; 741 } 742 } 743 free(hdr, M_TEMP); |
775 776out: 777 VOP_UNLOCK(vp, 0, p); 778 error1 = vn_close(vp, FWRITE, cred, p); 779 if (error == 0) 780 error = error1; 781 return (error); | 744 745 return error; |
782} 783 784/* 785 * A callback for each_writable_segment() to write out the segment's 786 * program header entry. 787 */ 788static void 789cb_put_phdr(entry, closure) --- 236 unchanged lines hidden --- | 746} 747 748/* 749 * A callback for each_writable_segment() to write out the segment's 750 * program header entry. 751 */ 752static void 753cb_put_phdr(entry, closure) --- 236 unchanged lines hidden --- |