mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] coredump: allow interrupting dumps of large anonymous regions
@ 2025-01-16  4:05 Tavian Barnes
  2025-01-16  7:46 ` Mateusz Guzik
  2025-01-16 10:05 ` Jan Kara
  0 siblings, 2 replies; 8+ messages in thread
From: Tavian Barnes @ 2025-01-16  4:05 UTC (permalink / raw)
  To: linux-fsdevel
  Cc: Tavian Barnes, Alexander Viro, Christian Brauner, Jan Kara, linux-kernel

dump_user_range() supports sparse core dumps by skipping anonymous pages
which have not been modified.  If get_dump_page() returns NULL, the page
is skipped rather than written to the core dump with dump_emit_page().

Sadly, dump_emit_page() contains the only check for dump_interrupted(),
so when dumping a very large sparse region, the core dump becomes
effectively uninterruptible.  This can be observed with the following
test program:

    #include <stdlib.h>
    #include <stdio.h>
    #include <sys/mman.h>

    int main(void) {
        char *mem = mmap(NULL, 1ULL << 40, PROT_READ | PROT_WRITE,
                MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE, -1, 0);
        printf("%p %m\n", mem);
        if (mem != MAP_FAILED) {
                mem[0] = 1;
        }
        abort();
    }

The program allocates 1 TiB of anonymous memory, touches one page of it,
and aborts.  During the core dump, SIGKILL has no effect.  It takes
about 30 seconds to finish the dump, burning 100% CPU.

This issue naturally arises with things like Address Sanitizer, which
allocate a large sparse region of virtual address space for their shadow
memory.

Fix it by checking dump_interrupted() explicitly in dump_user_pages().

Signed-off-by: Tavian Barnes <tavianator@tavianator.com>
---
 fs/coredump.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/fs/coredump.c b/fs/coredump.c
index d48edb37bc35..fd29d3f15f1e 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -950,6 +950,10 @@ int dump_user_range(struct coredump_params *cprm, unsigned long start,
 			}
 		} else {
 			dump_skip(cprm, PAGE_SIZE);
+			if (dump_interrupted()) {
+				dump_page_free(dump_page);
+				return 0;
+			}
 		}
 		cond_resched();
 	}
-- 
2.48.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-01-19 10:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-16  4:05 [PATCH] coredump: allow interrupting dumps of large anonymous regions Tavian Barnes
2025-01-16  7:46 ` Mateusz Guzik
2025-01-16  9:56   ` Jan Kara
2025-01-16 12:04     ` Mateusz Guzik
2025-01-16 12:35       ` [PATCH] fs: avoid mmap sem relocks when coredumping with many missing pages Mateusz Guzik
2025-01-16 17:04       ` [PATCH] coredump: allow interrupting dumps of large anonymous regions Tavian Barnes
2025-01-19 10:28         ` Mateusz Guzik
2025-01-16 10:05 ` Jan Kara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®