Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 8 Oct 2021 00:22:09 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: b5cadc643e85 - main - Make core dump writes interruptible with SIGKILL
Message-ID:  <202110080022.1980M9HS043290@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=b5cadc643e853fa4cb23e5315e6f40bf9979a9c0

commit b5cadc643e853fa4cb23e5315e6f40bf9979a9c0
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2021-10-05 05:11:32 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
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)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202110080022.1980M9HS043290>