From nobody Sun Oct 10 09:24:28 2021 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id F3E2312DFA26; Sun, 10 Oct 2021 09:24: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 4HRxMl5JNmz3N8L; Sun, 10 Oct 2021 09:24:35 +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 7CF603486; Sun, 10 Oct 2021 09:24:28 +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 19A9OStt003754; Sun, 10 Oct 2021 09:24:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19A9OScK003753; Sun, 10 Oct 2021 09:24:28 GMT (envelope-from git) Date: Sun, 10 Oct 2021 09:24:28 GMT Message-Id: <202110100924.19A9OScK003753@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: aa90eb737dcf - stable/13 - Make core dump writes interruptible with SIGKILL List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org 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/stable/13 X-Git-Reftype: branch X-Git-Commit: aa90eb737dcf80ba1d4342250ab738861d57676e Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=aa90eb737dcf80ba1d4342250ab738861d57676e commit aa90eb737dcf80ba1d4342250ab738861d57676e Author: Konstantin Belousov AuthorDate: 2021-10-05 05:11:32 +0000 Commit: Konstantin Belousov CommitDate: 2021-10-10 09:22:58 +0000 Make core dump writes interruptible with SIGKILL (cherry picked from commit b5cadc643e853fa4cb23e5315e6f40bf9979a9c0) --- share/man/man5/core.5 | 16 +++++++++++++++- sys/kern/imgact_elf.c | 4 ++++ sys/kern/kern_exec.c | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/share/man/man5/core.5 b/share/man/man5/core.5 index d176548d1570..0af1b2b7e8bf 100644 --- a/share/man/man5/core.5 +++ b/share/man/man5/core.5 @@ -28,7 +28,7 @@ .\" @(#)core.5 8.3 (Berkeley) 12/11/93 .\" $FreeBSD$ .\" -.Dd August 2, 2020 +.Dd October 5, 2021 .Dt CORE 5 .Os .Sh NAME @@ -57,6 +57,20 @@ The maximum size of a core file is limited by the limit. Files which would be larger than the limit are not created. .Pp +With a large limit, a process that had mapped a very large, +and perhaps sparsely populated, virtual memory region, could take +a very long time to create core dumps. +The system ignores all signals sent to a process writing a core file, except +.Dv SIGKILL +which terminates the writing and causes immediate exit of the process. +The behavior of +.Dv SIGKILL +can be disabled by setting tunable +.Xr sysctl 8 +variable +.Va kern.core_dump_can_intr +to zero. +.Pp The name of the file is controlled via the .Xr sysctl 8 variable diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 057c583324bb..e1b6e3fc6ba7 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -1547,6 +1547,8 @@ core_write(struct coredump_params *p, const void *base, size_t len, p->active_cred, p->file_cred, resid, p->td)); } +extern int core_dump_can_intr; + static int core_output(char *base, size_t len, off_t offset, struct coredump_params *p, void *tmpbuf) @@ -1572,6 +1574,8 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *p, * anonymous memory or truncated files, for example. */ for (runlen = 0; runlen < len; runlen += PAGE_SIZE) { + if (core_dump_can_intr && curproc_sigkilled()) + return (EINTR); error = vm_fault(map, (uintptr_t)base + runlen, VM_PROT_READ, VM_FAULT_NOFILL, NULL); if (runlen == 0) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 0611eedcec73..2ea0efc4a2cb 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -150,6 +150,11 @@ static int map_at_zero = 0; SYSCTL_INT(_security_bsd, OID_AUTO, map_at_zero, CTLFLAG_RWTUN, &map_at_zero, 0, "Permit processes to map an object at virtual address 0."); +int core_dump_can_intr = 1; +SYSCTL_INT(_kern, OID_AUTO, core_dump_can_intr, CTLFLAG_RWTUN, + &core_dump_can_intr, 0, + "Core dumping interruptible with SIGKILL"); + static int sysctl_kern_ps_strings(SYSCTL_HANDLER_ARGS) {