From nobody Fri Oct 08 00:22:09 2021 X-Original-To: dev-commits-src-main@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 BDF7D17E5328; Fri, 8 Oct 2021 00:22:11 +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 4HQTQp3mjcz3RG8; Fri, 8 Oct 2021 00:22:10 +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 B3B7A1D698; Fri, 8 Oct 2021 00:22:09 +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 1980M906043291; Fri, 8 Oct 2021 00:22:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1980M9HS043290; Fri, 8 Oct 2021 00:22:09 GMT (envelope-from git) Date: Fri, 8 Oct 2021 00:22:09 GMT Message-Id: <202110080022.1980M9HS043290@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: b5cadc643e85 - main - Make core dump writes interruptible with SIGKILL List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b5cadc643e853fa4cb23e5315e6f40bf9979a9c0 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b5cadc643e853fa4cb23e5315e6f40bf9979a9c0 commit b5cadc643e853fa4cb23e5315e6f40bf9979a9c0 Author: Konstantin Belousov AuthorDate: 2021-10-05 05:11:32 +0000 Commit: Konstantin Belousov CommitDate: 2021-10-08 00:21:43 +0000 Make core dump writes interruptible with SIGKILL This can be disabled by sysctl kern.core_dump_can_intr Reported and tested by: pho Reviewed by: imp, markj Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D32313 --- share/man/man5/core.5 | 16 +++++++++++++++- sys/kern/kern_exec.c | 7 +++++++ 2 files changed, 22 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/kern_exec.c b/sys/kern/kern_exec.c index 4b3035cb7e08..7ec405ee6a62 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -151,6 +151,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."); +static 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) { @@ -1943,6 +1948,8 @@ core_output(char *base, size_t len, off_t offset, struct coredump_params *cp, * 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)