From owner-dev-commits-src-all@freebsd.org Mon May 3 16:20:38 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BE37B6364E5; Mon, 3 May 2021 16:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4FYp9f4sk0z3D02; Mon, 3 May 2021 16:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 9A18920F7F; Mon, 3 May 2021 16:20:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 143GKckV022216; Mon, 3 May 2021 16:20:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 143GKcJo022215; Mon, 3 May 2021 16:20:38 GMT (envelope-from git) Date: Mon, 3 May 2021 16:20:38 GMT Message-Id: <202105031620.143GKcJo022215@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 86ffb3d1a0cb - main - ELF coredump: define several useful flags for the coredump operations MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 86ffb3d1a0cbb09ba0123ff8d34149e691b461c4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 May 2021 16:20:38 -0000 The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=86ffb3d1a0cbb09ba0123ff8d34149e691b461c4 commit 86ffb3d1a0cbb09ba0123ff8d34149e691b461c4 Author: Konstantin Belousov AuthorDate: 2021-04-24 11:45:01 +0000 Commit: Konstantin Belousov CommitDate: 2021-05-03 16:13:47 +0000 ELF coredump: define several useful flags for the coredump operations - SVC_ALL request dumping all map entries, including those marked as non-dumpable - SVC_NOCOMPRESS disallows compressing the dump regardless of the sysctl policy - SVC_PC_COREDUMP is provided for future use by userspace core dump request Reviewed by: markj Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D29955 --- sys/kern/imgact_elf.c | 31 ++++++++++++++++++++----------- sys/sys/sysent.h | 5 +++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 77045842a13c..563629b747b5 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1655,7 +1655,7 @@ int __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) { struct ucred *cred = td->td_ucred; - int error = 0; + int compm, error = 0; struct sseg_closure seginfo; struct note_info_list notelst; struct coredump_params params; @@ -1706,9 +1706,13 @@ __elfN(coredump)(struct thread *td, struct vnode *vp, off_t limit, int flags) } /* Create a compression stream if necessary. */ - if (compress_user_cores != 0) { + compm = compress_user_cores; + if ((flags & (SVC_PT_COREDUMP | SVC_NOCOMPRESS)) == SVC_PT_COREDUMP && + compm == 0) + compm = COMPRESS_GZIP; + if (compm != 0) { params.comp = compressor_init(core_compressed_write, - compress_user_cores, CORE_BUF_SIZE, + compm, CORE_BUF_SIZE, compress_user_cores_level, ¶ms); if (params.comp == NULL) { error = EFAULT; @@ -1826,12 +1830,15 @@ each_dumpable_segment(struct thread *td, segment_callback func, void *closure, * are marked MAP_ENTRY_NOCOREDUMP now so we no longer * need to arbitrarily ignore such segments. */ - if (elf_legacy_coredump) { - if ((entry->protection & VM_PROT_RW) != VM_PROT_RW) - continue; - } else { - if ((entry->protection & VM_PROT_ALL) == 0) - continue; + if ((flags & SVC_ALL) == 0) { + if (elf_legacy_coredump) { + if ((entry->protection & VM_PROT_RW) != + VM_PROT_RW) + continue; + } else { + if ((entry->protection & VM_PROT_ALL) == 0) + continue; + } } /* @@ -1840,9 +1847,11 @@ each_dumpable_segment(struct thread *td, segment_callback func, void *closure, * madvise(2). Do not dump submaps (i.e. parts of the * kernel map). */ - if (entry->eflags & (MAP_ENTRY_NOCOREDUMP|MAP_ENTRY_IS_SUB_MAP)) + if ((entry->eflags & MAP_ENTRY_IS_SUB_MAP) != 0) + continue; + if ((entry->eflags & MAP_ENTRY_NOCOREDUMP) != 0 && + (flags & SVC_ALL) == 0) continue; - if ((object = entry->object.vm_object) == NULL) continue; diff --git a/sys/sys/sysent.h b/sys/sys/sysent.h index db729239243f..e6db2ec3dfb1 100644 --- a/sys/sys/sysent.h +++ b/sys/sys/sysent.h @@ -171,6 +171,11 @@ struct sysentvec { #define SV_ABI_CLOUDABI 17 #define SV_ABI_UNDEF 255 +/* sv_coredump flags */ +#define SVC_PT_COREDUMP 0x00000001 /* dump requested by ptrace(2) */ +#define SVC_NOCOMPRESS 0x00000002 /* disable compression. */ +#define SVC_ALL 0x00000004 /* dump everything */ + #ifdef _KERNEL extern struct sysentvec aout_sysvec; extern struct sysent sysent[];